Skip to content

Commit 6647408

Browse files
Add more steadystate and Dynamical Shifted Fock benchmarks (#557)
1 parent 4c4d03a commit 6647408

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-10
lines changed

CHANGELOG.md

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

1010
- Fix `cite()` bibtex output. ([#552])
1111
- Add `qeye_like` and `qzero_like`, which are synonyms of `one` and `zero`. ([#555])
12+
- Add steadystate and DSF benchmarks. The `SteadyStateODESOlver` tolerances are lowered to `terminate_reltol=1e-4` and `terminate_abstol=1e-6` to improve speed at the cost of accuracy. ([#557])
1213

1314
## [v0.36.0]
1415
Release date: 2025-09-29
@@ -328,3 +329,4 @@ Release date: 2024-11-13
328329
[#546]: https://github.com/qutip/QuantumToolbox.jl/issues/546
329330
[#552]: https://github.com/qutip/QuantumToolbox.jl/issues/552
330331
[#555]: https://github.com/qutip/QuantumToolbox.jl/issues/555
332+
[#557]: https://github.com/qutip/QuantumToolbox.jl/issues/557

benchmarks/Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[deps]
22
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3-
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
4-
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
53
QuantumToolbox = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"
4+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
function benchmark_dsf!(SUITE)
2+
F = 2
3+
Δ = 0.25
4+
κ = 1
5+
U = 0.01
6+
J = 0.5
7+
tlist = LinRange(0, 15, 300)
8+
9+
N = 5
10+
a1 = kron(destroy(N), qeye(N))
11+
a2 = kron(qeye(N), destroy(N))
12+
function H_dsf(op_list, p)
13+
Δ = p.Δ
14+
F = p.F
15+
U = p.U
16+
J = p.J
17+
a1, a2 = op_list
18+
return Δ * a1' * a1 +
19+
Δ * a2' * a2 +
20+
U * a1'^2 * a1^2 +
21+
U * a2'^2 * a2^2 +
22+
F * (a1 + a1') +
23+
J * (a1' * a2 + a1 * a2')
24+
end
25+
function c_ops_dsf(op_list, p)
26+
κ = p.κ
27+
a1, a2 = op_list
28+
return [κ * a1, κ * a2]
29+
end
30+
function e_ops_dsf(op_list, p)
31+
a1, a2 = op_list
32+
return [a1' * a1, a2' * a2]
33+
end
34+
op_list = [a1, a2]
35+
ψ0 = kron(fock(N, 0), fock(N, 0))
36+
α0 = 1.5
37+
α0_l = [α0, α0]
38+
dsf_params == Δ, F = F, κ = κ, U = U, J = J)
39+
40+
SUITE["Time Evolution"]["Dynamical Shifted Fock"]["mesolve"] = @benchmarkable dsf_mesolve(
41+
$H_dsf,
42+
$ψ0,
43+
$tlist,
44+
$c_ops_dsf,
45+
$op_list,
46+
$α0_l,
47+
$dsf_params,
48+
e_ops = $e_ops_dsf,
49+
progress_bar = Val(false),
50+
)
51+
52+
SUITE["Time Evolution"]["Dynamical Shifted Fock"]["mcsolve"]["Serial"] = @benchmarkable dsf_mcsolve(
53+
$H_dsf,
54+
$ψ0,
55+
$tlist,
56+
$c_ops_dsf,
57+
$op_list,
58+
$α0_l,
59+
$dsf_params,
60+
ntraj = 100,
61+
e_ops = $e_ops_dsf,
62+
progress_bar = Val(false),
63+
ensemblealg = EnsembleSerial(),
64+
)
65+
66+
SUITE["Time Evolution"]["Dynamical Shifted Fock"]["mcsolve"]["Multithreaded"] = @benchmarkable dsf_mcsolve(
67+
$H_dsf,
68+
$ψ0,
69+
$tlist,
70+
$c_ops_dsf,
71+
$op_list,
72+
$α0_l,
73+
$dsf_params,
74+
ntraj = 100,
75+
e_ops = $e_ops_dsf,
76+
progress_bar = Val(false),
77+
ensemblealg = EnsembleThreads(),
78+
)
79+
80+
return nothing
81+
end

benchmarks/runbenchmarks.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ using BenchmarkTools
22
using LinearAlgebra
33
using SparseArrays
44
using QuantumToolbox
5-
using OrdinaryDiffEq
6-
using LinearSolve
5+
using SciMLBase: EnsembleSerial, EnsembleThreads
76

87
BLAS.set_num_threads(1)
98

109
const SUITE = BenchmarkGroup()
1110

1211
include("correlations_and_spectrum.jl")
1312
include("dynamical_fock_dimension.jl")
13+
include("dynamical_shifted_fock.jl")
1414
include("eigenvalues.jl")
1515
include("steadystate.jl")
1616
include("timeevolution.jl")
1717

1818
benchmark_correlations_and_spectrum!(SUITE)
1919
benchmark_dfd!(SUITE)
20+
benchmark_dsf!(SUITE)
2021
benchmark_eigenvalues!(SUITE)
2122
benchmark_steadystate!(SUITE)
2223
benchmark_timeevolution!(SUITE)

benchmarks/steadystate.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ function benchmark_steadystate!(SUITE)
1111

1212
SUITE["Steadystate"]["Direct"] = @benchmarkable steadystate($H, $c_ops)
1313

14+
SUITE["Steadystate"]["Iterative"] = @benchmarkable steadystate($H, $c_ops; solver = SteadyStateLinearSolver())
15+
16+
SUITE["Steadystate"]["ODE"] = @benchmarkable steadystate($H, $c_ops; solver = SteadyStateODESolver())
17+
1418
return nothing
1519
end

src/steadystate.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ end
4747
alg = Tsit5(),
4848
ψ0 = nothing,
4949
tmax = Inf,
50-
terminate_reltol = 1e-5,
51-
terminate_abstol = 1e-7
50+
terminate_reltol = 1e-4,
51+
terminate_abstol = 1e-6
5252
)
5353
5454
An ordinary differential equation (ODE) solver for solving [`steadystate`](@ref). It solves the stationary state based on [`mesolve`](@ref) with a termination condition.
@@ -69,8 +69,8 @@ or
6969
- `alg::OrdinaryDiffEqAlgorithm=Tsit5()`: The algorithm to solve the ODE.
7070
- `ψ0::Union{Nothing,QuantumObject}=nothing`: The initial state of the system. If not specified, a random pure state will be generated.
7171
- `tmax::Real=Inf`: The final time step for the steady state problem.
72-
- `terminate_reltol` = The relative tolerance for stationary state terminate condition. Default to `1e-5`.
73-
- `terminate_abstol` = The absolute tolerance for stationary state terminate condition. Default to `1e-7`.
72+
- `terminate_reltol` = The relative tolerance for stationary state terminate condition. Default to `1e-4`.
73+
- `terminate_abstol` = The absolute tolerance for stationary state terminate condition. Default to `1e-6`.
7474
7575
!!! warning "Tolerances for terminate condition"
7676
The terminate condition tolerances `terminate_reltol` and `terminate_abstol` should be larger than `reltol` and `abstol` of [`mesolve`](@ref), respectively.
@@ -87,8 +87,8 @@ Base.@kwdef struct SteadyStateODESolver{
8787
alg::MT = Tsit5()
8888
ψ0::ST = nothing
8989
tmax::TT = Inf
90-
terminate_reltol::RT = 10 * DEFAULT_ODE_SOLVER_OPTIONS.reltol
91-
terminate_abstol::AT = 10 * DEFAULT_ODE_SOLVER_OPTIONS.abstol
90+
terminate_reltol::RT = 1e-4
91+
terminate_abstol::AT = 1e-6
9292
end
9393

9494
@doc raw"""

0 commit comments

Comments
 (0)