Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Support different length for `to` and `from` on GeneralDimensions. ([#448])
- Extend the `Makie.jl` extension to all the other available backends. ([#450])
- Fix definition of noise derivative in stochastic solvers. ([#453])

## [v0.30.0]
Release date: 2025-04-12
Expand Down Expand Up @@ -206,3 +207,4 @@ Release date: 2024-11-13
[#443]: https://github.com/qutip/QuantumToolbox.jl/issues/443
[#448]: https://github.com/qutip/QuantumToolbox.jl/issues/448
[#450]: https://github.com/qutip/QuantumToolbox.jl/issues/450
[#453]: https://github.com/qutip/QuantumToolbox.jl/issues/453
3 changes: 3 additions & 0 deletions src/qobj/quantum_object_evo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@
isconstant(data.λ) && return ScaledOperator(α * data.λ, data.L)
return ScaledOperator(data.λ, _promote_to_scimloperator(α, data.L)) # Try to propagate the rule
end
function _promote_to_scimloperator(α::Number, data::AddedOperator)
return AddedOperator(_promote_to_scimloperator.(α, data.ops)) # Try to propagate the rule

Check warning on line 472 in src/qobj/quantum_object_evo.jl

View check run for this annotation

Codecov / codecov/patch

src/qobj/quantum_object_evo.jl#L471-L472

Added lines #L471 - L472 were not covered by tests
end
function _promote_to_scimloperator(α::Number, data::AbstractSciMLOperator)
return α * data # Going back to the generic case
end
Expand Down
24 changes: 17 additions & 7 deletions src/time_evolution/callback_helpers/callback_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
) where {SF<:AbstractSaveFunc}
cb_save = _generate_stochastic_save_callback(e_ops, sc_ops, tlist, store_measurement, progress_bar, method)

# Ensure that the noise is stored in tlist. # TODO: Fix this directly in DiffEqNoiseProcess.jl
# See https://github.com/SciML/DiffEqNoiseProcess.jl/issues/214 for example
tstops = haskey(kwargs, :tstops) ? unique!(sort!(vcat(tlist, kwargs.tstops))) : tlist
kwargs2 = merge(kwargs, (tstops = tstops,))

Check warning on line 30 in src/time_evolution/callback_helpers/callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/callback_helpers.jl#L29-L30

Added lines #L29 - L30 were not covered by tests

if SF === SaveFuncSSESolve
cb_normalize = _ssesolve_generate_normalize_cb()
return _merge_kwargs_with_callback(kwargs, CallbackSet(cb_normalize, cb_save))
return _merge_kwargs_with_callback(kwargs2, CallbackSet(cb_normalize, cb_save))

Check warning on line 34 in src/time_evolution/callback_helpers/callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/callback_helpers.jl#L34

Added line #L34 was not covered by tests
end

return _merge_kwargs_with_callback(kwargs, cb_save)
return _merge_kwargs_with_callback(kwargs2, cb_save)

Check warning on line 37 in src/time_evolution/callback_helpers/callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/callback_helpers.jl#L37

Added line #L37 was not covered by tests
end
_generate_stochastic_kwargs(
e_ops::Nothing,
Expand Down Expand Up @@ -69,7 +74,9 @@
expvals = e_ops isa Nothing ? nothing : Array{ComplexF64}(undef, length(e_ops), length(tlist))
m_expvals = getVal(store_measurement) ? Array{Float64}(undef, length(sc_ops), length(tlist) - 1) : nothing

_save_func = method(store_measurement, e_ops_data, m_ops_data, progr, Ref(1), expvals, m_expvals)
_save_func_cache = Array{Float64}(undef, length(sc_ops))
_save_func =

Check warning on line 78 in src/time_evolution/callback_helpers/callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/callback_helpers.jl#L77-L78

Added lines #L77 - L78 were not covered by tests
method(store_measurement, e_ops_data, m_ops_data, progr, Ref(1), expvals, m_expvals, tlist, _save_func_cache)
return FunctionCallingCallback(_save_func, funcat = tlist)
end

Expand Down Expand Up @@ -162,9 +169,12 @@

# %% ------------ Noise Measurement Helpers ------------ %%

# TODO: Add some cache mechanism to avoid memory allocations
function _homodyne_dWdt(integrator)
@inbounds _dWdt = (integrator.W.u[end] .- integrator.W.u[end-1]) ./ (integrator.W.t[end] - integrator.W.t[end-1])
# TODO: To improve. See https://github.com/SciML/DiffEqNoiseProcess.jl/issues/214
function _homodyne_dWdt!(dWdt_cache, integrator, tlist, iter)
idx = findfirst(>=(tlist[iter[]-1]), integrator.W.t)

Check warning on line 174 in src/time_evolution/callback_helpers/callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/callback_helpers.jl#L173-L174

Added lines #L173 - L174 were not covered by tests

# We are assuming that the last element is tlist[iter[]]
@inbounds dWdt_cache .= (integrator.W.u[end] .- integrator.W.u[idx]) ./ (integrator.W.t[end] - integrator.W.t[idx])

Check warning on line 177 in src/time_evolution/callback_helpers/callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/callback_helpers.jl#L177

Added line #L177 was not covered by tests

return _dWdt
return nothing

Check warning on line 179 in src/time_evolution/callback_helpers/callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/callback_helpers.jl#L179

Added line #L179 was not covered by tests
end
12 changes: 8 additions & 4 deletions src/time_evolution/callback_helpers/smesolve_callback_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
IT,
TEXPV<:Union{Nothing,AbstractMatrix},
TMEXPV<:Union{Nothing,AbstractMatrix},
TLT<:AbstractVector,
CT<:AbstractVector,
} <: AbstractSaveFunc
store_measurement::Val{SM}
e_ops::TE
Expand All @@ -18,10 +20,12 @@
iter::IT
expvals::TEXPV
m_expvals::TMEXPV
tlist::TLT
dWdt_cache::CT
end

(f::SaveFuncSMESolve)(u, t, integrator) =
_save_func_smesolve(u, integrator, f.e_ops, f.m_ops, f.progr, f.iter, f.expvals, f.m_expvals)
_save_func_smesolve(u, integrator, f.e_ops, f.m_ops, f.progr, f.iter, f.expvals, f.m_expvals, f.tlist, f.dWdt_cache)
(f::SaveFuncSMESolve{false,Nothing})(u, t, integrator) = _save_func(integrator, f.progr) # Common for both all solvers

_get_e_ops_data(e_ops, ::Type{SaveFuncSMESolve}) = _get_e_ops_data(e_ops, SaveFuncMESolve)
Expand All @@ -31,7 +35,7 @@
##

# When e_ops is a list of operators
function _save_func_smesolve(u, integrator, e_ops, m_ops, progr, iter, expvals, m_expvals)
function _save_func_smesolve(u, integrator, e_ops, m_ops, progr, iter, expvals, m_expvals, tlist, dWdt_cache)

Check warning on line 38 in src/time_evolution/callback_helpers/smesolve_callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/smesolve_callback_helpers.jl#L38

Added line #L38 was not covered by tests
# This is equivalent to tr(op * ρ), when both are matrices.
# The advantage of using this convention is that We don't need
# to reshape u to make it a matrix, but we reshape the e_ops once.
Expand All @@ -45,8 +49,8 @@
end

if !isnothing(m_expvals) && iter[] > 1
_dWdt = _homodyne_dWdt(integrator)
@. m_expvals[:, iter[]-1] = real(_expect(m_ops)) + _dWdt
_homodyne_dWdt!(dWdt_cache, integrator, tlist, iter)
@. m_expvals[:, iter[]-1] = real(_expect(m_ops)) + dWdt_cache

Check warning on line 53 in src/time_evolution/callback_helpers/smesolve_callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/smesolve_callback_helpers.jl#L52-L53

Added lines #L52 - L53 were not covered by tests
end

iter[] += 1
Expand Down
12 changes: 8 additions & 4 deletions src/time_evolution/callback_helpers/ssesolve_callback_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
IT,
TEXPV<:Union{Nothing,AbstractMatrix},
TMEXPV<:Union{Nothing,AbstractMatrix},
TLT<:AbstractVector,
CT<:AbstractVector,
} <: AbstractSaveFunc
store_measurement::Val{SM}
e_ops::TE
Expand All @@ -18,10 +20,12 @@
iter::IT
expvals::TEXPV
m_expvals::TMEXPV
tlist::TLT
dWdt_cache::CT
end

(f::SaveFuncSSESolve)(u, t, integrator) =
_save_func_ssesolve(u, integrator, f.e_ops, f.m_ops, f.progr, f.iter, f.expvals, f.m_expvals)
_save_func_ssesolve(u, integrator, f.e_ops, f.m_ops, f.progr, f.iter, f.expvals, f.m_expvals, f.tlist, f.dWdt_cache)
(f::SaveFuncSSESolve{false,Nothing})(u, t, integrator) = _save_func(integrator, f.progr) # Common for both all solvers

_get_e_ops_data(e_ops, ::Type{SaveFuncSSESolve}) = get_data.(e_ops)
Expand All @@ -32,7 +36,7 @@
##

# When e_ops is a list of operators
function _save_func_ssesolve(u, integrator, e_ops, m_ops, progr, iter, expvals, m_expvals)
function _save_func_ssesolve(u, integrator, e_ops, m_ops, progr, iter, expvals, m_expvals, tlist, dWdt_cache)

Check warning on line 39 in src/time_evolution/callback_helpers/ssesolve_callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/ssesolve_callback_helpers.jl#L39

Added line #L39 was not covered by tests
ψ = u

_expect = op -> dot(ψ, op, ψ)
Expand All @@ -42,8 +46,8 @@
end

if !isnothing(m_expvals) && iter[] > 1
_dWdt = _homodyne_dWdt(integrator)
@. m_expvals[:, iter[]-1] = real(_expect(m_ops)) + _dWdt
_homodyne_dWdt!(dWdt_cache, integrator, tlist, iter)
@. m_expvals[:, iter[]-1] = real(_expect(m_ops)) + dWdt_cache

Check warning on line 50 in src/time_evolution/callback_helpers/ssesolve_callback_helpers.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/callback_helpers/ssesolve_callback_helpers.jl#L49-L50

Added lines #L49 - L50 were not covered by tests
end

iter[] += 1
Expand Down
2 changes: 1 addition & 1 deletion src/time_evolution/ssesolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
sc_ops_evo_data,
)

K = -1im * get_data(H_eff_evo) + K_l
K = get_data(QobjEvo(H_eff_evo, -1im)) + K_l

Check warning on line 116 in src/time_evolution/ssesolve.jl

View check run for this annotation

Codecov / codecov/patch

src/time_evolution/ssesolve.jl#L116

Added line #L116 was not covered by tests

D_l = map(op -> op + _ScalarOperator_e(op, -) * IdentityOperator(prod(dims)), sc_ops_evo_data)
D = DiffusionOperator(D_l)
Expand Down
2 changes: 1 addition & 1 deletion src/time_evolution/time_evolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export TimeEvolutionSol, TimeEvolutionMCSol, TimeEvolutionStochasticSol
export liouvillian_floquet, liouvillian_generalized

const DEFAULT_ODE_SOLVER_OPTIONS = (abstol = 1e-8, reltol = 1e-6, save_everystep = false, save_end = true)
const DEFAULT_SDE_SOLVER_OPTIONS = (abstol = 1e-2, reltol = 1e-2, save_everystep = false, save_end = true)
const DEFAULT_SDE_SOLVER_OPTIONS = (abstol = 1e-3, reltol = 2e-3, save_everystep = false, save_end = true)
const COL_TIMES_WHICH_INIT_SIZE = 200

@doc raw"""
Expand Down
Loading