Skip to content

Commit e7f8bec

Browse files
Fix type instabilities
1 parent 2c83707 commit e7f8bec

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

src/qobj/superoperators.jl

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end
4141

4242
## intrinsic liouvillian
4343
_liouvillian(H::MT, Id::AbstractMatrix) where {MT<:Union{AbstractMatrix,AbstractSciMLOperator}} =
44-
-1im * _spre(H, Id) + 1im * _spost(H', Id) # without extracting the prefactor -1im seems to be better for AbstractSciMLOperator
44+
-1im * (_spre(H, Id) - _spost(H', Id))
4545
_liouvillian(H::MatrixOperator, Id::AbstractMatrix) = MatrixOperator(_liouvillian(H.A, Id))
4646
_liouvillian(H::AddedOperator, Id::AbstractMatrix) = AddedOperator(map(op -> _liouvillian(op, Id), H.ops))
4747

@@ -178,19 +178,4 @@ liouvillian(H::AbstractQuantumObject{Operator}, Id_cache::Diagonal = I(prod(H.di
178178

179179
liouvillian(H::AbstractQuantumObject{SuperOperator}, Id_cache::Diagonal) = H
180180

181-
function _sum_lindblad_dissipators(c_ops, Id_cache::Diagonal)
182-
D = 0
183-
# sum all the (time-independent) c_ops first
184-
c_ops_ti = filter(op -> isa(op, QuantumObject), c_ops)
185-
if !isempty(c_ops_ti)
186-
D += mapreduce(op -> lindblad_dissipator(op, Id_cache), +, c_ops_ti)
187-
end
188-
189-
# sum rest of the QobjEvo together
190-
c_ops_td = filter(op -> isa(op, QuantumObjectEvolution), c_ops)
191-
if !isempty(c_ops_td)
192-
D += mapreduce(op -> lindblad_dissipator(op, Id_cache), +, c_ops_td)
193-
end
194-
195-
return D
196-
end
181+
_sum_lindblad_dissipators(c_ops, Id_cache::Diagonal) = sum(op -> lindblad_dissipator(op, Id_cache), c_ops)

test/core-test/quantum_objects_evo.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,14 @@
237237
@test_throws ArgumentError cache_operator(L_td, ψ)
238238

239239
@testset "Type Inference" begin
240-
# we use destroy and create here because they somehow causes type instability before
241-
H_td2 = H_td + QobjEvo(destroy(N) + create(N), coef3)
242-
c_ops1 = (destroy(N), create(N))
243-
c_ops2 = (destroy(N), QobjEvo(create(N), coef1))
240+
H_td2 = H_td + QobjEvo(a + a', coef3)
241+
c_ops1 = (a, a')
242+
c_ops2 = (a, QobjEvo(a', coef1))
244243

245244
@inferred liouvillian(H_td, c_ops1)
246-
# @inferred liouvillian(H_td, c_ops2)
245+
@inferred liouvillian(H_td, c_ops2)
247246
@inferred liouvillian(H_td2, c_ops1)
248-
# @inferred liouvillian(H_td2, c_ops2)
247+
@inferred liouvillian(H_td2, c_ops2)
249248
end
250249
end
251250
end

0 commit comments

Comments
 (0)