Skip to content

Commit df287f1

Browse files
committed
fix stochastic solvers
1 parent c984f95 commit df287f1

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

src/time_evolution/mesolve.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ c_ops are Nothing. You are probably running the wrong function."))
77

88
@doc raw"""
99
mesolveProblem(
10-
H::Union{AbstractQuantumObject{HOpType},Tuple},
11-
ψ0::QuantumObject{StateOpType},
10+
H::Union{AbstractQuantumObject,Tuple},
11+
ψ0::QuantumObject,
1212
tlist,
1313
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
1414
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
@@ -94,8 +94,8 @@ end
9494

9595
@doc raw"""
9696
mesolve(
97-
H::Union{AbstractQuantumObject{HOpType},Tuple},
98-
ψ0::QuantumObject{StateOpType},
97+
H::Union{AbstractQuantumObject,Tuple},
98+
ψ0::QuantumObject,
9999
tlist::AbstractVector,
100100
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
101101
alg::OrdinaryDiffEqAlgorithm = Tsit5(),

src/time_evolution/smesolve.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _smesolve_ScalarOperator(op_vec) =
1212
@doc raw"""
1313
smesolveProblem(
1414
H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
15-
ψ0::QuantumObject{KetQuantumObject},
15+
ψ0::QuantumObject,
1616
tlist::AbstractVector,
1717
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
1818
sc_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
@@ -26,7 +26,7 @@ _smesolve_ScalarOperator(op_vec) =
2626
Generate the SDEProblem for the Stochastic Master Equation time evolution of an open quantum system. This is defined by the following stochastic differential equation:
2727
2828
```math
29-
d| \rho (t) = -i [\hat{H}, \rho(t)] dt + \sum_n \mathcal{D}[\hat{C}_n] \rho(t) dt + \sum_n \mathcal{D}[\hat{S}_n] \rho(t) dt + \sum_n \mathcal{H}[\hat{S}_n] \rho(t) dW_n(t),
29+
d \rho (t) = -i [\hat{H}, \rho(t)] dt + \sum_i \mathcal{D}[\hat{C}_i] \rho(t) dt + \sum_n \mathcal{D}[\hat{S}_n] \rho(t) dt + \sum_n \mathcal{H}[\hat{S}_n] \rho(t) dW_n(t),
3030
```
3131
3232
where
@@ -41,15 +41,15 @@ is the Lindblad superoperator, and
4141
\mathcal{H}[\hat{O}] \rho = \hat{O} \rho + \rho \hat{O}^\dagger - \mathrm{Tr}[\hat{O} \rho + \rho \hat{O}^\dagger] \rho,
4242
```
4343
44-
Above, ``\hat{C}_n`` represent the operators related to pure dissipation, while ``\hat{S}_n`` are the measurement operators. The ``dW_n(t)`` term is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
44+
Above, ``\hat{C}_i`` represent the collapse operators related to pure dissipation, while ``\hat{S}_n`` are the stochastic collapse operators. The ``dW_n(t)`` term is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
4545
4646
# Arguments
4747
4848
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
4949
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``. It can be either a [`Ket`](@ref) or a [`Operator`](@ref).
5050
- `tlist`: List of times at which to save either the state or the expectation values of the system.
51-
- `c_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
52-
- `sc_ops`: List of measurement collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
51+
- `c_ops`: List of collapse operators ``\{\hat{C}_i\}_i``. It can be either a `Vector` or a `Tuple`.
52+
- `sc_ops`: List of stochastic collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
5353
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
5454
- `params`: `NamedTuple` of parameters to pass to the solver.
5555
- `rng`: Random number generator for reproducibility.
@@ -69,7 +69,7 @@ Above, ``\hat{C}_n`` represent the operators related to pure dissipation, while
6969
"""
7070
function smesolveProblem(
7171
H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
72-
ψ0::QuantumObject{KetQuantumObject},
72+
ψ0::QuantumObject{StateOpType},
7373
tlist::AbstractVector,
7474
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
7575
sc_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
@@ -78,12 +78,12 @@ function smesolveProblem(
7878
rng::AbstractRNG = default_rng(),
7979
progress_bar::Union{Val,Bool} = Val(true),
8080
kwargs...,
81-
)
81+
) where {StateOpType<:Union{KetQuantumObject,OperatorQuantumObject}}
8282
haskey(kwargs, :save_idxs) &&
8383
throw(ArgumentError("The keyword argument \"save_idxs\" is not supported in QuantumToolbox."))
8484

8585
isnothing(sc_ops) &&
86-
throw(ArgumentError("The list of measurement collapse operators must be provided. Use mesolveProblem instead."))
86+
throw(ArgumentError("The list of stochastic collapse operators must be provided. Use mesolveProblem instead."))
8787

8888
tlist = _check_tlist(tlist, _FType(ψ0))
8989

@@ -131,7 +131,7 @@ end
131131
@doc raw"""
132132
smesolveEnsembleProblem(
133133
H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
134-
ψ0::QuantumObject{KetQuantumObject},
134+
ψ0::QuantumObject,
135135
tlist::AbstractVector,
136136
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
137137
sc_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
@@ -149,7 +149,7 @@ end
149149
Generate the SDEProblem for the Stochastic Master Equation time evolution of an open quantum system. This is defined by the following stochastic differential equation:
150150
151151
```math
152-
d| \rho (t) = -i [\hat{H}, \rho(t)] dt + \sum_n \mathcal{D}[\hat{C}_n] \rho(t) dt + \sum_n \mathcal{D}[\hat{S}_n] \rho(t) dt + \sum_n \mathcal{H}[\hat{S}_n] \rho(t) dW_n(t),
152+
d \rho (t) = -i [\hat{H}, \rho(t)] dt + \sum_i \mathcal{D}[\hat{C}_i] \rho(t) dt + \sum_n \mathcal{D}[\hat{S}_n] \rho(t) dt + \sum_n \mathcal{H}[\hat{S}_n] \rho(t) dW_n(t),
153153
```
154154
155155
where
@@ -164,15 +164,15 @@ is the Lindblad superoperator, and
164164
\mathcal{H}[\hat{O}] \rho = \hat{O} \rho + \rho \hat{O}^\dagger - \mathrm{Tr}[\hat{O} \rho + \rho \hat{O}^\dagger] \rho,
165165
```
166166
167-
Above, ``\hat{C}_n`` represent the operators related to pure dissipation, while ``\hat{S}_n`` are the measurement operators. The ``dW_n(t)`` term is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
167+
Above, ``\hat{C}_i`` represent the collapse operators related to pure dissipation, while ``\hat{S}_n`` are the stochastic collapse operators. The ``dW_n(t)`` term is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
168168
169169
# Arguments
170170
171171
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
172172
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``. It can be either a [`Ket`](@ref) or a [`Operator`](@ref).
173173
- `tlist`: List of times at which to save either the state or the expectation values of the system.
174-
- `c_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
175-
- `sc_ops`: List of measurement collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
174+
- `c_ops`: List of collapse operators ``\{\hat{C}_i\}_i``. It can be either a `Vector` or a `Tuple`.
175+
- `sc_ops`: List of stochastic collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
176176
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
177177
- `params`: `NamedTuple` of parameters to pass to the solver.
178178
- `rng`: Random number generator for reproducibility.
@@ -196,7 +196,7 @@ Above, ``\hat{C}_n`` represent the operators related to pure dissipation, while
196196
"""
197197
function smesolveEnsembleProblem(
198198
H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
199-
ψ0::QuantumObject{KetQuantumObject},
199+
ψ0::QuantumObject{StateOpType},
200200
tlist::AbstractVector,
201201
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
202202
sc_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
@@ -209,7 +209,7 @@ function smesolveEnsembleProblem(
209209
output_func::Union{Tuple,Nothing} = nothing,
210210
progress_bar::Union{Val,Bool} = Val(true),
211211
kwargs...,
212-
)
212+
) where {StateOpType<:Union{KetQuantumObject,OperatorQuantumObject}}
213213
_prob_func =
214214
isnothing(prob_func) ? _ensemble_dispatch_prob_func(rng, ntraj, tlist, _stochastic_prob_func) : prob_func
215215
_output_func =
@@ -242,7 +242,7 @@ end
242242
@doc raw"""
243243
smesolve(
244244
H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
245-
ψ0::QuantumObject{KetQuantumObject},
245+
ψ0::QuantumObject,
246246
tlist::AbstractVector,
247247
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
248248
sc_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
@@ -261,7 +261,7 @@ end
261261
Stochastic Master Equation time evolution of an open quantum system. This is defined by the following stochastic differential equation:
262262
263263
```math
264-
d| \rho (t) = -i [\hat{H}, \rho(t)] dt + \sum_n \mathcal{D}[\hat{C}_n] \rho(t) dt + \sum_n \mathcal{D}[\hat{S}_n] \rho(t) dt + \sum_n \mathcal{H}[\hat{S}_n] \rho(t) dW_n(t),
264+
d \rho (t) = -i [\hat{H}, \rho(t)] dt + \sum_i \mathcal{D}[\hat{C}_i] \rho(t) dt + \sum_n \mathcal{D}[\hat{S}_n] \rho(t) dt + \sum_n \mathcal{H}[\hat{S}_n] \rho(t) dW_n(t),
265265
```
266266
267267
where
@@ -276,15 +276,15 @@ is the Lindblad superoperator, and
276276
\mathcal{H}[\hat{O}] \rho = \hat{O} \rho + \rho \hat{O}^\dagger - \mathrm{Tr}[\hat{O} \rho + \rho \hat{O}^\dagger] \rho,
277277
```
278278
279-
Above, ``\hat{C}_n`` represent the operators related to pure dissipation, while ``\hat{S}_n`` are the measurement operators. The ``dW_n(t)`` term is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
279+
Above, ``\hat{C}_i`` represent the collapse operators related to pure dissipation, while ``\hat{S}_n`` are the stochastic co operators. The ``dW_n(t)`` term is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
280280
281281
# Arguments
282282
283283
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
284284
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``. It can be either a [`Ket`](@ref) or a [`Operator`](@ref).
285285
- `tlist`: List of times at which to save either the state or the expectation values of the system.
286-
- `c_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
287-
- `sc_ops`: List of measurement collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
286+
- `c_ops`: List of collapse operators ``\{\hat{C}_i\}_i``. It can be either a `Vector` or a `Tuple`.
287+
- `sc_ops`: List of stochastic collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
288288
- `alg`: The algorithm to use for the stochastic differential equation. Default is `SRA1()`.
289289
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
290290
- `params`: `NamedTuple` of parameters to pass to the solver.
@@ -309,7 +309,7 @@ Above, ``\hat{C}_n`` represent the operators related to pure dissipation, while
309309
"""
310310
function smesolve(
311311
H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
312-
ψ0::QuantumObject{KetQuantumObject},
312+
ψ0::QuantumObject{StateOpType},
313313
tlist::AbstractVector,
314314
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
315315
sc_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
@@ -323,7 +323,7 @@ function smesolve(
323323
output_func::Union{Tuple,Nothing} = nothing,
324324
progress_bar::Union{Val,Bool} = Val(true),
325325
kwargs...,
326-
)
326+
) where {StateOpType<:Union{KetQuantumObject,OperatorQuantumObject}}
327327
ensemble_prob = smesolveEnsembleProblem(
328328
H,
329329
ψ0,

src/time_evolution/ssesolve.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,24 @@ d|\psi(t)\rangle = -i \hat{K} |\psi(t)\rangle dt + \sum_n \hat{M}_n |\psi(t)\ran
108108
where
109109
110110
```math
111-
\hat{K} = \hat{H} + i \sum_n \left(\frac{e_n}{2} \hat{C}_n - \frac{1}{2} \hat{C}_n^\dagger \hat{C}_n - \frac{e_n^2}{8}\right),
111+
\hat{K} = \hat{H} + i \sum_n \left(\frac{e_n}{2} \hat{S}_n - \frac{1}{2} \hat{S}_n^\dagger \hat{S}_n - \frac{e_n^2}{8}\right),
112112
```
113113
```math
114-
\hat{M}_n = \hat{C}_n - \frac{e_n}{2},
114+
\hat{M}_n = \hat{S}_n - \frac{e_n}{2},
115115
```
116116
and
117117
```math
118-
e_n = \langle \hat{C}_n + \hat{C}_n^\dagger \rangle.
118+
e_n = \langle \hat{S}_n + \hat{S}_n^\dagger \rangle.
119119
```
120120
121-
Above, ``\hat{C}_n`` is the `n`-th collapse operator and ``dW_n(t)`` is the real Wiener increment associated to ``\hat{C}_n``. See [Wiseman2009Quantum](@cite) for more details.
121+
Above, ``\hat{S}_n`` are the stochastic collapse operators and ``dW_n(t)`` is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
122122
123123
# Arguments
124124
125125
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
126126
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``.
127127
- `tlist`: List of times at which to save either the state or the expectation values of the system.
128-
- `sc_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
128+
- `sc_ops`: List of stochastic collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
129129
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
130130
- `params`: `NamedTuple` of parameters to pass to the solver.
131131
- `rng`: Random number generator for reproducibility.
@@ -158,7 +158,7 @@ function ssesolveProblem(
158158
throw(ArgumentError("The keyword argument \"save_idxs\" is not supported in QuantumToolbox."))
159159

160160
sc_ops isa Nothing &&
161-
throw(ArgumentError("The list of collapse operators must be provided. Use sesolveProblem instead."))
161+
throw(ArgumentError("The list of stochastic collapse operators must be provided. Use sesolveProblem instead."))
162162

163163
tlist = _check_tlist(tlist, _FType(ψ0))
164164

@@ -227,24 +227,24 @@ d|\psi(t)\rangle = -i \hat{K} |\psi(t)\rangle dt + \sum_n \hat{M}_n |\psi(t)\ran
227227
where
228228
229229
```math
230-
\hat{K} = \hat{H} + i \sum_n \left(\frac{e_n}{2} \hat{C}_n - \frac{1}{2} \hat{C}_n^\dagger \hat{C}_n - \frac{e_n^2}{8}\right),
230+
\hat{K} = \hat{H} + i \sum_n \left(\frac{e_n}{2} \hat{S}_n - \frac{1}{2} \hat{S}_n^\dagger \hat{S}_n - \frac{e_n^2}{8}\right),
231231
```
232232
```math
233-
\hat{M}_n = \hat{C}_n - \frac{e_n}{2},
233+
\hat{M}_n = \hat{S}_n - \frac{e_n}{2},
234234
```
235235
and
236236
```math
237-
e_n = \langle \hat{C}_n + \hat{C}_n^\dagger \rangle.
237+
e_n = \langle \hat{S}_n + \hat{S}_n^\dagger \rangle.
238238
```
239239
240-
Above, ``\hat{C}_n`` is the `n`-th collapse operator and ``dW_n(t)`` is the real Wiener increment associated to ``\hat{C}_n``. See [Wiseman2009Quantum](@cite) for more details.
240+
Above, ``\hat{S}_n`` are the stochastic collapse operators and ``dW_n(t)`` is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
241241
242242
# Arguments
243243
244244
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
245245
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``.
246246
- `tlist`: List of times at which to save either the state or the expectation values of the system.
247-
- `sc_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
247+
- `sc_ops`: List of stochastic collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
248248
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
249249
- `params`: `NamedTuple` of parameters to pass to the solver.
250250
- `rng`: Random number generator for reproducibility.
@@ -340,7 +340,7 @@ end
340340
)
341341
342342
343-
Stochastic Schrödinger equation evolution of a quantum system given the system Hamiltonian ``\hat{H}`` and a list of stochadtic collapse (jump) operators ``\{\hat{C}_n\}_n``.
343+
Stochastic Schrödinger equation evolution of a quantum system given the system Hamiltonian ``\hat{H}`` and a list of stochastic collapse (jump) operators ``\{\hat{S}_n\}_n``.
344344
The stochastic evolution of the state ``|\psi(t)\rangle`` is defined by:
345345
346346
```math
@@ -350,25 +350,25 @@ d|\psi(t)\rangle = -i \hat{K} |\psi(t)\rangle dt + \sum_n \hat{M}_n |\psi(t)\ran
350350
where
351351
352352
```math
353-
\hat{K} = \hat{H} + i \sum_n \left(\frac{e_n}{2} \hat{C}_n - \frac{1}{2} \hat{C}_n^\dagger \hat{C}_n - \frac{e_n^2}{8}\right),
353+
\hat{K} = \hat{H} + i \sum_n \left(\frac{e_n}{2} \hat{S}_n - \frac{1}{2} \hat{S}_n^\dagger \hat{S}_n - \frac{e_n^2}{8}\right),
354354
```
355355
```math
356-
\hat{M}_n = \hat{C}_n - \frac{e_n}{2},
356+
\hat{M}_n = \hat{S}_n - \frac{e_n}{2},
357357
```
358358
and
359359
```math
360-
e_n = \langle \hat{C}_n + \hat{C}_n^\dagger \rangle.
360+
e_n = \langle \hat{S}_n + \hat{S}_n^\dagger \rangle.
361361
```
362362
363-
Above, ``\hat{C}_n`` is the `n`-th collapse operator and ``dW_n(t)`` is the real Wiener increment associated to ``\hat{C}_n``. See [Wiseman2009Quantum](@cite) for more details.
363+
Above, ``\hat{S}_n`` are the stochastic collapse operators and ``dW_n(t)`` is the real Wiener increment associated to ``\hat{S}_n``. See [Wiseman2009Quantum](@cite) for more details.
364364
365365
366366
# Arguments
367367
368368
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
369369
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``.
370370
- `tlist`: List of times at which to save either the state or the expectation values of the system.
371-
- `sc_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
371+
- `sc_ops`: List of stochastic collapse operators ``\{\hat{S}_n\}_n``. It can be either a `Vector` or a `Tuple`.
372372
- `alg`: The algorithm to use for the stochastic differential equation. Default is `SRA1()`.
373373
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
374374
- `params`: `NamedTuple` of parameters to pass to the solver.

0 commit comments

Comments
 (0)