1- export sesolveProblem, sesolve
1+ export sesolveProblem, sesolve, sesolve_map
22
33_sesolve_make_U_QobjEvo (H) = - 1im * QuantumObjectEvolution (H, type = Operator ())
44
@@ -157,12 +157,16 @@ end
157157function sesolve (prob:: TimeEvolutionProblem , alg:: OrdinaryDiffEqAlgorithm = Tsit5 (); kwargs... )
158158 sol = solve (prob. prob, alg; kwargs... )
159159
160- ψt = map (ϕ -> QuantumObject (ϕ, type = Ket (), dims = prob. dimensions), sol. u)
160+ return _gen_sesolve_solution (sol, prob. times, prob. dimensions)
161+ end
162+
163+ function _gen_sesolve_solution (sol, times, dimensions)
164+ ψt = map (ϕ -> QuantumObject (ϕ, type = Ket (), dims = dimensions), sol. u)
161165
162166 kwargs = NamedTuple (sol. prob. kwargs) # Convert to NamedTuple for Zygote.jl compatibility
163167
164168 return TimeEvolutionSol (
165- prob . times,
169+ times,
166170 sol. t,
167171 ψt,
168172 _get_expvals (sol, SaveFuncSESolve),
@@ -172,3 +176,55 @@ function sesolve(prob::TimeEvolutionProblem, alg::OrdinaryDiffEqAlgorithm = Tsit
172176 kwargs. reltol,
173177 )
174178end
179+
180+ @doc raw """
181+ sesolve_map
182+
183+ (TBA)
184+ """
185+ function sesolve_map (
186+ H:: Union{AbstractQuantumObject{Operator},Tuple} ,
187+ ψ0:: Vector{<:QuantumObject{Ket}} ,
188+ tlist:: AbstractVector ;
189+ alg:: OrdinaryDiffEqAlgorithm = Tsit5 (),
190+ ensemblealg:: EnsembleAlgorithm = EnsembleThreads (),
191+ e_ops:: Union{Nothing,AbstractVector,Tuple} = nothing ,
192+ params = [NullParameters ()],
193+ progress_bar:: Union{Val,Bool} = Val (true ),
194+ kwargs... ,
195+ )
196+ # mapping initial states and parameters
197+ ψ0_iter = map (get_data, ψ0)
198+ iter = collect (Iterators. product (ψ0_iter, params... ))
199+ ntraj = length (iter)
200+
201+ # we disable the progress bar of the sesolveProblem because we use a global progress bar for all the trajectories
202+ prob = sesolveProblem (
203+ H,
204+ first (ψ0),
205+ tlist;
206+ e_ops = e_ops,
207+ params = first (iter)[2 : end ],
208+ progress_bar = Val (false ),
209+ kwargs... ,
210+ )
211+
212+ # generate and solve ensemble problem
213+ _output_func = _ensemble_dispatch_output_func (ensemblealg, progress_bar, ntraj) # setup global progress bar
214+ ens_prob = TimeEvolutionProblem (
215+ EnsembleProblem (
216+ prob. prob,
217+ prob_func = (prob, i, repeat) -> remake (prob, u0 = iter[i][1 ], p = iter[i][2 : end ]),
218+ safetycopy = false ,
219+ ),
220+ prob. times,
221+ prob. dimensions,
222+ (progr = _output_func[2 ], channel = _output_func[3 ]),
223+ )
224+ sol = _ensemble_dispatch_solve (ens_prob, alg, ensemblealg, ntraj)
225+
226+ # handle solution and make it become an Array of TimeEvolutionSol
227+ return reshape (map (i -> _gen_sesolve_solution (sol[:, i], prob. times, prob. dimensions), eachindex (sol)), size (iter))
228+ end
229+ sesolve_map (H:: Union{AbstractQuantumObject{Operator},Tuple} , ψ0:: QuantumObject{Ket} , tlist:: AbstractVector ; kwargs... ) =
230+ sesolve_map (H, [ψ0], tlist; kwargs... )
0 commit comments