Skip to content

Commit

Permalink
ensure QuantumOptics expression bases are finite and consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Aug 13, 2024
1 parent 57d6372 commit aeae289
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions ext/QuantumOpticsExt/QuantumOpticsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,25 @@ express_nolookup(s::XBasisState, ::QuantumOpticsRepr) = (_s₊,_s₋)[s.idx]
express_nolookup(s::YBasisState, ::QuantumOpticsRepr) = (_i₊,_i₋)[s.idx]
express_nolookup(s::ZBasisState, ::QuantumOpticsRepr) = (_l0,_l1)[s.idx]

express_nolookup(s::FockState, r::QuantumOpticsRepr) = fockstate(FockBasis(r.cutoff),s.idx)
express_nolookup(s::CoherentState, r::QuantumOpticsRepr) = coherentstate(FockBasis(r.cutoff),s.alpha)
express_nolookup(o::NumberOp, r::QuantumOpticsRepr) = number(FockBasis(r.cutoff))
express_nolookup(o::CreateOp, r::QuantumOpticsRepr) = create(FockBasis(r.cutoff))
express_nolookup(o::DestroyOp, r::QuantumOpticsRepr) = destroy(FockBasis(r.cutoff))
express_nolookup(o::DisplaceOp, r::QuantumOpticsRepr) = displace(FockBasis(r.cutoff), o.alpha)
express_nolookup(x::MixedState, ::QuantumOpticsRepr) = identityoperator(basis(x))/length(basis(x)) # TODO there is probably a more efficient way to represent it
express_nolookup(x::IdentityOp, r::QuantumOpticsRepr) = identityoperator(FockBasis(r.cutoff))
function finite_basis(s,r)
if isfinite(length(basis(s)))
return basis(s)
else
if isa(basis(s), FockBasis)
return FockBasis(r.cutoff)
else
error()
end
end
end
express_nolookup(s::FockState, r::QuantumOpticsRepr) = fockstate(finite_basis(s,r),s.idx)
express_nolookup(s::CoherentState, r::QuantumOpticsRepr) = coherentstate(finite_basis(s,r),s.alpha)
express_nolookup(o::NumberOp, r::QuantumOpticsRepr) = number(finite_basis(s,r))
express_nolookup(o::CreateOp, r::QuantumOpticsRepr) = create(finite_basis(s,r))
express_nolookup(o::DestroyOp, r::QuantumOpticsRepr) = destroy(finite_basis(s,r))
express_nolookup(o::DisplaceOp, r::QuantumOpticsRepr) = displace(finite_basis(s,r), o.alpha)
express_nolookup(x::MixedState, ::QuantumOpticsRepr) = identityoperator(finite_basis(s,r))/length(finite_basis(s,r)) # TODO there is probably a more efficient way to represent it
express_nolookup(x::IdentityOp, r::QuantumOpticsRepr) = identityoperator(finite_basis(s,r))

express_nolookup(p::PauliNoiseCPTP, ::QuantumOpticsRepr) = LazySuperSum(SpinBasis(1//2), [1-p.px-p.py-p.pz,p.px,p.py,p.pz],
[LazyPrePost(_id,_id),LazyPrePost(_x,_x),LazyPrePost(_y,_y),LazyPrePost(_z,_z)])
Expand Down

0 comments on commit aeae289

Please sign in to comment.