diff --git a/src/time_evolution/mesolve.jl b/src/time_evolution/mesolve.jl index 78ea39cd..560f7c98 100644 --- a/src/time_evolution/mesolve.jl +++ b/src/time_evolution/mesolve.jl @@ -103,7 +103,7 @@ function mesolveProblem( params..., ) - saveat = is_empty_e_ops ? t_l : [] + saveat = is_empty_e_ops ? t_l : [t_l[end]] default_values = (abstol = 1e-7, reltol = 1e-5, saveat = saveat) kwargs2 = merge(default_values, kwargs) if !isempty(e_ops) || progress_bar diff --git a/src/time_evolution/sesolve.jl b/src/time_evolution/sesolve.jl index 76d6d6c7..d9ade040 100644 --- a/src/time_evolution/sesolve.jl +++ b/src/time_evolution/sesolve.jl @@ -23,7 +23,7 @@ function sesolve_td_dudt!(du, u, p, t) return mul!(du, H_t, u, -1im, 1) end -""" +@doc raw""" sesolveProblem(H::QuantumObject, ψ0::QuantumObject, t_l::AbstractVector; @@ -38,15 +38,15 @@ Generates the ODEProblem for the Schrödinger time evolution of a quantum system # Arguments - - `H::QuantumObject`: The Hamiltonian of the system. - - `ψ0::QuantumObject`: The initial state of the system. - - `t_l::AbstractVector`: The time list of the evolution. - - `alg::OrdinaryDiffEq.OrdinaryDiffEqAlgorithm`: The algorithm used for the time evolution. - - `e_ops::AbstractVector`: The list of operators to be evaluated during the evolution. - - `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: The time-dependent Hamiltonian of the system. If `nothing`, the Hamiltonian is time-independent. - - `params::NamedTuple`: The parameters of the system. - - `progress_bar::Bool`: Whether to show the progress bar. - - `kwargs...`: The keyword arguments passed to the `ODEProblem` constructor. +- `H::QuantumObject`: The Hamiltonian of the system. +- `ψ0::QuantumObject`: The initial state of the system. +- `t_l::AbstractVector`: The time list of the evolution. +- `alg::OrdinaryDiffEq.OrdinaryDiffEqAlgorithm`: The algorithm used for the time evolution. +- `e_ops::AbstractVector`: The list of operators to be evaluated during the evolution. +- `H_t::Union{Nothing,Function,TimeDependentOperatorSum}`: The time-dependent Hamiltonian of the system. If `nothing`, the Hamiltonian is time-independent. +- `params::NamedTuple`: The parameters of the system. +- `progress_bar::Bool`: Whether to show the progress bar. +- `kwargs...`: The keyword arguments passed to the `ODEProblem` constructor. Note that the default tolerances in `kwargs` are given as `reltol=1e-5` and `abstol=1e-7`. @@ -54,7 +54,7 @@ For more details about `alg` and extra `kwargs`, please refer to [`DifferentialE # Returns - - `prob`: The `ODEProblem` for the Schrödinger time evolution of the system. +- `prob`: The `ODEProblem` for the Schrödinger time evolution of the system. """ function sesolveProblem( H::QuantumObject{MT1,OperatorQuantumObject}, @@ -90,7 +90,7 @@ function sesolveProblem( params..., ) - saveat = is_empty_e_ops ? t_l : [] + saveat = is_empty_e_ops ? t_l : [t_l[end]] default_values = (abstol = 1e-7, reltol = 1e-5, saveat = saveat) kwargs2 = merge(default_values, kwargs) if !isempty(e_ops) || progress_bar diff --git a/test/time_evolution_and_partial_trace.jl b/test/time_evolution_and_partial_trace.jl index 9b9d00b5..9c39d72f 100644 --- a/test/time_evolution_and_partial_trace.jl +++ b/test/time_evolution_and_partial_trace.jl @@ -11,9 +11,19 @@ t_l = LinRange(0, 1000, 1000) e_ops = [a_d * a] sol = sesolve(H, psi0, t_l, e_ops = e_ops, alg = Vern7(), progress_bar = false) + sol_string = sprint((t, s) -> show(t, "text/plain", s), sol) @test sum(abs.(sol.expect[1, :] .- sin.(η * t_l) .^ 2)) / length(t_l) < 0.1 @test ptrace(sol.states[end], 1) ≈ ptrace(ket2dm(sol.states[end]), 1) @test ptrace(sol.states[end]', 1) ≈ ptrace(sol.states[end], 1) + @test sol_string == + "Solution of time evolution\n" * + "(return code: $(sol.retcode))\n" * + "--------------------------\n" * + "num_states = $(length(sol.states))\n" * + "num_expect = $(size(sol.expect, 1))\n" * + "ODE alg.: $(sol.alg)\n" * + "abstol = $(sol.abstol)\n" * + "reltol = $(sol.reltol)\n" a = destroy(N) a_d = a' @@ -24,7 +34,17 @@ t_l = LinRange(0, 100, 1000) sol_me = mesolve(H, psi0, t_l, c_ops, e_ops = e_ops, alg = Vern7(), progress_bar = false) sol_mc = mcsolve(H, psi0, t_l, c_ops, n_traj = 500, e_ops = e_ops, progress_bar = false) + sol_me_string = sprint((t, s) -> show(t, "text/plain", s), sol_me) @test sum(abs.(sol_mc.expect .- sol_me.expect)) / length(t_l) < 0.1 + @test sol_me_string == + "Solution of time evolution\n" * + "(return code: $(sol_me.retcode))\n" * + "--------------------------\n" * + "num_states = $(length(sol_me.states))\n" * + "num_expect = $(size(sol_me.expect, 1))\n" * + "ODE alg.: $(sol_me.alg)\n" * + "abstol = $(sol_me.abstol)\n" * + "reltol = $(sol_me.reltol)\n" sp1 = kron(sigmap(), qeye(2)) sm1 = sp1'