From 1c1b31d1f320eaebe6da7dfd2f575f6d76d69b5c Mon Sep 17 00:00:00 2001 From: Akira Kyle Date: Mon, 9 Dec 2024 16:03:00 -0700 Subject: [PATCH] Move to no parametric type on abstract quanutum objects --- Project.toml | 2 +- src/bloch_redfield_master.jl | 2 +- src/phasespace.jl | 9 +++++---- src/schroedinger.jl | 13 ++++++++----- src/stochastic_master.jl | 7 ++++--- src/stochastic_schroedinger.jl | 7 ++++--- test/test_spectralanalysis.jl | 3 ++- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Project.toml b/Project.toml index e16865db..b82e0f2e 100644 --- a/Project.toml +++ b/Project.toml @@ -33,7 +33,7 @@ IterativeSolvers = "0.9" KrylovKit = "0.6, 0.7, 0.8" LinearMaps = "3" OrdinaryDiffEq = "5, 6" -QuantumOpticsBase = "0.3, 0.4, 0.5" +QuantumOpticsBase = "0.6" RecursiveArrayTools = "2, 3" Reexport = "0.2, 1.0" StochasticDiffEq = "6.68.0" diff --git a/src/bloch_redfield_master.jl b/src/bloch_redfield_master.jl index bb93f1a5..9abd07a5 100644 --- a/src/bloch_redfield_master.jl +++ b/src/bloch_redfield_master.jl @@ -128,7 +128,7 @@ Time-evolution according to a Bloch-Redfield master equation. """ function master_bloch_redfield(tspan, rho0::Operator{B,B}, L::SuperOperator{Tuple{B,B},Tuple{B,B}}, - H::AbstractOperator{B,B}; fout::Union{Function,Nothing}=nothing, + H::BLROperator{B,B}; fout::Union{Function,Nothing}=nothing, kwargs...) where {B} #Prep basis transf diff --git a/src/phasespace.jl b/src/phasespace.jl index fc0e1a26..c39bfef9 100644 --- a/src/phasespace.jl +++ b/src/phasespace.jl @@ -4,7 +4,8 @@ import QuantumOpticsBase: wigner, coherentspinstate, qfuncsu2, - wignersu2 + wignersu2, + BLROperator """ qfunc(a, α) @@ -16,12 +17,12 @@ function can either be evaluated on one point α or on a grid specified by the vectors `xvec` and `yvec`. Note that conversion from `x` and `y` to `α` is done via the relation ``α = \\frac{1}{\\sqrt{2}}(x + i y)``. """ -function qfunc(rho::AbstractOperator{B,B}, alpha) where B<:FockBasis +function qfunc(rho::BLROperator{B,B}, alpha) where B<:FockBasis b = basis(rho) _qfunc_operator(rho, alpha, Ket(b), Ket(b)) end -function qfunc(rho::AbstractOperator{B,B}, xvec::AbstractVector, yvec::AbstractVector) where B<:FockBasis +function qfunc(rho::BLROperator{B,B}, xvec::AbstractVector, yvec::AbstractVector) where B<:FockBasis b = basis(rho) Nx = length(xvec) Ny = length(yvec) @@ -84,7 +85,7 @@ function qfunc(psi::Ket{B}, xvec::AbstractVector, yvec::AbstractVector) where B< return result end -function qfunc(state::Union{Ket{B}, AbstractOperator{B,B}}, x, y) where B<:FockBasis +function qfunc(state::Union{Ket{B}, BLROperator{B,B}}, x, y) where B<:FockBasis qfunc(state, complex(x, y)/sqrt(2)) end diff --git a/src/schroedinger.jl b/src/schroedinger.jl index eddecc6c..783fc4f7 100644 --- a/src/schroedinger.jl +++ b/src/schroedinger.jl @@ -1,3 +1,4 @@ +using QuantumOpticsBase: BLROperator """ timeevolution.schroedinger(tspan, psi0, H; fout) @@ -12,9 +13,9 @@ Integrate Schroedinger equation to evolve states or compute propagators. normalized nor permanent! It is still in use by the ode solver and therefore must not be changed. """ -function schroedinger(tspan, psi0::T, H::AbstractOperator{B,B}; +function schroedinger(tspan, psi0::T, H::BLROperator{B,B}; fout=nothing, - kwargs...) where {B,Bo,T<:Union{AbstractOperator{B,Bo},StateVector{B}}} + kwargs...) where {B,Bo,T<:Union{BLROperator{B,Bo},Bra{B},Ket{B}}} _check_const(H) dschroedinger_(t, psi, dpsi) = dschroedinger!(dpsi, H, psi) tspan, psi0 = _promote_time_and_state(psi0, H, tspan) # promote only if ForwardDiff.Dual @@ -57,7 +58,7 @@ function schroedinger_dynamic(tspan, psi0, f; end function schroedinger_dynamic(tspan, psi0::T, H::AbstractTimeDependentOperator; - kwargs...) where {B,Bp,T<:Union{AbstractOperator{B,Bp},StateVector{B}}} + kwargs...) where {B,Bp,T<:Union{BLROperator{B,Bp},Bra{B},Ket{B}}} promoted_tspan, psi0 = _promote_time_and_state(psi0, H, tspan) if promoted_tspan !== tspan # promote H promoted_H = TimeDependentSum(H.coefficients, H.static_op.operators; init_time=first(promoted_tspan)) @@ -74,8 +75,10 @@ Write the data stored in `y` into `x`, where either `x` or `y` is a quantum object such as a [`Ket`](@ref) or an [`Operator`](@ref), and the other one is a vector or a matrix with a matching size. """ -recast!(psi::StateVector{B,D},x::D) where {B, D} = (psi.data = x); -recast!(x::D,psi::StateVector{B,D}) where {B, D} = nothing +recast!(psi::Bra{B,D},x::D) where {B, D} = (psi.data = x); +recast!(x::D,psi::Bra{B,D}) where {B, D} = nothing +recast!(psi::Ket{B,D},x::D) where {B, D} = (psi.data = x); +recast!(x::D,psi::Ket{B,D}) where {B, D} = nothing function recast!(proj::Operator{B1,B2,T},x::T) where {B1,B2,T} proj.data = x end diff --git a/src/stochastic_master.jl b/src/stochastic_master.jl index 88baff30..0b113246 100644 --- a/src/stochastic_master.jl +++ b/src/stochastic_master.jl @@ -1,4 +1,5 @@ import ...timeevolution: dmaster_h!, dmaster_nh!, dmaster_h_dynamic!, check_master +using QuantumOpticsBase: BLROperator """ stochastic.master(tspan, rho0, H, J, C; ) @@ -29,7 +30,7 @@ non-hermitian Hamiltonian and then calls master_nh which is slightly faster. be changed. * `kwargs...`: Further arguments are passed on to the ode solver. """ -function master(tspan, rho0::T, H::AbstractOperator{B,B}, +function master(tspan, rho0::T, H::BLROperator{B,B}, J, C; rates=nothing, Jdagger=dagger.(J), Cdagger=dagger.(C), @@ -165,13 +166,13 @@ function check_master_stoch(rho0::Operator{B,B}, C, Cdagger) where B @assert length(C) == length(Cdagger) isreducible = true for c=C - @assert isa(c, AbstractOperator{B,B}) + @assert isa(c, BLROperator{B,B}) if !isa(c, DataOperator) isreducible = false end end for c=Cdagger - @assert isa(c, AbstractOperator{B,B}) + @assert isa(c, BLROperator{B,B}) if !isa(c, DataOperator) isreducible = false end diff --git a/src/stochastic_schroedinger.jl b/src/stochastic_schroedinger.jl index bd8066b2..d34882bd 100644 --- a/src/stochastic_schroedinger.jl +++ b/src/stochastic_schroedinger.jl @@ -1,4 +1,5 @@ import ...timeevolution: dschroedinger!, dschroedinger_dynamic!, check_schroedinger +using QuantumOpticsBase: BLROperator """ stochastic.schroedinger(tspan, state0, H, Hs[; fout, ...]) @@ -19,7 +20,7 @@ Integrate stochastic Schrödinger equation. each time step taken by the solver. * `kwargs...`: Further arguments are passed on to the ode solver. """ -function schroedinger(tspan, psi0::T, H::AbstractOperator{B,B}, Hs::Vector; +function schroedinger(tspan, psi0::T, H::BLROperator{B,B}, Hs::Vector; fout=nothing, normalize_state=false, calback=nothing, @@ -35,7 +36,7 @@ function schroedinger(tspan, psi0::T, H::AbstractOperator{B,B}, Hs::Vector; # TODO: replace checks by dispatch for h=Hs - @assert isa(h, AbstractOperator{B,B}) + @assert isa(h, BLROperator{B,B}) end dschroedinger_determ(t, psi, dpsi) = dschroedinger!(dpsi, H, psi) @@ -54,7 +55,7 @@ function schroedinger(tspan, psi0::T, H::AbstractOperator{B,B}, Hs::Vector; ncb=ncb, kwargs...) end -schroedinger(tspan, psi0::Ket{B}, H::AbstractOperator{B,B}, Hs::AbstractOperator{B,B}; kwargs...) where B = schroedinger(tspan, psi0, H, [Hs]; kwargs...) +schroedinger(tspan, psi0::Ket{B}, H::BLROperator{B,B}, Hs::BLROperator{B,B}; kwargs...) where B = schroedinger(tspan, psi0, H, [Hs]; kwargs...) """ stochastic.schroedinger_dynamic(tspan, state0, fdeterm, fstoch[; fout, ...]) diff --git a/test/test_spectralanalysis.jl b/test/test_spectralanalysis.jl index 34022f0c..6c75ca0c 100644 --- a/test/test_spectralanalysis.jl +++ b/test/test_spectralanalysis.jl @@ -1,8 +1,9 @@ using Test using QuantumOptics using LinearAlgebra, SparseArrays, Random +using QuantumOpticsBase: BLROperator -mutable struct SpectralanalysisTestOperator{BL<:Basis,BR<:Basis} <: AbstractOperator{BL,BR} end +mutable struct SpectralanalysisTestOperator{BL<:Basis,BR<:Basis} <: BLROperator{BL,BR} end @testset "spectralanalysis" begin