Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)

- Add support of `QobjEvo` for `steadystate` (ODE solver only). ([#536])

## [v0.34.1]
Release date: 2025-08-23

Expand Down Expand Up @@ -301,3 +303,4 @@ Release date: 2024-11-13
[#517]: https://github.com/qutip/QuantumToolbox.jl/issues/517
[#520]: https://github.com/qutip/QuantumToolbox.jl/issues/520
[#531]: https://github.com/qutip/QuantumToolbox.jl/issues/531
[#536]: https://github.com/qutip/QuantumToolbox.jl/issues/536
17 changes: 13 additions & 4 deletions src/steadystate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ end

@doc raw"""
steadystate(
H::QuantumObject{OpType},
H::AbstractQuantumObject{OpType},
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
solver::SteadyStateSolver = SteadyStateDirectSolver(),
kwargs...,
Expand All @@ -111,7 +111,7 @@ Solve the stationary state based on different solvers.
- `kwargs`: The keyword arguments for the solver.
"""
function steadystate(
H::QuantumObject{OpType},
H::AbstractQuantumObject{OpType},
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
solver::SteadyStateSolver = SteadyStateDirectSolver(),
kwargs...,
Expand Down Expand Up @@ -199,7 +199,7 @@ function _steadystate(L::QuantumObject{SuperOperator}, solver::SteadyStateDirect
return QuantumObject(ρss, Operator(), L.dimensions)
end

function _steadystate(L::QuantumObject{SuperOperator}, solver::SteadyStateODESolver; kwargs...)
function _steadystate(L::AbstractQuantumObject{SuperOperator}, solver::SteadyStateODESolver; kwargs...)
tmax = solver.tmax

ψ0 = isnothing(solver.ψ0) ? rand_ket(L.dimensions) : solver.ψ0
Expand All @@ -212,17 +212,26 @@ function _steadystate(L::QuantumObject{SuperOperator}, solver::SteadyStateODESol
sol = mesolve(
L,
ψ0,
[ftype(0), ftype(tmax)],
[ftype(0), ftype(tmax)];
alg = solver.alg,
progress_bar = Val(false),
save_everystep = false,
saveat = ftype[],
callback = cb,
kwargs...,
)

ρss = sol.states[end]
return ρss
end

_steadystate(
L::QuantumObjectEvolution{SuperOperator},
solver::T;
kwargs...,
) where {T<:Union{SteadyStateDirectSolver,SteadyStateEigenSolver,SteadyStateLinearSolver}} =
throw(ArgumentError("$(get_typename_wrapper(solver)) does not support QobjEvo."))

struct SteadyStateODECondition{CT<:AbstractArray}
cache::CT
end
Expand Down
8 changes: 4 additions & 4 deletions test/core-test/steady_state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
a = destroy(N)
a_d = a'
H = a_d * a + 0.1 * (a + a_d)
Ht = QobjEvo(H, (p, t) -> 1) # for test throw
c_ops = [sqrt(0.1) * a]
e_ops = [a_d * a]
psi0 = fock(N, 3)
Expand All @@ -17,18 +18,17 @@
solver = SteadyStateDirectSolver()
ρ_ss = steadystate(H, c_ops, solver = solver)
@test tracedist(rho_me, ρ_ss) < 1e-4
@test_throws ArgumentError steadystate(Ht, c_ops, solver = solver)

solver = SteadyStateLinearSolver()
ρ_ss = steadystate(H, c_ops, solver = solver)
@test tracedist(rho_me, ρ_ss) < 1e-4

solver = SteadyStateLinearSolver()
ρ_ss = steadystate(H, c_ops, solver = solver)
@test tracedist(rho_me, ρ_ss) < 1e-4
Comment on lines -25 to -27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we remove this part because there is exact same thing in Lines 21 - 23

@test_throws ArgumentError steadystate(Ht, c_ops, solver = solver)

solver = SteadyStateEigenSolver()
ρ_ss = steadystate(H, c_ops, solver = solver)
@test tracedist(rho_me, ρ_ss) < 1e-4
@test_throws ArgumentError steadystate(Ht, c_ops, solver = solver)

@testset "Type Inference (steadystate)" begin
L = liouvillian(H, c_ops)
Expand Down
Loading