Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to no parametric type on abstract quanutum objects #429

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/bloch_redfield_master.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/phasespace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import QuantumOpticsBase:
wigner,
coherentspinstate,
qfuncsu2,
wignersu2
wignersu2,
BLROperator

"""
qfunc(a, α)
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions src/schroedinger.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using QuantumOpticsBase: BLROperator
"""
timeevolution.schroedinger(tspan, psi0, H; fout)

Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/stochastic_master.jl
Original file line number Diff line number Diff line change
@@ -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; <keyword arguments>)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/stochastic_schroedinger.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ...timeevolution: dschroedinger!, dschroedinger_dynamic!, check_schroedinger
using QuantumOpticsBase: BLROperator

"""
stochastic.schroedinger(tspan, state0, H, Hs[; fout, ...])
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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, ...])
Expand Down
3 changes: 2 additions & 1 deletion test/test_spectralanalysis.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading