Skip to content

Commit 8ce6b28

Browse files
Extend the support to Tuple in time_evolution
1 parent f34d9ff commit 8ce6b28

File tree

8 files changed

+68
-61
lines changed

8 files changed

+68
-61
lines changed

src/qobj/operator_sum.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ A constructor to represent a sum of operators ``\sum_i c_i \hat{O}_i`` with a li
77
88
This is very useful when we have to update only the coefficients, without allocating memory by performing the sum of the operators.
99
"""
10-
struct OperatorSum{CT<:Vector{<:Number},OT<:AbstractVector} <: AbstractQuantumObject
10+
struct OperatorSum{CT<:AbstractVector{<:Number},OT<:Union{AbstractVector,Tuple}} <: AbstractQuantumObject
1111
coefficients::CT
1212
operators::OT
13-
function OperatorSum(coefficients::CT, operators::OT) where {CT<:Vector{<:Number},OT<:AbstractVector}
13+
function OperatorSum(
14+
coefficients::CT,
15+
operators::OT,
16+
) where {CT<:AbstractVector{<:Number},OT<:Union{AbstractVector,Tuple}}
1417
length(coefficients) == length(operators) ||
1518
throw(DimensionMismatch("The number of coefficients must be the same as the number of operators."))
1619
# Check if all the operators have the same dimensions
@@ -22,7 +25,8 @@ struct OperatorSum{CT<:Vector{<:Number},OT<:AbstractVector} <: AbstractQuantumOb
2225
mapreduce(eltype, promote_type, coefficients),
2326
)
2427
coefficients2 = T.(coefficients)
25-
return new{Vector{T},OT}(coefficients2, operators)
28+
CT2 = typeof(coefficients2)
29+
return new{CT2,OT}(coefficients2, operators)
2630
end
2731
end
2832

src/time_evolution/mcsolve.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ end
100100
mcsolveProblem(H::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject},
101101
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
102102
tlist::AbstractVector,
103-
c_ops::Union{Nothing,AbstractVector}=nothing;
103+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
104104
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
105-
e_ops::Union{Nothing,AbstractVector}=nothing,
105+
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
106106
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
107107
params::NamedTuple=NamedTuple(),
108108
jump_callback::TJC=ContinuousLindbladJumpCallback(),
@@ -147,9 +147,9 @@ If the environmental measurements register a quantum jump, the wave function und
147147
- `H::QuantumObject`: Hamiltonian of the system ``\hat{H}``.
148148
- `ψ0::QuantumObject`: Initial state of the system ``|\psi(0)\rangle``.
149149
- `tlist::AbstractVector`: List of times at which to save the state of the system.
150-
- `c_ops::Union{Nothing,AbstractVector}`: List of collapse operators ``\{\hat{C}_n\}_n``.
150+
- `c_ops::Union{Nothing,AbstractVector,Tuple}`: List of collapse operators ``\{\hat{C}_n\}_n``.
151151
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
152-
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
152+
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
153153
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
154154
- `params::NamedTuple`: Dictionary of parameters to pass to the solver.
155155
- `seeds::Union{Nothing, Vector{Int}}`: List of seeds for the random number generator. Length must be equal to the number of trajectories provided.
@@ -172,9 +172,9 @@ function mcsolveProblem(
172172
H::QuantumObject{MT1,OperatorQuantumObject},
173173
ψ0::QuantumObject{<:AbstractArray,KetQuantumObject},
174174
tlist::AbstractVector,
175-
c_ops::Union{Nothing,AbstractVector} = nothing;
175+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
176176
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
177-
e_ops::Union{Nothing,AbstractVector} = nothing,
177+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
178178
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
179179
params::NamedTuple = NamedTuple(),
180180
seeds::Union{Nothing,Vector{Int}} = nothing,
@@ -286,9 +286,9 @@ end
286286
mcsolveEnsembleProblem(H::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject},
287287
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
288288
tlist::AbstractVector,
289-
c_ops::Union{Nothing,AbstractVector}=nothing;
289+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
290290
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
291-
e_ops::Union{Nothing,AbstractVector}=nothing,
291+
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
292292
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
293293
params::NamedTuple=NamedTuple(),
294294
jump_callback::TJC=ContinuousLindbladJumpCallback(),
@@ -335,9 +335,9 @@ If the environmental measurements register a quantum jump, the wave function und
335335
- `H::QuantumObject`: Hamiltonian of the system ``\hat{H}``.
336336
- `ψ0::QuantumObject`: Initial state of the system ``|\psi(0)\rangle``.
337337
- `tlist::AbstractVector`: List of times at which to save the state of the system.
338-
- `c_ops::Union{Nothing,AbstractVector}`: List of collapse operators ``\{\hat{C}_n\}_n``.
338+
- `c_ops::Union{Nothing,AbstractVector,Tuple}`: List of collapse operators ``\{\hat{C}_n\}_n``.
339339
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
340-
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
340+
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
341341
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
342342
- `params::NamedTuple`: Dictionary of parameters to pass to the solver.
343343
- `seeds::Union{Nothing, Vector{Int}}`: List of seeds for the random number generator. Length must be equal to the number of trajectories provided.
@@ -362,9 +362,9 @@ function mcsolveEnsembleProblem(
362362
H::QuantumObject{MT1,OperatorQuantumObject},
363363
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
364364
tlist::AbstractVector,
365-
c_ops::Union{Nothing,AbstractVector} = nothing;
365+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
366366
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
367-
e_ops::Union{Nothing,AbstractVector} = nothing,
367+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
368368
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
369369
params::NamedTuple = NamedTuple(),
370370
jump_callback::TJC = ContinuousLindbladJumpCallback(),
@@ -396,9 +396,9 @@ end
396396
mcsolve(H::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject},
397397
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
398398
tlist::AbstractVector,
399-
c_ops::Union{Nothing,AbstractVector}=nothing;
399+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
400400
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
401-
e_ops::Union{Nothing,AbstractVector}=nothing,
401+
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
402402
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
403403
params::NamedTuple=NamedTuple(),
404404
ntraj::Int=1,
@@ -445,9 +445,9 @@ If the environmental measurements register a quantum jump, the wave function und
445445
- `H::QuantumObject`: Hamiltonian of the system ``\hat{H}``.
446446
- `ψ0::QuantumObject`: Initial state of the system ``|\psi(0)\rangle``.
447447
- `tlist::AbstractVector`: List of times at which to save the state of the system.
448-
- `c_ops::Union{Nothing,AbstractVector}`: List of collapse operators ``\{\hat{C}_n\}_n``.
448+
- `c_ops::Union{Nothing,AbstractVector,Tuple}`: List of collapse operators ``\{\hat{C}_n\}_n``.
449449
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
450-
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
450+
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
451451
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
452452
- `params::NamedTuple`: Dictionary of parameters to pass to the solver.
453453
- `seeds::Union{Nothing, Vector{Int}}`: List of seeds for the random number generator. Length must be equal to the number of trajectories provided.
@@ -475,9 +475,9 @@ function mcsolve(
475475
H::QuantumObject{MT1,OperatorQuantumObject},
476476
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
477477
tlist::AbstractVector,
478-
c_ops::Union{Nothing,AbstractVector} = nothing;
478+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
479479
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
480-
e_ops::Union{Nothing,AbstractVector} = nothing,
480+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
481481
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
482482
params::NamedTuple = NamedTuple(),
483483
seeds::Union{Nothing,Vector{Int}} = nothing,

src/time_evolution/mesolve.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ end
5252
mesolveProblem(H::QuantumObject,
5353
ψ0::QuantumObject,
5454
tlist::AbstractVector,
55-
c_ops::Union{Nothing,AbstractVector}=nothing;
55+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
5656
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
57-
e_ops::Union{Nothing,AbstractVector}=nothing,
57+
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
5858
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
5959
params::NamedTuple=NamedTuple(),
6060
progress_bar::Union{Val,Bool}=Val(true),
@@ -77,9 +77,9 @@ where
7777
- `H::QuantumObject`: The Hamiltonian ``\hat{H}`` or the Liouvillian of the system.
7878
- `ψ0::QuantumObject`: The initial state of the system.
7979
- `tlist::AbstractVector`: The time list of the evolution.
80-
- `c_ops::Union{Nothing,AbstractVector}=nothing`: The list of the collapse operators ``\{\hat{C}_n\}_n``.
80+
- `c_ops::Union{Nothing,AbstractVector,Tuple}=nothing`: The list of the collapse operators ``\{\hat{C}_n\}_n``.
8181
- `alg::OrdinaryDiffEqAlgorithm=Tsit5()`: The algorithm used for the time evolution.
82-
- `e_ops::Union{Nothing,AbstractVector}=nothing`: The list of the operators for which the expectation values are calculated.
82+
- `e_ops::Union{Nothing,AbstractVector,Tuple}=nothing`: The list of the operators for which the expectation values are calculated.
8383
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing`: The time-dependent Hamiltonian or Liouvillian.
8484
- `params::NamedTuple=NamedTuple()`: The parameters of the time evolution.
8585
- `progress_bar::Union{Val,Bool}=Val(true)`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
@@ -101,9 +101,9 @@ function mesolveProblem(
101101
H::QuantumObject{MT1,HOpType},
102102
ψ0::QuantumObject{<:AbstractArray{T2},StateOpType},
103103
tlist,
104-
c_ops::Union{Nothing,AbstractVector} = nothing;
104+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
105105
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
106-
e_ops::Union{Nothing,AbstractVector} = nothing,
106+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
107107
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
108108
params::NamedTuple = NamedTuple(),
109109
progress_bar::Union{Val,Bool} = Val(true),
@@ -170,9 +170,9 @@ end
170170
mesolve(H::QuantumObject,
171171
ψ0::QuantumObject,
172172
tlist::AbstractVector,
173-
c_ops::Union{Nothing,AbstractVector}=nothing;
173+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
174174
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
175-
e_ops::Union{Nothing,AbstractVector}=nothing,
175+
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
176176
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
177177
params::NamedTuple=NamedTuple(),
178178
progress_bar::Union{Val,Bool}=Val(true),
@@ -195,9 +195,9 @@ where
195195
- `H::QuantumObject`: The Hamiltonian ``\hat{H}`` or the Liouvillian of the system.
196196
- `ψ0::QuantumObject`: The initial state of the system.
197197
- `tlist::AbstractVector`: The time list of the evolution.
198-
- `c_ops::Union{Nothing,AbstractVector}=nothing`: The list of the collapse operators ``\{\hat{C}_n\}_n``.
198+
- `c_ops::Union{Nothing,AbstractVector,Tuple}=nothing`: The list of the collapse operators ``\{\hat{C}_n\}_n``.
199199
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
200-
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
200+
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
201201
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
202202
- `params::NamedTuple`: Named Tuple of parameters to pass to the solver.
203203
- `progress_bar::Union{Val,Bool}`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
@@ -219,9 +219,9 @@ function mesolve(
219219
H::QuantumObject{MT1,HOpType},
220220
ψ0::QuantumObject{<:AbstractArray{T2},StateOpType},
221221
tlist::AbstractVector,
222-
c_ops::Union{Nothing,AbstractVector} = nothing;
222+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
223223
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
224-
e_ops::Union{Nothing,AbstractVector} = nothing,
224+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
225225
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
226226
params::NamedTuple = NamedTuple(),
227227
progress_bar::Union{Val,Bool} = Val(true),

src/time_evolution/sesolve.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
ψ0::QuantumObject,
4949
tlist::AbstractVector;
5050
alg::OrdinaryDiffEqAlgorithm=Tsit5()
51-
e_ops::Union{Nothing,AbstractVector} = nothing,
51+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
5252
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
5353
params::NamedTuple=NamedTuple(),
5454
progress_bar::Union{Val,Bool}=Val(true),
@@ -66,7 +66,7 @@ Generates the ODEProblem for the Schrödinger time evolution of a quantum system
6666
- `ψ0::QuantumObject`: The initial state of the system ``|\psi(0)\rangle``.
6767
- `tlist::AbstractVector`: The time list of the evolution.
6868
- `alg::OrdinaryDiffEqAlgorithm`: The algorithm used for the time evolution.
69-
- `e_ops::Union{Nothing,AbstractVector}`: The list of operators to be evaluated during the evolution.
69+
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: The list of operators to be evaluated during the evolution.
7070
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: The time-dependent Hamiltonian of the system. If `nothing`, the Hamiltonian is time-independent.
7171
- `params::NamedTuple`: The parameters of the system.
7272
- `progress_bar::Union{Val,Bool}`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
@@ -89,7 +89,7 @@ function sesolveProblem(
8989
ψ0::QuantumObject{<:AbstractVector{T2},KetQuantumObject},
9090
tlist::AbstractVector;
9191
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
92-
e_ops::Union{Nothing,AbstractVector} = nothing,
92+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
9393
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
9494
params::NamedTuple = NamedTuple(),
9595
progress_bar::Union{Val,Bool} = Val(true),
@@ -148,7 +148,7 @@ end
148148
ψ0::QuantumObject,
149149
tlist::AbstractVector;
150150
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
151-
e_ops::Union{Nothing,AbstractVector} = nothing,
151+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
152152
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
153153
params::NamedTuple=NamedTuple(),
154154
progress_bar::Union{Val,Bool}=Val(true),
@@ -166,7 +166,7 @@ Time evolution of a closed quantum system using the Schrödinger equation:
166166
- `ψ0::QuantumObject`: The initial state of the system ``|\psi(0)\rangle``.
167167
- `tlist::AbstractVector`: List of times at which to save the state of the system.
168168
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
169-
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
169+
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
170170
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
171171
- `params::NamedTuple`: Dictionary of parameters to pass to the solver.
172172
- `progress_bar::Union{Val,Bool}`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
@@ -189,7 +189,7 @@ function sesolve(
189189
ψ0::QuantumObject{<:AbstractVector{T2},KetQuantumObject},
190190
tlist::AbstractVector;
191191
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
192-
e_ops::Union{Nothing,AbstractVector} = nothing,
192+
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
193193
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
194194
params::NamedTuple = NamedTuple(),
195195
progress_bar::Union{Val,Bool} = Val(true),

0 commit comments

Comments
 (0)