Skip to content

Commit e70c8ac

Browse files
ytdHuangalbertomercurio
authored andcommitted
try to use IdentityOperator
1 parent 4649d73 commit e70c8ac

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/qobj/superoperators.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,32 @@ _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-
# TODO: use the commented code (since it is optimized for certain types of SciMLOperators, and was able to give correct results before `SciMLOperators v1.0.0`)
19-
# Id_cache = I(size(A, 1))
20-
# return _spre(A, Id_cache) * _spost(B, Id_cache)
21-
22-
return kron(transpose(B), A)
23-
end
2417

2518
## if input is AbstractSciMLOperator
2619
## some of them are optimized to speed things up
2720
## the rest of the SciMLOperators will just use lazy tensor (and prompt a warning)
2821
_spre(A::MatrixOperator, Id::AbstractMatrix) = MatrixOperator(_spre(A.A, Id))
2922
_spre(A::ScaledOperator, Id::AbstractMatrix) = ScaledOperator(A.λ, _spre(A.L, Id))
3023
_spre(A::AddedOperator, Id::AbstractMatrix) = AddedOperator(map(op -> _spre(op, Id), A.ops))
31-
function _spre(A::AbstractSciMLOperator, Id::AbstractMatrix)
24+
function _spre(A::AbstractSciMLOperator, Id::Union{AbstractMatrix,AbstractSciMLOperator})
3225
_lazy_tensor_warning(Id, A)
3326
return kron(Id, A)
3427
end
3528

3629
_spost(B::MatrixOperator, Id::AbstractMatrix) = MatrixOperator(_spost(B.A, Id))
3730
_spost(B::ScaledOperator, Id::AbstractMatrix) = ScaledOperator(B.λ, _spost(B.L, Id))
3831
_spost(B::AddedOperator, Id::AbstractMatrix) = AddedOperator(map(op -> _spost(op, Id), B.ops))
39-
function _spost(B::AbstractSciMLOperator, Id::AbstractMatrix)
32+
function _spost(B::AbstractSciMLOperator, Id::Union{AbstractMatrix,AbstractSciMLOperator})
4033
B_T = transpose(B)
4134
_lazy_tensor_warning(B_T, Id)
4235
return kron(B_T, Id)
4336
end
4437

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+
4543
## intrinsic liouvillian
4644
_liouvillian(H::MT, Id::AbstractMatrix) where {MT<:Union{AbstractMatrix,AbstractSciMLOperator}} =
4745
-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,) liouvillian(H_td, c_ops) # warnings from lazy tensor in `lindblad_dissipator(c_op2)`
218+
L_td = @test_logs (:warn,) (:warn,) (: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)