Skip to content

Commit 4f4fc2b

Browse files
ytdHuangalbertomercurio
authored andcommitted
fix QobjEvo in-place operator evaluation
1 parent e70c8ac commit 4f4fc2b

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/qobj/quantum_object_evo.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,11 @@ function (A::QuantumObjectEvolution)(
513513
end
514514

515515
# We put `nothing` in the place of `u` because the time-dependence doesn't depend on the state
516-
A.data(ψout.data, ψin.data, nothing, p, t)
516+
## TODO: should use SciMLOperators v1 API: A.data(ψout.data, ψin.data, nothing, p, t)
517+
## But somehow that doesn't work for some specific cases in our runtests.
518+
## Therefore, we use the most basic way to do it for now
519+
update_coefficients!(A.data, nothing, p, t)
520+
mul!(ψout.data, A.data, ψin.data)
517521

518522
return ψout
519523
end

src/qobj/superoperators.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,31 @@ _sprepost(A::AbstractMatrix, B::AbstractMatrix) = kron(transpose(sparse(B)), spa
1414
_sprepost(A::AbstractMatrix, B::AbstractSparseMatrix) = kron(transpose(B), sparse(A))
1515
_sprepost(A::AbstractSparseMatrix, B::AbstractMatrix) = kron(transpose(sparse(B)), A)
1616
_sprepost(A::AbstractSparseMatrix, B::AbstractSparseMatrix) = kron(transpose(B), A)
17+
function _sprepost(A, B) # for any other input types
18+
Id_cache = I(size(A, 1))
19+
return _spre(A, Id_cache) * _spost(B, Id_cache)
20+
end
1721

1822
## if input is AbstractSciMLOperator
1923
## some of them are optimized to speed things up
2024
## the rest of the SciMLOperators will just use lazy tensor (and prompt a warning)
2125
_spre(A::MatrixOperator, Id::AbstractMatrix) = MatrixOperator(_spre(A.A, Id))
2226
_spre(A::ScaledOperator, Id::AbstractMatrix) = ScaledOperator(A.λ, _spre(A.L, Id))
2327
_spre(A::AddedOperator, Id::AbstractMatrix) = AddedOperator(map(op -> _spre(op, Id), A.ops))
24-
function _spre(A::AbstractSciMLOperator, Id::Union{AbstractMatrix,AbstractSciMLOperator})
28+
function _spre(A::AbstractSciMLOperator, Id::AbstractMatrix)
2529
_lazy_tensor_warning(Id, A)
2630
return kron(Id, A)
2731
end
2832

2933
_spost(B::MatrixOperator, Id::AbstractMatrix) = MatrixOperator(_spost(B.A, Id))
3034
_spost(B::ScaledOperator, Id::AbstractMatrix) = ScaledOperator(B.λ, _spost(B.L, Id))
3135
_spost(B::AddedOperator, Id::AbstractMatrix) = AddedOperator(map(op -> _spost(op, Id), B.ops))
32-
function _spost(B::AbstractSciMLOperator, Id::Union{AbstractMatrix,AbstractSciMLOperator})
36+
function _spost(B::AbstractSciMLOperator, Id::AbstractMatrix)
3337
B_T = transpose(B)
3438
_lazy_tensor_warning(B_T, Id)
3539
return kron(B_T, Id)
3640
end
3741

38-
function _sprepost(A::AbstractSciMLOperator, B::AbstractSciMLOperator)
39-
Id_cache = IdentityOperator(size(A, 1))
40-
return _spre(A, Id_cache) * _spost(B, Id_cache)
41-
end
42-
4342
## intrinsic liouvillian
4443
_liouvillian(H::MT, Id::AbstractMatrix) where {MT<:Union{AbstractMatrix,AbstractSciMLOperator}} =
4544
-1im * (_spre(H, Id) - _spost(H, Id))

test/core-test/quantum_objects_evo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
coef2(p, t) * conj(coef3(p, t)) * (spre(a) * spost(X') - 0.5 * spre(X' * a) - 0.5 * spost(X' * a)) + # cross terms
216216
conj(coef2(p, t)) * coef3(p, t) * (spre(X) * spost(a') - 0.5 * spre(a' * X) - 0.5 * spost(a' * X)) # cross terms
217217
L_ti = liouvillian(H_ti) + D1_ti + D2_ti
218-
L_td = @test_logs (:warn,) (:warn,) (:warn,) (:warn,) liouvillian(H_td, c_ops) # warnings from lazy tensor in `lindblad_dissipator(c_op2)`
218+
L_td = @test_logs (:warn,) (:warn,) liouvillian(H_td, c_ops) # warnings from lazy tensor in `lindblad_dissipator(c_op2)`
219219
ρvec = mat2vec(rand_dm(N))
220220
@test L_td(p, t) L_ti
221221
@test iscached(L_td) == false

0 commit comments

Comments
 (0)