Skip to content

Commit a7c3818

Browse files
authored
docs: rm saving manuel (#401)
1 parent 1856bcc commit a7c3818

File tree

6 files changed

+294
-12
lines changed

6 files changed

+294
-12
lines changed

docs/pages.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pages = [
3434
"Plotting" => "manual/plotting.md",
3535
"Time Evolution" => "manual/time_dependent.md",
3636
"Linear Response" => "manual/linear_response.md",
37-
"Saving and Loading" => "manual/saving.md",
3837
"SciML Extension" => "manual/SciMLExt.md",
3938
]
4039
],

docs/src/examples/ab_initio_noise.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This example demonstrates how to compute the spectra obtained from probing the s
99
````@example ab_initio_noise
1010
using HarmonicBalance, Plots
1111
using ModelingToolkit, StaticArrays, StochasticDiffEq, DSP
12+
using ModelingToolkit: setp
1213
````
1314

1415
We first define a gelper function to compute power spectral density of the simulated response

docs/src/examples/cumulants_KPO.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
```@meta
2+
EditURL = "../../../examples/cumulants_KPO.jl"
3+
```
4+
5+
# Cumulant approximations for the Kerr parametric oscillator
6+
7+
Let us compare the higher cumulant approximations for the Kerr parametric oscillator (KPO). The KPO is a model for a cavity with a Kerr nonlinearity and a parametric drive after one applied the Rotating Wave approximation. For this we use the `QuantumCumulants` and the `QuantumCumulantsExt` module in `HarmonicBalance`.
8+
9+
````@example cumulants_KPO
10+
using QuantumCumulants, HarmonicBalance, Plots
11+
````
12+
13+
## first order cumulant
14+
15+
Let us define the Hamiltonian of the KPO using QuantumCumulants.
16+
17+
````@example cumulants_KPO
18+
h = FockSpace(:cavity)
19+
@qnumbers a::Destroy(h)
20+
@variables Δ::Real U::Real G::Real κ::Real
21+
param = [Δ, U, G, κ]
22+
23+
H_RWA = (-Δ + U) * a' * a + U * (a'^2 * a^2) / 2 - G * (a' * a' + a * a) / 2
24+
ops = [a, a']
25+
````
26+
27+
We can now compute the mean-field equations for the KPO using the `meanfield` function from `QuantumCumulants`. We need the complete the system equations of moition using the `complete` function.
28+
29+
````@example cumulants_KPO
30+
eqs_RWA = meanfield(ops, H_RWA, [a]; rates=[κ], order=1)
31+
eqs_completed_RWA = complete(eqs_RWA)
32+
````
33+
34+
To compute the steady states of the KPO, we use `HarmonicBalance`. We define the HomotopyContinuation problem using the `Problem`.
35+
36+
````@example cumulants_KPO
37+
fixed = (U => 0.001, κ => 0.002)
38+
varied = (Δ => range(-0.03, 0.03, 100), G => range(1e-5, 0.02, 100))
39+
problem_c1 = HarmonicBalance.Problem(eqs_completed_RWA, param, varied, fixed)
40+
````
41+
42+
This gives us the phase
43+
44+
````@example cumulants_KPO
45+
result = get_steady_states(problem_c1, WarmUp())
46+
plot_phase_diagram(result; class="stable")
47+
````
48+
49+
## second order cumulant
50+
51+
The next order cumulant can be computed by setting the `order` keyword.
52+
53+
````@example cumulants_KPO
54+
ops = [a]
55+
eqs_RWA = meanfield(ops, H_RWA, [a]; rates=[κ], order=2)
56+
eqs_c2 = complete(eqs_RWA)
57+
problem_c2 = HarmonicBalance.Problem(eqs_c2, param, varied, fixed)
58+
````
59+
60+
Which gives us the phase diagram
61+
62+
````@example cumulants_KPO
63+
result = get_steady_states(problem_c2, WarmUp())
64+
plot_phase_diagram(result; class="stable", clim=(0, 4))
65+
````
66+
67+
However, the phase diagram seems to wrong. Indeed, plotting, the photon number `a⁺aᵣ` shows that and additional state with the negative photon number is stable. However, the this is unphysical.
68+
69+
````@example cumulants_KPO
70+
fixed = (U => 0.001, κ => 0.002, G => 0.01)
71+
varied = (Δ => range(-0.03, 0.03, 200))
72+
problem_c2 = HarmonicBalance.Problem(eqs_c2, param, varied, fixed)
73+
result = get_steady_states(problem_c2, TotalDegree())
74+
plot(result; y="a⁺aᵣ", class="stable")
75+
````
76+
77+
Let us classify the solutions having negative photon numbers. That way we can filter out these solutions.
78+
79+
````@example cumulants_KPO
80+
classify_solutions!(result, "a⁺aᵣ < 0", "neg photon number");
81+
plot(result; y="aᵣ", class="stable", not_class="neg photon number")
82+
````
83+
84+
## third order cumulant
85+
86+
Similarly, for third order
87+
88+
````@example cumulants_KPO
89+
ops = [a]
90+
eqs_RWA = meanfield(ops, H_RWA, [a]; rates=[κ], order=3)
91+
eqs_c3 = complete(eqs_RWA)
92+
93+
fixed = (U => 0.001, κ => 0.002, G => 0.01)
94+
varied = (Δ => range(-0.03, 0.03, 50))
95+
problem_c3 = HarmonicBalance.Problem(eqs_c3, param, varied, fixed)
96+
result = get_steady_states(problem_c3, TotalDegree())
97+
classify_solutions!(result, "a⁺aᵣ < 0", "neg photon number");
98+
plot(result; y="a⁺aᵣ", class="stable")
99+
````
100+
101+
---
102+
103+
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
104+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
```@meta
2+
EditURL = "../../../examples/harmonic_oscillator_KB_vs_HB.jl"
3+
```
4+
5+
Harmonic oscillator: comparison of KB and HB methods
6+
7+
````@example harmonic_oscillator_KB_vs_HB
8+
using HarmonicBalance, Plots
9+
10+
@variables ω ω0 F γ t x(t)
11+
diff_eq = DifferentialEquation(d(x, t, 2) + ω0^2 * x + γ * d(x, t) ~ F * cos(ω * t), x)
12+
add_harmonic!(diff_eq, x, ω)
13+
````
14+
15+
````@example harmonic_oscillator_KB_vs_HB
16+
krylov_eq1 = get_krylov_equations(diff_eq; order=1)
17+
````
18+
19+
````@example harmonic_oscillator_KB_vs_HB
20+
krylov_eq2 = get_krylov_equations(diff_eq; order=2)
21+
````
22+
23+
````@example harmonic_oscillator_KB_vs_HB
24+
harmonic_eq = get_harmonic_equations(diff_eq)
25+
harmonic_eq = rearrange_standard(harmonic_eq)
26+
````
27+
28+
````@example harmonic_oscillator_KB_vs_HB
29+
varied = (ω => range(0.1, 1.9, 200)) # range of parameter values
30+
fixed = (ω0 => 1.0, γ => 0.05, F => 0.1) # fixed parameters
31+
result_krylov1 = get_steady_states(krylov_eq1, varied, fixed)
32+
result_krylov2 = get_steady_states(krylov_eq2, varied, fixed)
33+
result_harmonic = get_steady_states(harmonic_eq, varied, fixed);
34+
nothing #hide
35+
````
36+
37+
````@example harmonic_oscillator_KB_vs_HB
38+
plot(
39+
plot(result_krylov1; y="u1^2+v1^2", label="Krylov 1"),
40+
plot(result_krylov2; y="u1^2+v1^2", label="Krylov 2"),
41+
plot(result_harmonic; y="u1^2+v1^2", label="Harmonic");
42+
layout=(3, 1),
43+
)
44+
````
45+
46+
````@example harmonic_oscillator_KB_vs_HB
47+
plot(
48+
plot(result_krylov1; y="u1", label="Krylov 1", legend=:best),
49+
plot(result_krylov2; y="u1", label="Krylov 2", legend=:best),
50+
plot(result_harmonic; y="u1", label="Harmonic", legend=:best);
51+
layout=(3, 1),
52+
)
53+
````
54+
55+
````@example harmonic_oscillator_KB_vs_HB
56+
plot(
57+
plot(result_krylov1; y="v1", label="Krylov 1", legend=:best),
58+
plot(result_krylov2; y="v1", label="Krylov 2", legend=:best),
59+
plot(result_harmonic; y="v1", label="Harmonic", legend=:best);
60+
layout=(3, 1),
61+
)
62+
````
63+
64+
````@example harmonic_oscillator_KB_vs_HB
65+
plot(
66+
plot_eigenvalues(result_krylov1, 1; title="Krylov 1", ylims=(-4, 4)),
67+
plot_eigenvalues(result_krylov2, 1; title="Krylov 2", ylims=(-4, 4)),
68+
plot_eigenvalues(result_harmonic, 1; title="Harmonic", ylims=(-4, 4));
69+
layout=(3, 1),
70+
)
71+
````
72+
73+
````@example harmonic_oscillator_KB_vs_HB
74+
plot(
75+
plot_linear_response(
76+
result_krylov1, x, 1; Ω_range=range(0.1, 1.9, 200), title="Krylov 1"
77+
),
78+
plot_linear_response(
79+
result_krylov2, x, 1; Ω_range=range(0.1, 1.9, 200), title="Krylov 2"
80+
),
81+
plot_linear_response(
82+
result_harmonic, x, 1; Ω_range=range(0.1, 1.9, 200), title="Harmonic"
83+
);
84+
layout=(3, 1),
85+
clims=(0, 250),
86+
)
87+
````
88+
89+
---
90+
91+
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
92+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
```@meta
2+
EditURL = "../../../examples/steady_state_sweep.jl"
3+
```
4+
5+
# Steady state sweeps
6+
7+
````@example steady_state_sweep
8+
using HarmonicBalance, SteadyStateDiffEq, ModelingToolkit
9+
using BenchmarkTools, Plots, StaticArrays, OrdinaryDiffEq, LinearAlgebra
10+
using HarmonicBalance: OrderedDict
11+
12+
@variables α ω ω0 F γ η t x(t);
13+
14+
diff_eq = DifferentialEquation(
15+
d(x, t, 2) + ω0^2 * x + α * x^3 + γ * d(x, t) + η * d(x, t) * x^2 ~ F * cos(ω * t), x
16+
)
17+
add_harmonic!(diff_eq, x, ω)
18+
harmonic_eq = get_harmonic_equations(diff_eq)
19+
20+
fixed = (ω0 => 1.0, γ => 1e-2, F => 0.02, α => 1.0, η => 0.3)
21+
ω_span = (0.8, 1.3);
22+
ω_range = range(ω_span..., 201);
23+
varied = ω => ω_range
24+
25+
result_HB = get_steady_states(harmonic_eq, varied, fixed)
26+
plot(result_HB, "sqrt(u1^2+v1^2)")
27+
````
28+
29+
## Steady state sweep using `SteadyStateDiffEq.jl`
30+
31+
````@example steady_state_sweep
32+
param = OrderedDict(merge(Dict(fixed), Dict(ω => 1.1)))
33+
x0 = [0, 0.0];
34+
prob_ss = SteadyStateProblem(
35+
harmonic_eq, x0, param; in_place=false, u0_constructor=x -> SVector(x...)
36+
)
37+
38+
varied = 6 => ω_range
39+
result_ss = steady_state_sweep(
40+
prob_ss, DynamicSS(Rodas5()); varied, abstol=1e-5, reltol=1e-5
41+
)
42+
43+
plot(result_HB, "sqrt(u1^2+v1^2)")
44+
plot!(ω_range, norm.(result_ss); c=:gray, ls=:dash)
45+
````
46+
47+
## Adiabatic evolution
48+
49+
````@example steady_state_sweep
50+
timespan = (0.0, 50_000)
51+
sweep = AdiabaticSweep(ω => (0.8, 1.3), timespan) # linearly interpolate between two values at two times
52+
ode_problem = ODEProblem(harmonic_eq, fixed; u0=[0.01; 0.0], timespan, sweep)
53+
time_soln = solve(ode_problem, Tsit5(); saveat=250)
54+
55+
plot(result_HB, "sqrt(u1^2+v1^2)")
56+
plot(time_soln.t, norm.(time_soln.u))
57+
````
58+
59+
## using follow_branch
60+
61+
````@example steady_state_sweep
62+
followed_branch, Ys = follow_branch(1, result_HB; y="√(u1^2+v1^2)")
63+
Y_followed_gr =
64+
real.([Ys[param_idx][branch] for (param_idx, branch) in enumerate(followed_branch)]);
65+
66+
plot(result_HB, "sqrt(u1^2+v1^2)")
67+
plot!(ω_range, Y_followed_gr; c=:gray, ls=:dash)
68+
````
69+
70+
## comparison
71+
72+
````@example steady_state_sweep
73+
@btime result_ss = steady_state_sweep(
74+
prob_ss, DynamicSS(Rodas5()); varied, abstol=1e-5, reltol=1e-5
75+
)
76+
77+
@btime time_soln = solve(ode_problem, Tsit5(); saveat=250)
78+
79+
@btime begin
80+
followed_branch, Ys = follow_branch(1, result_HB; y="√(u1^2+v1^2)")
81+
Y_followed_gr =
82+
real.([Ys[param_idx][branch] for (param_idx, branch) in enumerate(followed_branch)])
83+
end
84+
````
85+
86+
Plotting them together gives:
87+
88+
````@example steady_state_sweep
89+
plot(ω_range, norm.(result_ss))
90+
plot!(ω_range, norm.(time_soln.u))
91+
plot!(ω_range, Y_followed_gr)
92+
````
93+
94+
---
95+
96+
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
97+

docs/src/manual/saving.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)