Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the support to Tuple in time_evolution #248

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/correlations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ExponentialSeries(; tol = 1e-14, calc_steadystate = false) = ExponentialSeries(t
A::QuantumObject,
B::QuantumObject,
C::QuantumObject,
c_ops::Union{Nothing,AbstractVector}=nothing;
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
kwargs...)

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)}``
Expand All @@ -35,7 +35,7 @@ function correlation_3op_2t(
A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject},
C::QuantumObject{<:AbstractArray{T5},OperatorQuantumObject},
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
kwargs...,
) where {
T1,
Expand Down Expand Up @@ -65,7 +65,7 @@ end
τ_l::AbstractVector,
A::QuantumObject,
B::QuantumObject,
c_ops::Union{Nothing,AbstractVector}=nothing;
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
reverse::Bool=false,
kwargs...)

Expand All @@ -81,7 +81,7 @@ function correlation_2op_2t(
τ_l::AbstractVector,
A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject},
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
reverse::Bool = false,
kwargs...,
) where {
Expand All @@ -108,7 +108,7 @@ end
τ_l::AbstractVector,
A::QuantumObject,
B::QuantumObject,
c_ops::Union{Nothing,AbstractVector}=nothing;
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
reverse::Bool=false,
kwargs...)

Expand All @@ -122,7 +122,7 @@ function correlation_2op_1t(
τ_l::AbstractVector,
A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject},
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
reverse::Bool = false,
kwargs...,
) where {
Expand All @@ -143,7 +143,7 @@ end
ω_list::AbstractVector,
A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject},
B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
c_ops::Union{Nothing,AbstractVector}=nothing;
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
solver::MySolver=ExponentialSeries(),
kwargs...)

Expand All @@ -158,7 +158,7 @@ function spectrum(
ω_list::AbstractVector,
A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject},
B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
solver::MySolver = ExponentialSeries(),
kwargs...,
) where {
Expand Down
4 changes: 2 additions & 2 deletions src/qobj/eigsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ end

@doc raw"""
eigsolve_al(H::QuantumObject,
T::Real, c_ops::Union{Nothing,AbstractVector}=nothing;
T::Real, c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
H_t::Union{Nothing,Function}=nothing,
params::NamedTuple=NamedTuple(),
Expand Down Expand Up @@ -363,7 +363,7 @@ Solve the eigenvalue problem for a Liouvillian superoperator `L` using the Arnol
function eigsolve_al(
H::QuantumObject{MT1,HOpType},
T::Real,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
H_t::Union{Nothing,Function} = nothing,
params::NamedTuple = NamedTuple(),
Expand Down
10 changes: 7 additions & 3 deletions src/qobj/operator_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ A constructor to represent a sum of operators ``\sum_i c_i \hat{O}_i`` with a li

This is very useful when we have to update only the coefficients, without allocating memory by performing the sum of the operators.
"""
struct OperatorSum{CT<:Vector{<:Number},OT<:AbstractVector} <: AbstractQuantumObject
struct OperatorSum{CT<:AbstractVector{<:Number},OT<:Union{AbstractVector,Tuple}} <: AbstractQuantumObject
coefficients::CT
operators::OT
function OperatorSum(coefficients::CT, operators::OT) where {CT<:Vector{<:Number},OT<:AbstractVector}
function OperatorSum(
coefficients::CT,
operators::OT,
) where {CT<:AbstractVector{<:Number},OT<:Union{AbstractVector,Tuple}}
length(coefficients) == length(operators) ||
throw(DimensionMismatch("The number of coefficients must be the same as the number of operators."))
# Check if all the operators have the same dimensions
Expand All @@ -22,7 +25,8 @@ struct OperatorSum{CT<:Vector{<:Number},OT<:AbstractVector} <: AbstractQuantumOb
mapreduce(eltype, promote_type, coefficients),
)
coefficients2 = T.(coefficients)
return new{Vector{T},OT}(coefficients2, operators)
CT2 = typeof(coefficients2)
return new{CT2,OT}(coefficients2, operators)
end
end

Expand Down
18 changes: 9 additions & 9 deletions src/steadystate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
@doc raw"""
steadystate(
H::QuantumObject,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
solver::SteadyStateSolver = SteadyStateDirectSolver(),
kwargs...
)
Expand All @@ -75,13 +75,13 @@ Solve the stationary state based on different solvers.

# Parameters
- `H::QuantumObject`: The Hamiltonian or the Liouvillian of the system.
- `c_ops::Union{Nothing,AbstractVector}=nothing`: The list of the collapse operators.
- `c_ops::Union{Nothing,AbstractVector,Tuple}=nothing`: The list of the collapse operators.
- `solver::SteadyStateSolver=SteadyStateDirectSolver()`: see documentation [Solving for Steady-State Solutions](@ref doc:Solving-for-Steady-State-Solutions) for different solvers.
- `kwargs...`: The keyword arguments for the solver.
"""
function steadystate(
H::QuantumObject{<:AbstractArray,OpType},
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
solver::SteadyStateSolver = SteadyStateDirectSolver(),
kwargs...,
) where {OpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}}
Expand Down Expand Up @@ -188,7 +188,7 @@ _steadystate(
H::QuantumObject,
ψ0::QuantumObject,
tspan::Real = Inf,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
solver::SteadyStateODESolver = SteadyStateODESolver(),
reltol::Real = 1.0e-8,
abstol::Real = 1.0e-10,
Expand All @@ -213,7 +213,7 @@ or
- `H::QuantumObject`: The Hamiltonian or the Liouvillian of the system.
- `ψ0::QuantumObject`: The initial state of the system.
- `tspan::Real=Inf`: The final time step for the steady state problem.
- `c_ops::Union{Nothing,AbstractVector}=nothing`: The list of the collapse operators.
- `c_ops::Union{Nothing,AbstractVector,Tuple}=nothing`: The list of the collapse operators.
- `solver::SteadyStateODESolver=SteadyStateODESolver()`: see [`SteadyStateODESolver`](@ref) for more details.
- `reltol::Real=1.0e-8`: Relative tolerance in steady state terminate condition and solver adaptive timestepping.
- `abstol::Real=1.0e-10`: Absolute tolerance in steady state terminate condition and solver adaptive timestepping.
Expand All @@ -223,7 +223,7 @@ function steadystate(
H::QuantumObject{MT1,HOpType},
ψ0::QuantumObject{<:AbstractArray{T2},StateOpType},
tspan::Real = Inf,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
solver::SteadyStateODESolver = SteadyStateODESolver(),
reltol::Real = 1.0e-8,
abstol::Real = 1.0e-10,
Expand Down Expand Up @@ -274,7 +274,7 @@ end
H_p::QuantumObject{<:AbstractArray,OpType2},
H_m::QuantumObject{<:AbstractArray,OpType3},
ωd::Number,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
n_max::Integer = 2,
tol::R = 1e-8,
solver::FSolver = SSFloquetLinearSystem,
Expand Down Expand Up @@ -341,7 +341,7 @@ In the case of `SSFloquetEffectiveLiouvillian`, instead, the effective Liouvilli
- `H_p::QuantumObject`: The Hamiltonian or the Liouvillian of the part of the drive that oscillates as ``e^{i \omega t}``.
- `H_m::QuantumObject`: The Hamiltonian or the Liouvillian of the part of the drive that oscillates as ``e^{-i \omega t}``.
- `ωd::Number`: The frequency of the drive.
- `c_ops::AbstractVector = QuantumObject`: The optional collapse operators.
- `c_ops::Union{Nothing,AbstractVector} = nothing`: The optional collapse operators.
- `n_max::Integer = 2`: The number of Fourier components to consider.
- `tol::R = 1e-8`: The tolerance for the solver.
- `solver::FSolver = SSFloquetLinearSystem`: The solver to use.
Expand All @@ -352,7 +352,7 @@ function steadystate_floquet(
H_p::QuantumObject{<:AbstractArray,OpType2},
H_m::QuantumObject{<:AbstractArray,OpType3},
ωd::Number,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
n_max::Integer = 2,
tol::R = 1e-8,
solver::FSolver = SSFloquetLinearSystem(),
Expand Down
36 changes: 18 additions & 18 deletions src/time_evolution/mcsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ end
mcsolveProblem(H::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject},
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
tlist::AbstractVector,
c_ops::Union{Nothing,AbstractVector}=nothing;
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
e_ops::Union{Nothing,AbstractVector}=nothing,
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
params::NamedTuple=NamedTuple(),
jump_callback::TJC=ContinuousLindbladJumpCallback(),
Expand Down Expand Up @@ -147,9 +147,9 @@ If the environmental measurements register a quantum jump, the wave function und
- `H::QuantumObject`: Hamiltonian of the system ``\hat{H}``.
- `ψ0::QuantumObject`: Initial state of the system ``|\psi(0)\rangle``.
- `tlist::AbstractVector`: List of times at which to save the state of the system.
- `c_ops::Union{Nothing,AbstractVector}`: List of collapse operators ``\{\hat{C}_n\}_n``.
- `c_ops::Union{Nothing,AbstractVector,Tuple}`: List of collapse operators ``\{\hat{C}_n\}_n``.
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
- `params::NamedTuple`: Dictionary of parameters to pass to the solver.
- `seeds::Union{Nothing, Vector{Int}}`: List of seeds for the random number generator. Length must be equal to the number of trajectories provided.
Expand All @@ -172,9 +172,9 @@ function mcsolveProblem(
H::QuantumObject{MT1,OperatorQuantumObject},
ψ0::QuantumObject{<:AbstractArray,KetQuantumObject},
tlist::AbstractVector,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
e_ops::Union{Nothing,AbstractVector} = nothing,
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
params::NamedTuple = NamedTuple(),
seeds::Union{Nothing,Vector{Int}} = nothing,
Expand Down Expand Up @@ -286,9 +286,9 @@ end
mcsolveEnsembleProblem(H::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject},
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
tlist::AbstractVector,
c_ops::Union{Nothing,AbstractVector}=nothing;
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
e_ops::Union{Nothing,AbstractVector}=nothing,
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
params::NamedTuple=NamedTuple(),
jump_callback::TJC=ContinuousLindbladJumpCallback(),
Expand Down Expand Up @@ -335,9 +335,9 @@ If the environmental measurements register a quantum jump, the wave function und
- `H::QuantumObject`: Hamiltonian of the system ``\hat{H}``.
- `ψ0::QuantumObject`: Initial state of the system ``|\psi(0)\rangle``.
- `tlist::AbstractVector`: List of times at which to save the state of the system.
- `c_ops::Union{Nothing,AbstractVector}`: List of collapse operators ``\{\hat{C}_n\}_n``.
- `c_ops::Union{Nothing,AbstractVector,Tuple}`: List of collapse operators ``\{\hat{C}_n\}_n``.
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
- `params::NamedTuple`: Dictionary of parameters to pass to the solver.
- `seeds::Union{Nothing, Vector{Int}}`: List of seeds for the random number generator. Length must be equal to the number of trajectories provided.
Expand All @@ -362,9 +362,9 @@ function mcsolveEnsembleProblem(
H::QuantumObject{MT1,OperatorQuantumObject},
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
tlist::AbstractVector,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
e_ops::Union{Nothing,AbstractVector} = nothing,
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
params::NamedTuple = NamedTuple(),
jump_callback::TJC = ContinuousLindbladJumpCallback(),
Expand Down Expand Up @@ -396,9 +396,9 @@ end
mcsolve(H::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject},
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
tlist::AbstractVector,
c_ops::Union{Nothing,AbstractVector}=nothing;
c_ops::Union{Nothing,AbstractVector,Tuple}=nothing;
alg::OrdinaryDiffEqAlgorithm=Tsit5(),
e_ops::Union{Nothing,AbstractVector}=nothing,
e_ops::Union{Nothing,AbstractVector,Tuple}=nothing,
H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
params::NamedTuple=NamedTuple(),
ntraj::Int=1,
Expand Down Expand Up @@ -445,9 +445,9 @@ If the environmental measurements register a quantum jump, the wave function und
- `H::QuantumObject`: Hamiltonian of the system ``\hat{H}``.
- `ψ0::QuantumObject`: Initial state of the system ``|\psi(0)\rangle``.
- `tlist::AbstractVector`: List of times at which to save the state of the system.
- `c_ops::Union{Nothing,AbstractVector}`: List of collapse operators ``\{\hat{C}_n\}_n``.
- `c_ops::Union{Nothing,AbstractVector,Tuple}`: List of collapse operators ``\{\hat{C}_n\}_n``.
- `alg::OrdinaryDiffEqAlgorithm`: Algorithm to use for the time evolution.
- `e_ops::Union{Nothing,AbstractVector}`: List of operators for which to calculate expectation values.
- `e_ops::Union{Nothing,AbstractVector,Tuple}`: List of operators for which to calculate expectation values.
- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: Time-dependent part of the Hamiltonian.
- `params::NamedTuple`: Dictionary of parameters to pass to the solver.
- `seeds::Union{Nothing, Vector{Int}}`: List of seeds for the random number generator. Length must be equal to the number of trajectories provided.
Expand Down Expand Up @@ -475,9 +475,9 @@ function mcsolve(
H::QuantumObject{MT1,OperatorQuantumObject},
ψ0::QuantumObject{<:AbstractArray{T2},KetQuantumObject},
tlist::AbstractVector,
c_ops::Union{Nothing,AbstractVector} = nothing;
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
e_ops::Union{Nothing,AbstractVector} = nothing,
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
H_t::Union{Nothing,Function,TimeDependentOperatorSum} = nothing,
params::NamedTuple = NamedTuple(),
seeds::Union{Nothing,Vector{Int}} = nothing,
Expand Down
Loading