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 @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)

- Introduce new methods of `sesolve_map` and `mesolve_map` for advanced usage. Users can now customize their own `iter`ator structure, `prob_func` and `output_func`. ([#565])
- Use `ProgressMeter.jl` for progress bar rather than our in-house implementation. ([#569])

## [v0.37.0]
Release date: 2025-10-12
Expand Down Expand Up @@ -339,3 +340,4 @@ Release date: 2024-11-13
[#555]: https://github.com/qutip/QuantumToolbox.jl/issues/555
[#557]: https://github.com/qutip/QuantumToolbox.jl/issues/557
[#565]: https://github.com/qutip/QuantumToolbox.jl/issues/565
[#569]: https://github.com/qutip/QuantumToolbox.jl/issues/569
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumToolbox"
uuid = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"
authors = ["Alberto Mercurio", "Yi-Te Huang"]
version = "0.37.0"
authors = ["Alberto Mercurio", "Yi-Te Huang"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is there a special reason for this change ? lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that Julia v1.12 did it automatically when I have updated the environment.


[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand All @@ -18,6 +18,7 @@ LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
Expand Down Expand Up @@ -60,6 +61,7 @@ Makie = "0.24"
OrdinaryDiffEqCore = "1"
OrdinaryDiffEqTsit5 = "1"
Pkg = "1"
ProgressMeter = "1.11.0"
Random = "1"
SciMLBase = "2.105"
SciMLOperators = "1.4"
Expand Down
2 changes: 2 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ In order to get a better experience and take full advantage of `QuantumToolbox`
- [`Zygote.jl`](https://github.com/FluxML/Zygote.jl)
- [`Enzyme.jl`](https://github.com/EnzymeAD/Enzyme.jl)
- [`ForwardDiff.jl`](https://github.com/JuliaDiff/ForwardDiff.jl)
- Progress Bars:
- [`ProgressMeter.jl`](https://github.com/timholy/ProgressMeter.jl)
- Packages for other advanced usage:
- [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl)
- [`SciMLOperators.jl`](https://github.com/SciML/SciMLOperators.jl)
Expand Down
2 changes: 1 addition & 1 deletion src/QuantumToolbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import Graphs: connected_components, DiGraph
import IncompleteLU: ilu
import LaTeXStrings: @L_str
import Pkg
import ProgressMeter: Progress, next!
import Random: AbstractRNG, default_rng, seed!
import SpecialFunctions: loggamma
import StaticArraysCore: SVector, MVector
Expand All @@ -81,7 +82,6 @@ export cache_operator, iscached, isconstant
include("settings.jl")
include("utilities.jl")
include("versioninfo.jl")
include("progress_bar.jl")
include("linear_maps.jl")

# Quantum Object
Expand Down
8 changes: 8 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,11 @@ function MultiSiteOperator(args...)
)
return multisite_operator(args...)
end

export ProgressBar
function ProgressBar(args...; kwargs...)
# Use error instead of depwarn, since ProgressBar and Progress have different arguments
return error(
"`ProgressBar` is deprecated and will be removed in next major release. Use `Progress` from `ProgressMeter.jl` instead.",
)
end
85 changes: 0 additions & 85 deletions src/progress_bar.jl

This file was deleted.

7 changes: 5 additions & 2 deletions src/time_evolution/callback_helpers/callback_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ end
function _generate_save_callback(e_ops, tlist, progress_bar, method)
e_ops_data = e_ops isa Nothing ? nothing : _get_e_ops_data(e_ops, method)

progr = getVal(progress_bar) ? ProgressBar(length(tlist), enable = getVal(progress_bar)) : nothing
progr_desc = _get_progress_desc(method)
progr =
getVal(progress_bar) ?
Progress(length(tlist), showspeed = true, enabled = getVal(progress_bar), desc = progr_desc) : nothing

expvals = e_ops isa Nothing ? nothing : Array{ComplexF64}(undef, length(e_ops), length(tlist))

Expand All @@ -69,7 +72,7 @@ function _generate_stochastic_save_callback(e_ops, sc_ops, tlist, store_measurem
e_ops_data = e_ops isa Nothing ? nothing : _get_e_ops_data(e_ops, method)
m_ops_data = _get_m_ops_data(sc_ops, method)

progr = getVal(progress_bar) ? ProgressBar(length(tlist), enable = getVal(progress_bar)) : nothing
progr = getVal(progress_bar) ? Progress(length(tlist), showspeed = true, enabled = getVal(progress_bar)) : nothing

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function _generate_mcsolve_kwargs(ψ0, T, e_ops, tlist, c_ops, jump_callback, rn
end

if e_ops isa Nothing
# We are implicitly saying that we don't have a `ProgressBar`
# We are implicitly saying that we don't have a `Progress`
kwargs2 =
haskey(kwargs, :callback) ? merge(kwargs, (callback = CallbackSet(cb1, kwargs.callback),)) :
merge(kwargs, (callback = cb1,))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Helper functions for the mesolve callbacks.
=#

struct SaveFuncMESolve{TE,PT<:Union{Nothing,ProgressBar},IT,TEXPV<:Union{Nothing,AbstractMatrix}} <: AbstractSaveFunc
struct SaveFuncMESolve{TE,PT<:Union{Nothing,Progress},IT,TEXPV<:Union{Nothing,AbstractMatrix}} <: AbstractSaveFunc
e_ops::TE
progr::PT
iter::IT
Expand All @@ -14,6 +14,8 @@ end

_get_e_ops_data(e_ops, ::Type{SaveFuncMESolve}) = [_generate_mesolve_e_op(op) for op in e_ops] # Broadcasting generates type instabilities on Julia v1.10

_get_progress_desc(::Type{SaveFuncMESolve}) = "(mesolve) "

##

# When e_ops is a list of operators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Helper functions for the sesolve callbacks.
=#

struct SaveFuncSESolve{TE,PT<:Union{Nothing,ProgressBar},IT,TEXPV<:Union{Nothing,AbstractMatrix}} <: AbstractSaveFunc
struct SaveFuncSESolve{TE,PT<:Union{Nothing,Progress},IT,TEXPV<:Union{Nothing,AbstractMatrix}} <: AbstractSaveFunc
e_ops::TE
progr::PT
iter::IT
Expand All @@ -14,6 +14,8 @@ end

_get_e_ops_data(e_ops, ::Type{SaveFuncSESolve}) = get_data.(e_ops)

_get_progress_desc(::Type{SaveFuncSESolve}) = "(sesolve) "

##

# When e_ops is a list of operators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct SaveFuncSMESolve{
SM,
TE,
TE2,
PT<:Union{Nothing,ProgressBar},
PT<:Union{Nothing,Progress},
IT,
TEXPV<:Union{Nothing,AbstractMatrix},
TMEXPV<:Union{Nothing,AbstractMatrix},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct SaveFuncSSESolve{
SM,
TE,
TE2,
PT<:Union{Nothing,ProgressBar},
PT<:Union{Nothing,Progress},
IT,
TEXPV<:Union{Nothing,AbstractMatrix},
TMEXPV<:Union{Nothing,AbstractMatrix},
Expand Down
12 changes: 9 additions & 3 deletions src/time_evolution/mcsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ If the environmental measurements register a quantum jump, the wave function und
- `jump_callback`: The Jump Callback type: Discrete or Continuous. The default is `ContinuousLindbladJumpCallback()`, which is more precise.
- `progress_bar`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
- `prob_func`: Function to use for generating the ODEProblem.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `ProgressBar` object, and the (optional) `RemoteChannel` object.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `Progress` object, and the (optional) `RemoteChannel` object.
- `kwargs`: The keyword arguments for the ODEProblem.

# Notes
Expand Down Expand Up @@ -238,7 +238,13 @@ function mcsolveEnsembleProblem(
_prob_func = isnothing(prob_func) ? _ensemble_dispatch_prob_func(rng, ntraj, tlist, _mcsolve_prob_func) : prob_func
_output_func =
output_func isa Nothing ?
_ensemble_dispatch_output_func(ensemblealg, progress_bar, ntraj, _mcsolve_output_func) : output_func
_ensemble_dispatch_output_func(
ensemblealg,
progress_bar,
ntraj,
_mcsolve_output_func;
progr_desc = "(mcsolve) ",
) : output_func

prob_mc = mcsolveProblem(
H,
Expand Down Expand Up @@ -332,7 +338,7 @@ If the environmental measurements register a quantum jump, the wave function und
- `jump_callback`: The Jump Callback type: Discrete or Continuous. The default is `ContinuousLindbladJumpCallback()`, which is more precise.
- `progress_bar`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
- `prob_func`: Function to use for generating the ODEProblem.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `ProgressBar` object, and the (optional) `RemoteChannel` object.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `Progress` object, and the (optional) `RemoteChannel` object.
- `keep_runs_results`: Whether to save the results of each trajectory. Default to `Val(false)`.
- `normalize_states`: Whether to normalize the states. Default to `Val(true)`.
- `kwargs`: The keyword arguments for the ODEProblem.
Expand Down
10 changes: 8 additions & 2 deletions src/time_evolution/mesolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ mesolve_map(
# this method is for advanced usage
# User can define their own iterator structure, prob_func and output_func
# - `prob_func`: Function to use for generating the ODEProblem.
# - `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `ProgressBar` object, and the (optional) `RemoteChannel` object.
# - `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `Progress` object, and the (optional) `RemoteChannel` object.
#
# Return: An array of TimeEvolutionSol objects with the size same as the given iter.
function mesolve_map(
Expand All @@ -368,7 +368,13 @@ function mesolve_map(
_prob_func = isnothing(prob_func) ? (prob, i, repeat) -> _se_me_map_prob_func(prob, i, repeat, iter) : prob_func
_output_func =
isnothing(output_func) ?
_ensemble_dispatch_output_func(ensemblealg, progress_bar, ntraj, _standard_output_func) : output_func
_ensemble_dispatch_output_func(
ensemblealg,
progress_bar,
ntraj,
_standard_output_func;
progr_desc = "(mesolve_map) ",
) : output_func
ens_prob = TimeEvolutionProblem(
EnsembleProblem(prob.prob, prob_func = _prob_func, output_func = _output_func[1], safetycopy = false),
prob.times,
Expand Down
10 changes: 8 additions & 2 deletions src/time_evolution/sesolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ sesolve_map(H::Union{AbstractQuantumObject{Operator},Tuple}, ψ0::QuantumObject{
# this method is for advanced usage
# User can define their own iterator structure, prob_func and output_func
# - `prob_func`: Function to use for generating the ODEProblem.
# - `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `ProgressBar` object, and the (optional) `RemoteChannel` object.
# - `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `Progress` object, and the (optional) `RemoteChannel` object.
#
# Return: An array of TimeEvolutionSol objects with the size same as the given iter.
function sesolve_map(
Expand All @@ -277,7 +277,13 @@ function sesolve_map(
_prob_func = isnothing(prob_func) ? (prob, i, repeat) -> _se_me_map_prob_func(prob, i, repeat, iter) : prob_func
_output_func =
isnothing(output_func) ?
_ensemble_dispatch_output_func(ensemblealg, progress_bar, ntraj, _standard_output_func) : output_func
_ensemble_dispatch_output_func(
ensemblealg,
progress_bar,
ntraj,
_standard_output_func;
progr_desc = "(sesolve_map) ",
) : output_func
ens_prob = TimeEvolutionProblem(
EnsembleProblem(prob.prob, prob_func = _prob_func, output_func = _output_func[1], safetycopy = false),
prob.times,
Expand Down
14 changes: 9 additions & 5 deletions src/time_evolution/smesolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ function smesolveProblem(
to_dense(_complex_float_type(T), mat2vec(ket2dm(ψ0).data))
end

progr = ProgressBar(length(tlist), enable = getVal(progress_bar))

sc_ops_evo_data = Tuple(map(get_data ∘ QobjEvo, sc_ops_list))

K = get_data(L_evo)
Expand Down Expand Up @@ -203,7 +201,7 @@ Above, ``\hat{C}_i`` represent the collapse operators related to pure dissipatio
- `ntraj`: Number of trajectories to use. Default is `500`.
- `ensemblealg`: Ensemble method to use. Default to `EnsembleThreads()`.
- `prob_func`: Function to use for generating the SDEProblem.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `ProgressBar` object, and the (optional) `RemoteChannel` object.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `Progress` object, and the (optional) `RemoteChannel` object.
- `progress_bar`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
- `store_measurement`: Whether to store the measurement expectation values. Default is `Val(false)`.
- `kwargs`: The keyword arguments for the ODEProblem.
Expand Down Expand Up @@ -251,7 +249,13 @@ function smesolveEnsembleProblem(
) : prob_func
_output_func =
output_func isa Nothing ?
_ensemble_dispatch_output_func(ensemblealg, progress_bar, ntraj, _standard_output_func) : output_func
_ensemble_dispatch_output_func(
ensemblealg,
progress_bar,
ntraj,
_standard_output_func;
progr_desc = "(smesolve) ",
) : output_func

prob_sme = smesolveProblem(
H,
Expand Down Expand Up @@ -332,7 +336,7 @@ Above, ``\hat{C}_i`` represent the collapse operators related to pure dissipatio
- `ntraj`: Number of trajectories to use. Default is `500`.
- `ensemblealg`: Ensemble method to use. Default to `EnsembleThreads()`.
- `prob_func`: Function to use for generating the SDEProblem.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `ProgressBar` object, and the (optional) `RemoteChannel` object.
- `output_func`: a `Tuple` containing the `Function` to use for generating the output of a single trajectory, the (optional) `Progress` object, and the (optional) `RemoteChannel` object.
- `progress_bar`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
- `keep_runs_results`: Whether to save the results of each trajectory. Default to `Val(false)`.
- `store_measurement`: Whether to store the measurement expectation values. Default is `Val(false)`.
Expand Down
Loading
Loading