Skip to content

Commit 75fefe8

Browse files
authored
Automatically convert TimeDependentOperatorSum to liouvillian (#235)
2 parents db333c2 + 96d6f0a commit 75fefe8

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/qobj/operator_sum.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export OperatorSum
33
@doc raw"""
44
struct OperatorSum
55
6-
A structure to represent a sum of operators ``\sum_i c_i \hat{O}_i`` with a list of coefficients ``c_i`` and a list of operators ``\hat{O}_i``.
6+
A constructor to represent a sum of operators ``\sum_i c_i \hat{O}_i`` with a list of coefficients ``c_i`` and a list of operators ``\hat{O}_i``.
77
88
This is very useful when we have to update only the coefficients, without allocating memory by performing the sum of the operators.
99
"""
@@ -47,3 +47,7 @@ end
4747
end
4848
return y
4949
end
50+
51+
function liouvillian(A::OperatorSum, Id_cache = I(prod(A.operators[1].dims)))
52+
return OperatorSum(A.coefficients, liouvillian.(A.operators, Ref(Id_cache)))
53+
end

src/time_evolution/mesolve.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ function mesolveProblem(
139139
is_empty_e_ops = isempty(e_ops)
140140
end
141141

142+
if H_t isa TimeDependentOperatorSum
143+
H_t = liouvillian(H_t)
144+
end
145+
142146
p = (
143147
L = L,
144148
progr = progr,

src/time_evolution/time_evolution.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ end
140140
return mul!(y, A.operator_sum, x, α, β)
141141
end
142142

143+
function liouvillian(A::TimeDependentOperatorSum, Id_cache = I(prod(A.operator_sum.operators[1].dims)))
144+
return TimeDependentOperatorSum(A.coefficient_functions, liouvillian(A.operator_sum, Id_cache))
145+
end
146+
143147
#######################################
144148

145149
### LIOUVILLIAN ###

test/core-test/steady_state.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
e_ops = [a_d * a]
6464
psi0 = fock(N, 3)
6565
t_l = LinRange(0, 100 * 2π, 1000)
66-
H_t_f = TimeDependentOperatorSum([(t, p) -> sin(t)], [liouvillian(H_t)])
66+
H_t_f = TimeDependentOperatorSum((((t, p) -> sin(t)),), [H_t]) # It will be converted to liouvillian internally
6767
sol_me = mesolve(H, psi0, t_l, c_ops, e_ops = e_ops, H_t = H_t_f, progress_bar = Val(false))
6868
ρ_ss1 = steadystate_floquet(H, -1im * 0.5 * H_t, 1im * 0.5 * H_t, 1, c_ops, solver = SSFloquetLinearSystem())[1]
6969
ρ_ss2 =

0 commit comments

Comments
 (0)