Skip to content

Commit

Permalink
Merge pull request #23 from albertomercurio/albertomercurio-patch-1
Browse files Browse the repository at this point in the history
Minor copyto! changes
  • Loading branch information
albertomercurio authored Mar 6, 2024
2 parents c99ae82 + 5d3c914 commit 432f8c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/time_evolution/mcsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function _save_func_mcsolve(integrator)
expvals = internal_params.expvals
cache_mc = internal_params.cache_mc

cache_mc .= integrator.u
copyto!(cache_mc, integrator.u)
normalize!(cache_mc)
ψ = cache_mc
_expect = op -> dot(ψ, op, ψ)
Expand Down Expand Up @@ -38,7 +38,7 @@ function LindbladJumpAffect!(integrator)
collaps_idx = getindex(1:length(weights_mc), findfirst(>(rand()*sum(weights_mc)), cumsum_weights_mc))
mul!(cache_mc, c_ops[collaps_idx], ψ)
normalize!(cache_mc)
integrator.u .= cache_mc
copyto!(integrator.u, cache_mc)

push!(jump_times, integrator.t)
push!(jump_which, collaps_idx)
Expand Down Expand Up @@ -69,7 +69,7 @@ function _mcsolve_generate_statistics(sol, i, times, states, expvals_all, jump_t
sol_i = sol[:,i]
sol_u = haskey(sol_i.prob.kwargs, :save_idxs) ? sol_i.u : QuantumObject.(sol_i.u, dims=sol_i.prob.p.Hdims)

expvals_all[i, :, :] .= sol_i.prob.p.expvals
copyto!(view(expvals_all, i, :, :), sol_i.prob.p.expvals)
push!(times, sol_i.t)
push!(states, sol_u)
push!(jump_times, sol_i.prob.p.jump_times)
Expand Down
31 changes: 13 additions & 18 deletions src/time_evolution/time_evolution_dynamical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ function _increase_dims(QO::AbstractArray{T}, dims::Vector{<:Integer}, sel::Abst

if nd == 1
ρmat = similar(QO, rd_new[1], rd_new[1])
selectdim(ρmat, 1, rd[1]+1:rd_new[1]) .= 0
selectdim(ρmat, 2, rd[1]+1:rd_new[1]) .= 0
fill!(selectdim(ρmat, 1, rd[1]+1:rd_new[1]), 0)
fill!(selectdim(ρmat, 2, rd[1]+1:rd_new[1]), 0)
copyto!(view(ρmat, 1:rd[1], 1:rd[1]), QO)
else
ρmat2 = similar(QO, reverse!(repeat(rd_new, 2))...)
ρmat = reshape(QO, reverse!(repeat(rd, 2))...)
for i in eachindex(sel)
selectdim(ρmat2, nd-sel[i]+1, rd[sel[i]]+1:rd_new[sel[i]]) .= 0
selectdim(ρmat2, 2*nd-sel[i]+1, rd[sel[i]]+1:rd_new[sel[i]]) .= 0
fill!(selectdim(ρmat2, nd-sel[i]+1, rd[sel[i]]+1:rd_new[sel[i]]), 0)
fill!(selectdim(ρmat2, 2*nd-sel[i]+1, rd[sel[i]]+1:rd_new[sel[i]]), 0)
end
copyto!(view(ρmat2, reverse!(repeat([1:n for n in rd], 2))...), ρmat)
ρmat = reshape(ρmat2, prod(rd_new), prod(rd_new))
Expand Down Expand Up @@ -109,16 +109,16 @@ function _DFDIncreaseReduceAffect!(integrator)
end

@. pillow_list = _dfd_set_pillow(dim_list)
increase_list .= false
reduce_list .= false
fill!(increase_list, false)
fill!(reduce_list, false)
push!(dim_list_evo_times, integrator.t)
push!(dim_list_evo, dim_list)

e_ops2 = map(op -> mat2vec(get_data(op)'), e_ops(dim_list, dfd_params))
L = liouvillian(H(dim_list, dfd_params), c_ops(dim_list, dfd_params)).data

resize!(integrator, size(L, 1))
integrator.u .= mat2vec(ρt)
copyto!(integrator.u, mat2vec(ρt))
integrator.p = merge(internal_params, (L = L, e_ops = e_ops2,
dfd_ρt_cache = similar(integrator.u)))
end
Expand Down Expand Up @@ -232,14 +232,10 @@ function _DSF_mesolve_Affect!(integrator)
dsf_params = internal_params.dsf_params
expv_cache = internal_params.expv_cache
dsf_identity = internal_params.dsf_identity
# dsf_displace_cache_left = internal_params.dsf_displace_cache_left
# dsf_displace_cache_left_dag = internal_params.dsf_displace_cache_left_dag
# dsf_displace_cache_right = internal_params.dsf_displace_cache_right
# dsf_displace_cache_right_dag = internal_params.dsf_displace_cache_right_dag
dsf_displace_cache_full = internal_params.dsf_displace_cache_full

op_l_length = length(op_l)
dsf_displace_cache_full.coefficients .= 0
fill!(dsf_displace_cache_full.coefficients, 0)

for i in eachindex(op_l)
# op = op_l[i]
Expand Down Expand Up @@ -272,7 +268,7 @@ function _DSF_mesolve_Affect!(integrator)
end
end

dsf_cache .= integrator.u
copyto!(dsf_cache, integrator.u)
arnoldi!(expv_cache, dsf_displace_cache_full, dsf_cache)
expv!(integrator.u, expv_cache, 1, dsf_cache)

Expand Down Expand Up @@ -394,7 +390,7 @@ function _DSF_mcsolve_Condition(u, t, integrator)
δα_list = internal_params.δα_list
ψt = internal_params.dsf_cache1

ψt .= integrator.u
copyto!(ψt, integrator.u)
normalize!(ψt)

condition = false
Expand Down Expand Up @@ -426,7 +422,7 @@ function _DSF_mcsolve_Affect!(integrator)
dsf_displace_cache_full = internal_params.dsf_displace_cache_full

op_l_length = length(op_l)
dsf_displace_cache_full.coefficients .= 0
fill!(dsf_displace_cache_full.coefficients, 0)

for i in eachindex(op_l)
op = op_l[i]
Expand All @@ -451,7 +447,7 @@ function _DSF_mcsolve_Affect!(integrator)
end
end

dsf_cache .= integrator.u
copyto!(dsf_cache, integrator.u)
arnoldi!(expv_cache, dsf_displace_cache_full, dsf_cache)
expv!(integrator.u, expv_cache, 1, dsf_cache)

Expand All @@ -461,7 +457,7 @@ function _DSF_mcsolve_Affect!(integrator)
@. e_ops0 = get_data(e_ops2)
@. c_ops0 = get_data(c_ops2)
H_eff = H(op_l2, dsf_params).data - lmul!(convert(eltype(ψt), 0.5im), mapreduce(op -> op' * op, +, c_ops0))
internal_params.U .= lmul!(-1im, H_eff)
mul!(internal_params.U, -1im, H_eff)
end

function _dsf_mcsolve_prob_func(prob, i, repeat)
Expand All @@ -474,7 +470,6 @@ function _dsf_mcsolve_prob_func(prob, i, repeat)
jump_times = similar(internal_params.jump_times), jump_which = similar(internal_params.jump_which),
αt_list = deepcopy(internal_params.αt_list), dsf_cache1 = similar(internal_params.dsf_cache1),
dsf_cache2 = similar(internal_params.dsf_cache2), expv_cache = deepcopy(internal_params.expv_cache),
# dsf_displace_cache_full = deepcopy(internal_params.dsf_displace_cache_full),
dsf_displace_cache_full = OperatorSum(deepcopy(internal_params.dsf_displace_cache_full.coefficients), internal_params.dsf_displace_cache_full.operators)))

remake(prob, p=prm)
Expand Down

0 comments on commit 432f8c4

Please sign in to comment.