Skip to content

Commit 6bdb2e8

Browse files
Fix dsf_mcsolve
1 parent c19e0d6 commit 6bdb2e8

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/QuantumToolbox.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import SciMLBase:
2121
reinit!,
2222
remake,
2323
u_modified!,
24+
ODEFunction,
2425
ODEProblem,
2526
SDEProblem,
2627
EnsembleProblem,

src/time_evolution/mcsolve.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ function _mcsolve_generate_statistics(sol, i, states, expvals_all, jump_times, j
117117
return jump_which[i] = sol_i.prob.p.jump_which
118118
end
119119

120+
_mcsolve_make_Heff_QobjEvo(H::QuantumObject, c_ops) = QobjEvo(H - 1im * mapreduce(op -> op' * op, +, c_ops) / 2)
121+
_mcsolve_make_Heff_QobjEvo(H::Tuple, c_ops) = QobjEvo((H..., -1im * mapreduce(op -> op' * op, +, c_ops) / 2))
122+
_mcsolve_make_Heff_QobjEvo(H::QuantumObjectEvolution, c_ops) =
123+
H + QobjEvo(mapreduce(op -> op' * op, +, c_ops), -1im / 2)
124+
120125
@doc raw"""
121126
mcsolveProblem(H::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject},
122127
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
@@ -210,7 +215,7 @@ function mcsolveProblem(
210215

211216
tlist = convert(Vector{_FType(ψ0)}, tlist) # Convert it to support GPUs and avoid type instabilities for OrdinaryDiffEq.jl
212217

213-
H_eff_evo = QobjEvo(H) + QobjEvo(mapreduce(op -> op' * op, +, c_ops) / 2, -1im)
218+
H_eff_evo = _mcsolve_make_Heff_QobjEvo(H, c_ops)
214219

215220
if e_ops isa Nothing
216221
expvals = Array{ComplexF64}(undef, 0, length(tlist))

src/time_evolution/sesolve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function sesolveProblem(
124124
kwargs3 = _generate_sesolve_kwargs(e_ops, makeVal(progress_bar), tlist, kwargs2)
125125

126126
tspan = (tlist[1], tlist[end])
127-
return ODEProblem{true,FullSpecialize}(U, ψ0, tspan, p; kwargs3...)
127+
return ODEProblem{true}(U, ψ0, tspan, p; kwargs3...)
128128
end
129129

130130
@doc raw"""

src/time_evolution/time_evolution_dynamical.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,10 @@ function _DSF_mcsolve_Affect!(integrator)
572572
c_ops2 = c_ops(op_l2, dsf_params)
573573
@. e_ops0 = get_data(e_ops2)
574574
@. c_ops0 = get_data(c_ops2)
575-
H_eff = H(op_l2, dsf_params).data - lmul!(convert(eltype(ψt), 0.5im), mapreduce(op -> op' * op, +, c_ops0))
576-
return mul!(internal_params.U, -1im, H_eff)
575+
H_nh = lmul!(convert(eltype(ψt), 0.5im), mapreduce(op -> op' * op, +, c_ops0))
576+
# By doing this, we are assuming that the system is time-independent and f is a ScaledOperator
577+
copyto!(integrator.f.f.L.A, H(op_l2, dsf_params).data - H_nh)
578+
return u_modified!(integrator, true)
577579
end
578580

579581
function _dsf_mcsolve_prob_func(prob, i, repeat)
@@ -582,7 +584,6 @@ function _dsf_mcsolve_prob_func(prob, i, repeat)
582584
prm = merge(
583585
internal_params,
584586
(
585-
U = copy(internal_params.U),
586587
e_ops_mc = copy(internal_params.e_ops_mc),
587588
c_ops = copy(internal_params.c_ops),
588589
expvals = similar(internal_params.expvals),
@@ -605,7 +606,9 @@ function _dsf_mcsolve_prob_func(prob, i, repeat)
605606
),
606607
)
607608

608-
return remake(prob, p = prm)
609+
f = deepcopy(prob.f.f)
610+
611+
return remake(prob, f = f, p = prm)
609612
end
610613

611614
function dsf_mcsolveEnsembleProblem(

0 commit comments

Comments
 (0)