@@ -4,7 +4,7 @@ function _save_func_sesolve(integrator)
44 internal_params = integrator. p
55 progr = internal_params. progr
66
7- if ! internal_params. is_empty_e_ops
7+ if internal_params. is_empty_e_ops
88 e_ops = internal_params. e_ops
99 expvals = internal_params. expvals
1010
@@ -44,14 +44,13 @@ function _generate_sesolve_kwargs(e_ops, progress_bar::Val{false}, t_l, kwargs)
4444end
4545
4646@doc raw """
47- sesolveProblem(H::QuantumObject,
48- ψ0::QuantumObject,
49- tlist::AbstractVector;
50- alg::OrdinaryDiffEqAlgorithm=Tsit5()
51- e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
52- H_t::Union{Nothing,Function,TimeDependentOperatorSum}=nothing,
53- params::NamedTuple=NamedTuple(),
54- progress_bar::Union{Val,Bool}=Val(true),
47+ sesolveProblem(H,
48+ ψ0,
49+ tlist;
50+ alg=Tsit5()
51+ e_ops = nothing,
52+ params=NamedTuple(),
53+ progress_bar=Val(true),
5554 kwargs...)
5655
5756Generates the ODEProblem for the Schrödinger time evolution of a quantum system:
@@ -62,7 +61,7 @@ Generates the ODEProblem for the Schrödinger time evolution of a quantum system
6261
6362# Arguments
6463
65- - `H::QuantumObject`: The Hamiltonian of the system ``\h at{H}``.
64+ - `H::Union{ QuantumObject,Tuple} `: The Hamiltonian of the system ``\h at{H}``.
6665- `ψ0::QuantumObject`: The initial state of the system ``|\p si(0)\r angle``.
6766- `tlist::AbstractVector`: The time list of the evolution.
6867- `alg::OrdinaryDiffEqAlgorithm`: The algorithm used for the time evolution.
@@ -85,47 +84,43 @@ Generates the ODEProblem for the Schrödinger time evolution of a quantum system
8584- `prob`: The `ODEProblem` for the Schrödinger time evolution of the system.
8685"""
8786function sesolveProblem (
88- H:: Union{QuantumObject{MT1 ,OperatorQuantumObject},Tuple} ,
89- ψ0:: QuantumObject{<:AbstractVector{T2} ,KetQuantumObject} ,
87+ H:: Union{QuantumObject{DT1 ,OperatorQuantumObject},Tuple} ,
88+ ψ0:: QuantumObject{DT2 ,KetQuantumObject} ,
9089 tlist:: AbstractVector ;
91- alg:: OrdinaryDiffEqAlgorithm = Tsit5 (),
9290 e_ops:: Union{Nothing,AbstractVector,Tuple} = nothing ,
93- H_t:: Union{Nothing,Function,TimeDependentOperatorSum} = nothing ,
9491 params:: NamedTuple = NamedTuple (),
9592 progress_bar:: Union{Val,Bool} = Val (true ),
9693 kwargs... ,
97- ) where {MT1<: AbstractMatrix ,T2}
98- check_dims (H, ψ0)
99-
94+ ) where {DT1,DT2}
10095 haskey (kwargs, :save_idxs ) &&
10196 throw (ArgumentError (" The keyword argument \" save_idxs\" is not supported in QuantumToolbox." ))
10297
103- is_time_dependent = ! (H_t isa Nothing)
104-
10598 ϕ0 = sparse_to_dense (_CType (ψ0), get_data (ψ0)) # Convert it to dense vector with complex element type
10699
107100 t_l = convert (Vector{_FType (ψ0)}, tlist) # Convert it to support GPUs and avoid type instabilities for OrdinaryDiffEq.jl
108101
109- U = - 1im * get_data (H)
102+ H_evo = QobjEvo (H, - 1im ) # pre-multiply by -i
103+ isoper (H_evo) || throw (ArgumentError (" The Hamiltonian must be an Operator." ))
104+ check_dims (H_evo, ψ0)
105+ U = H_evo. data
106+
110107 progr = ProgressBar (length (t_l), enable = getVal (progress_bar))
111108
112109 if e_ops isa Nothing
113110 expvals = Array {ComplexF64} (undef, 0 , length (t_l))
114- e_ops2 = MT1[]
111+ e_ops_data = ()
115112 is_empty_e_ops = true
116113 else
117114 expvals = Array {ComplexF64} (undef, length (e_ops), length (t_l))
118- e_ops2 = get_data .(e_ops)
115+ e_ops_data = get_data .(e_ops)
119116 is_empty_e_ops = isempty (e_ops)
120117 end
121118
122119 p = (
123- U = U,
124- e_ops = e_ops2,
120+ e_ops = e_ops_data,
125121 expvals = expvals,
126122 progr = progr,
127- Hdims = H. dims,
128- H_t = H_t,
123+ Hdims = H_evo. dims,
129124 times = t_l,
130125 is_empty_e_ops = is_empty_e_ops,
131126 params... ,
@@ -136,10 +131,8 @@ function sesolveProblem(
136131 kwargs2 = merge (default_values, kwargs)
137132 kwargs3 = _generate_sesolve_kwargs (e_ops, makeVal (progress_bar), t_l, kwargs2)
138133
139- dudt! = is_time_dependent ? sesolve_td_dudt! : sesolve_ti_dudt!
140-
141134 tspan = (t_l[1 ], t_l[end ])
142- return ODEProblem {true,FullSpecialize} (dudt! , ϕ0, tspan, p; kwargs3... )
135+ return ODEProblem {true} (U , ϕ0, tspan, p; kwargs3... )
143136end
144137
145138@doc raw """
@@ -184,27 +177,16 @@ Time evolution of a closed quantum system using the Schrödinger equation:
184177- `sol::TimeEvolutionSol`: The solution of the time evolution. See also [`TimeEvolutionSol`](@ref)
185178"""
186179function sesolve (
187- H:: QuantumObject{MT1 ,OperatorQuantumObject} ,
188- ψ0:: QuantumObject{<:AbstractVector{T2} ,KetQuantumObject} ,
180+ H:: Union{ QuantumObject{DT1 ,OperatorQuantumObject},Tuple } ,
181+ ψ0:: QuantumObject{DT2 ,KetQuantumObject} ,
189182 tlist:: AbstractVector ;
190183 alg:: OrdinaryDiffEqAlgorithm = Tsit5 (),
191184 e_ops:: Union{Nothing,AbstractVector,Tuple} = nothing ,
192- H_t:: Union{Nothing,Function,TimeDependentOperatorSum} = nothing ,
193185 params:: NamedTuple = NamedTuple (),
194186 progress_bar:: Union{Val,Bool} = Val (true ),
195187 kwargs... ,
196- ) where {MT1<: AbstractMatrix ,T2}
197- prob = sesolveProblem (
198- H,
199- ψ0,
200- tlist;
201- alg = alg,
202- e_ops = e_ops,
203- H_t = H_t,
204- params = params,
205- progress_bar = progress_bar,
206- kwargs... ,
207- )
188+ ) where {DT1,DT2}
189+ prob = sesolveProblem (H, ψ0, tlist; e_ops = e_ops, params = params, progress_bar = progress_bar, kwargs... )
208190
209191 return sesolve (prob, alg)
210192end
0 commit comments