From 6275f8b7b094e1141fdfcc36b5b8462f938e8bf9 Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Tue, 13 Aug 2024 20:57:39 -0400 Subject: [PATCH] ensure QuantumOptics expression bases are finite and consistent (#81) --- CHANGELOG.md | 4 ++++ Project.toml | 2 +- ext/QuantumOpticsExt/QuantumOpticsExt.jl | 27 +++++++++++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0086a7b..3cccf8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # News +## v0.4.3 - 2024-08-13 + +- **(fix)** Fix for incorrect basis for `express(_,::QuantumOpticsRepr)` for certain operators. + ## v0.4.2 - 2024-08-11 - `@withmetadata` now supports inline docstrings for struct fields diff --git a/Project.toml b/Project.toml index b5021c0..76f73a4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QuantumSymbolics" uuid = "efa7fd63-0460-4890-beb7-be1bbdfbaeae" authors = ["QuantumSymbolics.jl contributors"] -version = "0.4.2" +version = "0.4.3" [deps] Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" diff --git a/ext/QuantumOpticsExt/QuantumOpticsExt.jl b/ext/QuantumOpticsExt/QuantumOpticsExt.jl index 311e171..81ca2fa 100644 --- a/ext/QuantumOpticsExt/QuantumOpticsExt.jl +++ b/ext/QuantumOpticsExt/QuantumOpticsExt.jl @@ -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(o,r)) +express_nolookup(o::CreateOp, r::QuantumOpticsRepr) = create(finite_basis(o,r)) +express_nolookup(o::DestroyOp, r::QuantumOpticsRepr) = destroy(finite_basis(o,r)) +express_nolookup(o::DisplaceOp, r::QuantumOpticsRepr) = displace(finite_basis(o,r), o.alpha) +express_nolookup(x::MixedState, r::QuantumOpticsRepr) = identityoperator(finite_basis(x,r))/length(finite_basis(x,r)) # TODO there is probably a more efficient way to represent it +express_nolookup(x::IdentityOp, r::QuantumOpticsRepr) = identityoperator(finite_basis(x,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)])