Skip to content

Commit 23dd64f

Browse files
Change documentation
1 parent f365582 commit 23dd64f

File tree

2 files changed

+22
-57
lines changed

2 files changed

+22
-57
lines changed

docs/src/resources/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ mesolve
215215
mcsolve
216216
ssesolve
217217
smesolve
218+
sesolve_map
219+
mesolve_map
218220
dfd_mesolve
219221
liouvillian
220222
liouvillian_generalized

docs/src/users_guide/cluster.md

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -193,72 +193,35 @@ flush(stdout)
193193
end
194194

195195
@everywhere begin
196-
const Nc = 20
197-
const ωc = 1.0
198-
const g = 0.05
199-
const γ = 0.01
200-
const F = 0.01
196+
Nc = 20
197+
ωc = 1.0
198+
g = 0.05
199+
γ = 0.01
200+
F = 0.01
201201

202-
const a = tensor(destroy(Nc), qeye(2))
202+
a = tensor(destroy(Nc), qeye(2))
203203

204-
const σm = tensor(qeye(Nc), sigmam())
205-
const σp = tensor(qeye(Nc), sigmap())
204+
σm = tensor(qeye(Nc), sigmam())
205+
σp = tensor(qeye(Nc), sigmap())
206+
σz = tensor(qeye(Nc), sigmaz())
206207

207-
H(ωq) = ωc * a' * a + ωq * tensor(num(Nc), qeye(2)) + g * (a' * σm + a * σp)
208+
ωq_fun(p, t) = p[1] # ωq
209+
drive_fun(p, t) = p[3] * cos(p[2] * t) # F cos(ωd t)
208210

209-
coef(p, t) = p.F * cos(p.ωd * t) # coefficient for the time-dependent term
211+
H = ωc * a' * a + QobjEvo(σz / 2, ωq_fun) + g * (a' * σm + a * σp) + QobjEvo(a + a', drive_fun)
210212

211-
const c_ops = [sqrt(γ) * a, sqrt(γ) * σm]
212-
const e_ops = [a' * a]
213+
c_ops = [sqrt(γ) * a, sqrt(γ) * σm]
214+
e_ops = [a' * a]
213215
end
214216

215-
# Define the ODE problem and the EnsembleProblem generation function
217+
ωq_list = range(ωc - 3*g, ωc + 3*g, 100)
218+
ωd_list = range(ωc - 3*g, ωc + 3*g, 100)
219+
F_list = [F]
216220

217-
@everywhere begin
218-
ωq_list = range(ωc - 3*g, ωc + 3*g, 100)
219-
ωd_list = range(ωc - 3*g, ωc + 3*g, 100)
220-
221-
const iter = collect(Iterators.product(ωq_list, ωd_list))
222-
223-
function my_prob_func(prob, i, repeat, channel)
224-
ωq, ωd = iter[i]
225-
H_i = H(ωq)
226-
H_d_i = H_i + QobjEvo(a + a', coef) # Hamiltonian with a driving term
227-
228-
L = liouvillian(H_d_i, c_ops).data # Make the Liouvillian
229-
230-
put!(channel, true) # Update the progress bar channel
231-
232-
remake(prob, f=L, p=(F = F, ωd = ωd))
233-
end
234-
end
235-
236-
ωq, ωd = iter[1]
237-
H0 = H(ωq) + QobjEvo(a + a', coef)
238-
ψ0 = tensor(fock(Nc, 0), basis(2, 1)) # Ground State
221+
ψ0 = tensor(fock(Nc, 0), basis(2, 1))
239222
tlist = range(0, 20 / γ, 1000)
240223

241-
prob = mesolveProblem(H0, ψ0, tlist, c_ops, e_ops=e_ops, progress_bar=Val(false), params=(F = F, ωd = ωd))
242-
243-
### Just to print the progress bar
244-
progr = ProgressBar(length(iter))
245-
progr_channel::RemoteChannel{Channel{Bool}} = RemoteChannel(() -> Channel{Bool}(1))
246-
###
247-
ens_prob = EnsembleProblem(prob.prob, prob_func=(prob, i, repeat) -> my_prob_func(prob, i, repeat, progr_channel))
248-
249-
250-
@sync begin
251-
@async while take!(progr_channel)
252-
next!(progr)
253-
end
254-
255-
@async begin
256-
sol = solve(ens_prob, Tsit5(), EnsembleSplitThreads(), trajectories = length(iter))
257-
put!(progr_channel, false)
258-
end
259-
end
224+
sol = mesolve_map(H, ψ0, tlist, c_ops; e_ops = e_ops, params = (ωq_list, ωd_list, F_list), ensemblealg = EnsembleSplitThreads())
260225
```
261226

262-
We are using the [`mesolveProblem`](@ref) function to define the master equation problem. We added some code to manage the progress bar, which is updated through a `RemoteChannel`. The `prob_func` argument of the `EnsembleProblem` function is used to define the function that generates the problem for each iteration. The `iter` variable contains the product of the `ωq_list` and `ωd_list` lists, which are used to sweep over the parameters. The `sol = solve(ens_prob, Tsit5(), EnsembleDistributed(), trajectories=length(iter))` command is used to solve the problem with the distributed ensemble method. The output of the script will be printed in the `output.out` file, which contains an output similar to the previous example.
263-
264-
227+
Notice that we are using the [`mesolve_map`](@ref) function, which internally uses the `EnsembleProblem` function to parallelize the computation. The result is an array of `TimeEvolutionSol` objects, where each element corresponds to a specific combination of parameters. One can access the solution for a specific combination of parameters using indexing. For example, `sol[1, 1, 1].expect` will give the expectation values for the first combination of `ωq`, `ωd`, and `F`.

0 commit comments

Comments
 (0)