@@ -2,6 +2,23 @@ export sesolveProblem, sesolve, sesolve_map
22
33_sesolve_make_U_QobjEvo (H) = - 1im * QuantumObjectEvolution (H, type = Operator ())
44
5+ function _gen_sesolve_solution (sol, times, dimensions)
6+ ψt = map (ϕ -> QuantumObject (ϕ, type = Ket (), dims = dimensions), sol. u)
7+
8+ kwargs = NamedTuple (sol. prob. kwargs) # Convert to NamedTuple for Zygote.jl compatibility
9+
10+ return TimeEvolutionSol (
11+ times,
12+ sol. t,
13+ ψt,
14+ _get_expvals (sol, SaveFuncSESolve),
15+ sol. retcode,
16+ sol. alg,
17+ kwargs. abstol,
18+ kwargs. reltol,
19+ )
20+ end
21+
522@doc raw """
623 sesolveProblem(
724 H::Union{AbstractQuantumObject{Operator},Tuple},
@@ -160,23 +177,6 @@ function sesolve(prob::TimeEvolutionProblem, alg::OrdinaryDiffEqAlgorithm = Tsit
160177 return _gen_sesolve_solution (sol, prob. times, prob. dimensions)
161178end
162179
163- function _gen_sesolve_solution (sol, times, dimensions)
164- ψt = map (ϕ -> QuantumObject (ϕ, type = Ket (), dims = dimensions), sol. u)
165-
166- kwargs = NamedTuple (sol. prob. kwargs) # Convert to NamedTuple for Zygote.jl compatibility
167-
168- return TimeEvolutionSol (
169- times,
170- sol. t,
171- ψt,
172- _get_expvals (sol, SaveFuncSESolve),
173- sol. retcode,
174- sol. alg,
175- kwargs. abstol,
176- kwargs. reltol,
177- )
178- end
179-
180180@doc raw """
181181 sesolve_map(
182182 H::Union{AbstractQuantumObject{Operator},Tuple},
@@ -254,13 +254,7 @@ function sesolve_map(
254254 ens_prob = TimeEvolutionProblem (
255255 EnsembleProblem (
256256 prob. prob,
257- prob_func = (prob, i, repeat) -> remake (
258- prob,
259- f = deepcopy (prob. f. f),
260- u0 = iter[i][1 ],
261- p = iter[i][2 : end ],
262- callback = haskey (prob. kwargs, :callback ) ? deepcopy (prob. kwargs[:callback ]) : nothing ,
263- ),
257+ prob_func = (prob, i, repeat) -> _se_me_map_prob_func (prob, i, repeat, iter),
264258 output_func = _output_func[1 ],
265259 safetycopy = false ,
266260 ),
@@ -271,7 +265,7 @@ function sesolve_map(
271265 sol = _ensemble_dispatch_solve (ens_prob, alg, ensemblealg, ntraj)
272266
273267 # handle solution and make it become an Array of TimeEvolutionSol
274- sol_vec = [_gen_sesolve_solution (sol[:, i], prob. times, prob. dimensions) for i in eachindex (sol)]
268+ sol_vec = [_gen_sesolve_solution (sol[:, i], prob. times, prob. dimensions) for i in eachindex (sol)] # map is type unstable
275269 return reshape (sol_vec, size (iter))
276270end
277271sesolve_map (H:: Union{AbstractQuantumObject{Operator},Tuple} , ψ0:: QuantumObject{Ket} , tlist:: AbstractVector ; kwargs... ) =
0 commit comments