Skip to content

Commit d21041f

Browse files
Extend the support to Tuple in time_evolution (#248)
* Extend the support to `Tuple` in time_evolution * Add missing cases
1 parent f897225 commit d21041f

File tree

11 files changed

+87
-80
lines changed

11 files changed

+87
-80
lines changed

src/correlations.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ExponentialSeries(; tol = 1e-14, calc_steadystate = false) = ExponentialSeries(t
2020
A::QuantumObject,
2121
B::QuantumObject,
2222
C::QuantumObject,
23-
c_ops::Union{Nothing,AbstractVector}=nothing;
23+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
2424
kwargs...)
2525
2626
Returns the two-times correlation function of three operators ``\hat{A}``, ``\hat{B}`` and ``\hat{C}``: ``\expval{\hat{A}(t) \hat{B}(t + \tau) \hat{C}(t)}``
@@ -35,7 +35,7 @@ function correlation_3op_2t(
3535
A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
3636
B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject},
3737
C::QuantumObject{<:AbstractArray{T5},OperatorQuantumObject},
38-
c_ops::Union{Nothing,AbstractVector} = nothing;
38+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
3939
kwargs...,
4040
) where {
4141
T1,
@@ -65,7 +65,7 @@ end
6565
τ_l::AbstractVector,
6666
A::QuantumObject,
6767
B::QuantumObject,
68-
c_ops::Union{Nothing,AbstractVector}=nothing;
68+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
6969
reverse::Bool=false,
7070
kwargs...)
7171
@@ -81,7 +81,7 @@ function correlation_2op_2t(
8181
τ_l::AbstractVector,
8282
A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
8383
B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject},
84-
c_ops::Union{Nothing,AbstractVector} = nothing;
84+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
8585
reverse::Bool = false,
8686
kwargs...,
8787
) where {
@@ -108,7 +108,7 @@ end
108108
τ_l::AbstractVector,
109109
A::QuantumObject,
110110
B::QuantumObject,
111-
c_ops::Union{Nothing,AbstractVector}=nothing;
111+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
112112
reverse::Bool=false,
113113
kwargs...)
114114
@@ -122,7 +122,7 @@ function correlation_2op_1t(
122122
τ_l::AbstractVector,
123123
A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
124124
B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject},
125-
c_ops::Union{Nothing,AbstractVector} = nothing;
125+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
126126
reverse::Bool = false,
127127
kwargs...,
128128
) where {
@@ -143,7 +143,7 @@ end
143143
ω_list::AbstractVector,
144144
A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject},
145145
B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
146-
c_ops::Union{Nothing,AbstractVector}=nothing;
146+
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
147147
solver::MySolver=ExponentialSeries(),
148148
kwargs...)
149149
@@ -158,7 +158,7 @@ function spectrum(
158158
ω_list::AbstractVector,
159159
A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject},
160160
B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
161-
c_ops::Union{Nothing,AbstractVector} = nothing;
161+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
162162
solver::MySolver = ExponentialSeries(),
163163
kwargs...,
164164
) where {

src/qobj/eigsolve.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ end
323323

324324
@doc raw"""
325325
eigsolve_al(H::QuantumObject,
326-
T::Real, c_ops::Union{Nothing,AbstractVector}=nothing;
326+
T::Real, c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
327327
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
328328
H_t::Union{Nothing,Function}=nothing,
329329
params::NamedTuple=NamedTuple(),
@@ -363,7 +363,7 @@ Solve the eigenvalue problem for a Liouvillian superoperator `L` using the Arnol
363363
function eigsolve_al(
364364
H::QuantumObject{MT1,HOpType},
365365
T::Real,
366-
c_ops::Union{Nothing,AbstractVector} = nothing;
366+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
367367
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
368368
H_t::Union{Nothing,Function} = nothing,
369369
params::NamedTuple = NamedTuple(),

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/steadystate.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666
@doc raw"""
6767
steadystate(
6868
H::QuantumObject,
69-
c_ops::Union{Nothing,AbstractVector} = nothing;
69+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
7070
solver::SteadyStateSolver = SteadyStateDirectSolver(),
7171
kwargs...
7272
)
@@ -75,13 +75,13 @@ Solve the stationary state based on different solvers.
7575
7676
# Parameters
7777
- `H::QuantumObject`: The Hamiltonian or the Liouvillian of the system.
78-
- `c_ops::Union{Nothing,AbstractVector}=nothing`: The list of the collapse operators.
78+
- `c_ops::Union{Nothing,AbstractVector,Tuple}=nothing`: The list of the collapse operators.
7979
- `solver::SteadyStateSolver=SteadyStateDirectSolver()`: see documentation [Solving for Steady-State Solutions](@ref doc:Solving-for-Steady-State-Solutions) for different solvers.
8080
- `kwargs...`: The keyword arguments for the solver.
8181
"""
8282
function steadystate(
8383
H::QuantumObject{<:AbstractArray,OpType},
84-
c_ops::Union{Nothing,AbstractVector} = nothing;
84+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
8585
solver::SteadyStateSolver = SteadyStateDirectSolver(),
8686
kwargs...,
8787
) where {OpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}}
@@ -188,7 +188,7 @@ _steadystate(
188188
H::QuantumObject,
189189
ψ0::QuantumObject,
190190
tspan::Real = Inf,
191-
c_ops::Union{Nothing,AbstractVector} = nothing;
191+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
192192
solver::SteadyStateODESolver = SteadyStateODESolver(),
193193
reltol::Real = 1.0e-8,
194194
abstol::Real = 1.0e-10,
@@ -213,7 +213,7 @@ or
213213
- `H::QuantumObject`: The Hamiltonian or the Liouvillian of the system.
214214
- `ψ0::QuantumObject`: The initial state of the system.
215215
- `tspan::Real=Inf`: The final time step for the steady state problem.
216-
- `c_ops::Union{Nothing,AbstractVector}=nothing`: The list of the collapse operators.
216+
- `c_ops::Union{Nothing,AbstractVector,Tuple}=nothing`: The list of the collapse operators.
217217
- `solver::SteadyStateODESolver=SteadyStateODESolver()`: see [`SteadyStateODESolver`](@ref) for more details.
218218
- `reltol::Real=1.0e-8`: Relative tolerance in steady state terminate condition and solver adaptive timestepping.
219219
- `abstol::Real=1.0e-10`: Absolute tolerance in steady state terminate condition and solver adaptive timestepping.
@@ -223,7 +223,7 @@ function steadystate(
223223
H::QuantumObject{MT1,HOpType},
224224
ψ0::QuantumObject{<:AbstractArray{T2},StateOpType},
225225
tspan::Real = Inf,
226-
c_ops::Union{Nothing,AbstractVector} = nothing;
226+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
227227
solver::SteadyStateODESolver = SteadyStateODESolver(),
228228
reltol::Real = 1.0e-8,
229229
abstol::Real = 1.0e-10,
@@ -274,7 +274,7 @@ end
274274
H_p::QuantumObject{<:AbstractArray,OpType2},
275275
H_m::QuantumObject{<:AbstractArray,OpType3},
276276
ωd::Number,
277-
c_ops::Union{Nothing,AbstractVector} = nothing;
277+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
278278
n_max::Integer = 2,
279279
tol::R = 1e-8,
280280
solver::FSolver = SSFloquetLinearSystem,
@@ -341,7 +341,7 @@ In the case of `SSFloquetEffectiveLiouvillian`, instead, the effective Liouvilli
341341
- `H_p::QuantumObject`: The Hamiltonian or the Liouvillian of the part of the drive that oscillates as ``e^{i \omega t}``.
342342
- `H_m::QuantumObject`: The Hamiltonian or the Liouvillian of the part of the drive that oscillates as ``e^{-i \omega t}``.
343343
- `ωd::Number`: The frequency of the drive.
344-
- `c_ops::AbstractVector = QuantumObject`: The optional collapse operators.
344+
- `c_ops::Union{Nothing,AbstractVector} = nothing`: The optional collapse operators.
345345
- `n_max::Integer = 2`: The number of Fourier components to consider.
346346
- `tol::R = 1e-8`: The tolerance for the solver.
347347
- `solver::FSolver = SSFloquetLinearSystem`: The solver to use.
@@ -352,7 +352,7 @@ function steadystate_floquet(
352352
H_p::QuantumObject{<:AbstractArray,OpType2},
353353
H_m::QuantumObject{<:AbstractArray,OpType3},
354354
ωd::Number,
355-
c_ops::Union{Nothing,AbstractVector} = nothing;
355+
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
356356
n_max::Integer = 2,
357357
tol::R = 1e-8,
358358
solver::FSolver = SSFloquetLinearSystem(),

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,

0 commit comments

Comments
 (0)