Skip to content

Commit 2ee9138

Browse files
committed
fix type instability
1 parent 9a7beab commit 2ee9138

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/qobj/superoperators.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,16 @@ function liouvillian(
166166
) where {DT,OpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}}
167167
L = liouvillian(H, Id_cache)
168168
if !(c_ops isa Nothing)
169-
c_ops_tuple = Tuple(c_ops) # we must convert it to a tuple, so filter below also return tuple
170-
171169
# sum all the (time-independent) c_ops first
172-
c_ops_ti = filter(op -> isa(op, QuantumObject), c_ops_tuple)
170+
c_ops_ti = filter(op -> isa(op, QuantumObject), c_ops)
173171
if !isempty(c_ops_ti)
174172
L += mapreduce(op -> lindblad_dissipator(op, Id_cache), +, c_ops_ti)
175173
end
176174

177175
# sum rest of the QobjEvo together
178-
c_ops_td = filter(op -> isa(op, QuantumObjectEvolution), c_ops_tuple)
176+
c_ops_td = filter(op -> isa(op, QuantumObjectEvolution), c_ops)
179177
if !isempty(c_ops_td)
180-
L += AddedOperator(map(op -> lindblad_dissipator(op, Id_cache), c_ops_td)) # it becomes AddedOperator at the end anyway
178+
L += mapreduce(op -> lindblad_dissipator(op, Id_cache), +, c_ops_td)
181179
end
182180
end
183181
return L

test/core-test/quantum_objects_evo.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@
215215
@testset "Type Inference" begin
216216
H_td2 = H_td + QobjEvo(a + a', coef3)
217217

218-
# we use destroy and create here because it somehow might cause type instability
219-
c_ops1 = (destroy(N), create(N))
218+
# we use destroy and create here because they somehow causes type instability before
219+
c_ops1 = (destroy(N), create(N))
220220
c_ops2 = (destroy(N), QobjEvo(create(N), coef1))
221221

222222
@inferred liouvillian(H_td, c_ops1)

0 commit comments

Comments
 (0)