Skip to content

Commit 5e94453

Browse files
Improve mcsolve performance (#265)
1 parent 110c2e5 commit 5e94453

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/time_evolution/mcsolve.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ end
2323
function LindbladJumpAffect!(integrator)
2424
internal_params = integrator.p
2525
c_ops = internal_params.c_ops
26+
c_ops_herm = internal_params.c_ops_herm
2627
cache_mc = internal_params.cache_mc
2728
weights_mc = internal_params.weights_mc
2829
cumsum_weights_mc = internal_params.cumsum_weights_mc
@@ -33,11 +34,11 @@ function LindbladJumpAffect!(integrator)
3334
ψ = integrator.u
3435

3536
@inbounds for i in eachindex(weights_mc)
36-
mul!(cache_mc, c_ops[i], ψ)
37-
weights_mc[i] = real(dot(cache_mc, cache_mc))
37+
weights_mc[i] = real(dot(ψ, c_ops_herm[i], ψ))
3838
end
3939
cumsum!(cumsum_weights_mc, weights_mc)
40-
collaps_idx = getindex(1:length(weights_mc), findfirst(>(rand(traj_rng) * sum(weights_mc)), cumsum_weights_mc))
40+
r = rand(traj_rng) * sum(weights_mc)
41+
collaps_idx = getindex(1:length(weights_mc), findfirst(>(r), cumsum_weights_mc))
4142
mul!(cache_mc, c_ops[collaps_idx], ψ)
4243
normalize!(cache_mc)
4344
copyto!(integrator.u, cache_mc)
@@ -237,13 +238,17 @@ function mcsolveProblem(
237238
jump_times = Vector{Float64}(undef, jump_times_which_init_size)
238239
jump_which = Vector{Int16}(undef, jump_times_which_init_size)
239240

241+
c_ops_data = get_data.(c_ops)
242+
c_ops_herm_data = map(op -> op' * op, c_ops_data)
243+
240244
params2 = (
241245
expvals = expvals,
242246
e_ops_mc = e_ops2,
243247
is_empty_e_ops_mc = is_empty_e_ops_mc,
244248
progr_mc = ProgressBar(length(t_l), enable = false),
245249
traj_rng = rng,
246-
c_ops = get_data.(c_ops),
250+
c_ops = c_ops_data,
251+
c_ops_herm = c_ops_herm_data,
247252
cache_mc = cache_mc,
248253
weights_mc = weights_mc,
249254
cumsum_weights_mc = cumsum_weights_mc,

0 commit comments

Comments
 (0)