Skip to content

Commit 3db51c6

Browse files
committed
allow customizing progress bar and bump to v0.38.1
1 parent 1002246 commit 3db51c6

File tree

8 files changed

+45
-23
lines changed

8 files changed

+45
-23
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)
99

10+
## [v0.38.1]
11+
Release date: 2025-10-27
12+
13+
- Add `ProgressMeterKWARGS` in `QuantumToolbox.settings` for customizing progress bar. ([#579])
14+
1015
## [v0.38.0]
1116
Release date: 2025-10-27
1217

@@ -248,6 +253,7 @@ Release date: 2024-11-13
248253
[v0.36.0]: https://github.com/qutip/QuantumToolbox.jl/releases/tag/v0.36.0
249254
[v0.37.0]: https://github.com/qutip/QuantumToolbox.jl/releases/tag/v0.37.0
250255
[v0.38.0]: https://github.com/qutip/QuantumToolbox.jl/releases/tag/v0.38.0
256+
[v0.38.1]: https://github.com/qutip/QuantumToolbox.jl/releases/tag/v0.38.1
251257
[#86]: https://github.com/qutip/QuantumToolbox.jl/issues/86
252258
[#139]: https://github.com/qutip/QuantumToolbox.jl/issues/139
253259
[#271]: https://github.com/qutip/QuantumToolbox.jl/issues/271
@@ -350,3 +356,4 @@ Release date: 2024-11-13
350356
[#572]: https://github.com/qutip/QuantumToolbox.jl/issues/572
351357
[#575]: https://github.com/qutip/QuantumToolbox.jl/issues/575
352358
[#576]: https://github.com/qutip/QuantumToolbox.jl/issues/576
359+
[#579]: https://github.com/qutip/QuantumToolbox.jl/issues/579

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "QuantumToolbox"
22
uuid = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"
3-
version = "0.38.0"
3+
version = "0.38.1"
44
authors = ["Alberto Mercurio", "Yi-Te Huang"]
55

66
[deps]

docs/src/users_guide/settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Here, we list out each setting along with the specific functions that will use i
1515
- `auto_tidyup::Bool = true` : Automatically tidyup during the following situations:
1616
* Solving for eigenstates, including [`eigenstates`](@ref), [`eigsolve`](@ref), [`eigsolve_al`](@ref)
1717
* Creating [`bloch_redfield_tensor`](@ref) or [`brterm`](@ref), and solving [`brmesolve`](@ref).
18+
- `ProgressMeterKWARGS::NamedTuple = (showspeed = true, printed = true)` : Default keyword arguments for progress bar in [`ProgressMeter.jl`](https://github.com/timholy/ProgressMeter.jl). This allows the customization of progress bar.
1819
- (to be announced)
1920

2021
## Change default settings

src/settings.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
Base.@kwdef mutable struct Settings
22
tidyup_tol::Float64 = 1e-14
33
auto_tidyup::Bool = true
4+
ProgressMeterKWARGS::NamedTuple = (showspeed = true, printed = true)
45
end
56

67
function Base.show(io::IO, s::Settings)
7-
# To align the output and make it easier to read
8-
# we use rpad `11`, which is the length of string: `auto_tidyup`
8+
# get maximum field name to align the output and make it easier to read
9+
maxLen = maximum(length String, fieldnames(Settings))
10+
911
println(io, "QuantumToolbox.jl Settings")
1012
println(io, "--------------------------")
11-
map(n -> println(io, rpad("$n", 11, " "), " = ", getfield(s, n)), fieldnames(Settings))
13+
map(n -> println(io, rpad("$n", maxLen, " "), " = ", getfield(s, n)), fieldnames(Settings))
1214
return nothing
1315
end
1416

@@ -21,6 +23,7 @@ Contains all the default global settings of QuantumToolbox.jl.
2123
2224
- `tidyup_tol::Float64 = 1e-14` : tolerance for [`tidyup`](@ref) and [`tidyup!`](@ref).
2325
- `auto_tidyup::Bool = true` : Automatically tidyup.
26+
- `ProgressMeterKWARGS::NamedTuple = (showspeed = true, printed = true)` : Default keyword arguments for progress bar in [`ProgressMeter.jl`](https://github.com/timholy/ProgressMeter.jl). This allows the customization of progress bar.
2427
2528
For detailed explanation of each settings, see our documentation [here](https://qutip.org/QuantumToolbox.jl/stable/users_guide/settings).
2629

src/time_evolution/callback_helpers/callback_helpers.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ function _generate_save_callback(e_ops, tlist, progress_bar, method)
5959

6060
progr =
6161
getVal(progress_bar) ?
62-
Progress(length(tlist), showspeed = true, enabled = getVal(progress_bar), desc = _get_progress_desc(method)) :
63-
nothing
62+
Progress(
63+
length(tlist);
64+
enabled = getVal(progress_bar),
65+
desc = _get_progress_desc(method),
66+
settings.ProgressMeterKWARGS...,
67+
) : nothing
6468

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

@@ -72,7 +76,9 @@ function _generate_stochastic_save_callback(e_ops, sc_ops, tlist, store_measurem
7276
e_ops_data = e_ops isa Nothing ? nothing : _get_e_ops_data(e_ops, method)
7377
m_ops_data = _get_m_ops_data(sc_ops, method)
7478

75-
progr = getVal(progress_bar) ? Progress(length(tlist), showspeed = true, enabled = getVal(progress_bar)) : nothing
79+
progr =
80+
getVal(progress_bar) ?
81+
Progress(length(tlist); enabled = getVal(progress_bar), settings.ProgressMeterKWARGS...) : nothing
7682

7783
expvals = e_ops isa Nothing ? nothing : Array{ComplexF64}(undef, length(e_ops), length(tlist))
7884
m_expvals = getVal(store_measurement) ? Array{Float64}(undef, length(sc_ops), length(tlist) - 1) : nothing

src/time_evolution/time_evolution.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function _ensemble_dispatch_output_func(
374374
progr_desc = "Progress: ",
375375
) where {ET<:Union{EnsembleSerial,EnsembleThreads}}
376376
if getVal(progress_bar)
377-
progr = Progress(ntraj, showspeed = true, enabled = getVal(progress_bar), desc = progr_desc)
377+
progr = Progress(ntraj; enabled = getVal(progress_bar), desc = progr_desc, settings.ProgressMeterKWARGS...)
378378
f = (sol, i) -> _ensemble_output_func_progress(sol, i, progr, output_func)
379379
return (f, progr, nothing)
380380
else
@@ -389,7 +389,7 @@ function _ensemble_dispatch_output_func(
389389
progr_desc = "Progress... ",
390390
) where {ET<:Union{EnsembleSplitThreads,EnsembleDistributed}}
391391
if getVal(progress_bar)
392-
progr = Progress(ntraj, showspeed = true, enabled = getVal(progress_bar), desc = progr_desc)
392+
progr = Progress(ntraj; enabled = getVal(progress_bar), desc = progr_desc, settings.ProgressMeterKWARGS...)
393393
progr_channel::RemoteChannel{Channel{Bool}} = RemoteChannel(() -> Channel{Bool}(1))
394394

395395
f = (sol, i) -> _ensemble_output_func_distributed(sol, i, progr_channel, output_func)

src/visualization.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,23 @@ end
152152

153153
const BLOCH_DATA_FIELDS = (:points, :vectors, :lines, :arcs)
154154
function Base.show(io::IO, b::Bloch)
155-
# To align the output and make it easier to read
156-
# we use rpad `17` and `19` for Bloch sphere data and properties, respectively
155+
# Align the output and make it easier to read
156+
# we use rpad `17` and `maxLen` for Bloch sphere data and properties, respectively
157157
# 17 is the length of string: `Number of vectors`
158-
# 19 is the length of string: `point_default_color`
158+
# maxLen is the maximum length among all field names
159+
maxLen = maximum(length String, fieldnames(Settings))
160+
159161
println(io, "Bloch Sphere\n")
160162
println(io, "data:")
161163
println(io, "-----")
162164
map(n -> println(io, rpad("Number of $n", 17, " "), " = ", length(getfield(b, n))), BLOCH_DATA_FIELDS)
163165
println(io, "")
164166
println(io, "properties:")
165167
println(io, "-----------")
166-
map(n -> (n BLOCH_DATA_FIELDS) && (println(io, rpad("$n", 19, " "), " = ", getfield(b, n))), fieldnames(Bloch))
168+
map(
169+
n -> (n BLOCH_DATA_FIELDS) && (println(io, rpad("$n", maxLen, " "), " = ", getfield(b, n))),
170+
fieldnames(Bloch),
171+
)
167172
return nothing
168173
end
169174

test/core-test/time_evolution.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ end
140140
@inferred sesolveProblem(H, ψ0, tlist, progress_bar = Val(false))
141141
@inferred sesolveProblem(H, ψ0, [0, 10], progress_bar = Val(false))
142142
@inferred sesolveProblem(H, TESetup.ψ0_int, tlist, progress_bar = Val(false))
143-
@inferred sesolve(H, ψ0, tlist, e_ops = e_ops, progress_bar = Val(false))
143+
@inferred sesolve(H, ψ0, tlist, e_ops = e_ops, progress_bar = Val(true)) # test progress bar
144144
@inferred sesolve(H, ψ0, tlist, progress_bar = Val(false))
145145
@inferred sesolve(H, ψ0, tlist, e_ops = e_ops, saveat = saveat, progress_bar = Val(false))
146146
@inferred sesolve(H, ψ0, tlist, e_ops = (TESetup.a' * TESetup.a, TESetup.a'), progress_bar = Val(false)) # We test the type inference for Tuple of different types
@@ -171,7 +171,7 @@ end
171171
ωq_fun(p, t) = p[2]
172172
H = QobjEvo(a' * a, ωc_fun) + QobjEvo(σz / 2, ωq_fun) + g * (a' * σm + a * σm')
173173

174-
sols0 = sesolve_map(TESetup.H, ψ0_list, tlist; e_ops = e_ops) # no params, but test progress_bar
174+
sols0 = sesolve_map(TESetup.H, ψ0_list, tlist; e_ops = e_ops, progress_bar = Val(false)) # no params
175175
sols1 = sesolve_map(H, ψ_0_e, tlist; e_ops = e_ops, params = (ωc_list, ωq_list), progress_bar = Val(false))
176176
sols2 = sesolve_map(H, ψ0_list, tlist; e_ops = e_ops, params = (ωc_list, ωq_list), progress_bar = Val(false))
177177
@test size(sols0) == (2,)
@@ -195,7 +195,7 @@ end
195195
end
196196

197197
@testset "Type Inference sesolve_map" begin
198-
@inferred sesolve_map(TESetup.H, ψ0_list, tlist; e_ops = e_ops, progress_bar = Val(false)) # no params
198+
@inferred sesolve_map(TESetup.H, ψ0_list, tlist; e_ops = e_ops, progress_bar = Val(true)) # no params, test progress bar
199199
@inferred sesolve_map(H, ψ0_list, tlist; e_ops = e_ops, params = (ωc_list, ωq_list), progress_bar = Val(false))
200200
end
201201
end
@@ -289,7 +289,7 @@ end
289289
@inferred mesolveProblem(H, ψ0, tlist, c_ops, e_ops = e_ops, progress_bar = Val(false))
290290
@inferred mesolveProblem(H, ψ0, [0, 10], c_ops, e_ops = e_ops, progress_bar = Val(false))
291291
@inferred mesolveProblem(H, TESetup.ψ0_int, tlist, c_ops, e_ops = e_ops, progress_bar = Val(false))
292-
@inferred mesolve(H, ψ0, tlist, c_ops, e_ops = e_ops, progress_bar = Val(false))
292+
@inferred mesolve(H, ψ0, tlist, c_ops, e_ops = e_ops, progress_bar = Val(true)) # also test progress bar
293293
@inferred mesolve(H, ψ0, tlist, c_ops, progress_bar = Val(false))
294294
@inferred mesolve(H, ψ0, tlist, c_ops, e_ops = e_ops, saveat = tlist, progress_bar = Val(false))
295295
@inferred mesolve(H, ψ0, tlist, (a, ad_t), e_ops = (a' * a, a'), progress_bar = Val(false)) # We test the type inference for Tuple
@@ -327,8 +327,8 @@ end
327327
ωq_fun(p, t) = p[2]
328328
H = QobjEvo(a' * a, ωc_fun) + QobjEvo(σz / 2, ωq_fun) + g * (a' * σm + a * σm')
329329

330-
# Test with multiple initial states but no params (this also tests progress_bar)
331-
sols0 = mesolve_map(TESetup.H, ψ0_list, tlist, c_ops; e_ops = e_ops)
330+
# Test with multiple initial states but no params
331+
sols0 = mesolve_map(TESetup.H, ψ0_list, tlist, c_ops; e_ops = e_ops, progress_bar = Val(false))
332332
# Test with single initial state
333333
sols1 = mesolve_map(H, ψ_0_e, tlist, c_ops; e_ops = e_ops, params = (ωc_list, ωq_list), progress_bar = Val(false))
334334
# Test with multiple initial states
@@ -375,7 +375,7 @@ end
375375
@test sols5 isa Array{<:TimeEvolutionSol}
376376

377377
@testset "Type Inference mesolve_map" begin
378-
@inferred mesolve_map(TESetup.H, ψ0_list, tlist, c_ops; e_ops = e_ops, progress_bar = Val(false)) # no params
378+
@inferred mesolve_map(TESetup.H, ψ0_list, tlist, c_ops; e_ops = e_ops, progress_bar = Val(true)) # no params, but test progress bar
379379
@inferred mesolve_map(
380380
H,
381381
ψ0_list,
@@ -564,7 +564,7 @@ end
564564
rng = rng,
565565
)
566566
@inferred mcsolve(H, ψ0, tlist, c_ops, ntraj = 5, e_ops = e_ops, progress_bar = Val(false), rng = rng)
567-
@inferred mcsolve(H, ψ0, tlist, c_ops, ntraj = 5, progress_bar = Val(true), rng = rng)
567+
@inferred mcsolve(H, ψ0, tlist, c_ops, ntraj = 5, progress_bar = Val(true), rng = rng) # test progress bar
568568
@inferred mcsolve(H, ψ0, [0, 10], c_ops, ntraj = 5, progress_bar = Val(false), rng = rng)
569569
@inferred mcsolve(H, TESetup.ψ0_int, tlist, c_ops, ntraj = 5, progress_bar = Val(false), rng = rng)
570570
@inferred mcsolve(H, ψ0, tlist, (a, a'), e_ops = (a' * a, a'), ntraj = 5, progress_bar = Val(false), rng = rng) # We test the type inference for Tuple of different types
@@ -696,7 +696,7 @@ end
696696
rng = rng,
697697
)
698698
@inferred ssesolve(H, ψ0, tlist, c_ops_tuple, ntraj = 5, e_ops = e_ops, progress_bar = Val(false), rng = rng)
699-
@inferred ssesolve(H, ψ0, tlist, c_ops_tuple, ntraj = 5, progress_bar = Val(true), rng = rng)
699+
@inferred ssesolve(H, ψ0, tlist, c_ops_tuple, ntraj = 5, progress_bar = Val(true), rng = rng) # test progress bar
700700
@inferred ssesolve(H, ψ0, [0, 10], c_ops_tuple, ntraj = 5, progress_bar = Val(false), rng = rng)
701701
@inferred ssesolve(H, TESetup.ψ0_int, tlist, c_ops_tuple, ntraj = 5, progress_bar = Val(false), rng = rng)
702702
@inferred ssesolve(
@@ -960,7 +960,7 @@ end
960960
ntraj = 5,
961961
progress_bar = Val(true),
962962
rng = rng,
963-
)
963+
) # test progress bar
964964
@inferred smesolve(
965965
H,
966966
ψ0,

0 commit comments

Comments
 (0)