Skip to content

Commit

Permalink
implement squeezing (#83)
Browse files Browse the repository at this point in the history
* implement squeezing

* change `SqueezedCoherentState` to `SqueezedState`

* update changelog and project.toml
  • Loading branch information
apkille authored Sep 17, 2024
1 parent f2cda40 commit c41ff6b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# News

## v0.4.4 - 2024-09-16

- Implement squeezing with `SqueezeOp` and `SqueezedState`.

## v0.4.3 - 2024-08-13

- **(fix)** Fix for incorrect basis for `express(_,::QuantumOpticsRepr)` for certain operators.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumSymbolics"
uuid = "efa7fd63-0460-4890-beb7-be1bbdfbaeae"
authors = ["QuantumSymbolics.jl contributors"]
version = "0.4.3"
version = "0.4.4"

[deps]
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Expand Down
25 changes: 17 additions & 8 deletions docs/src/QHO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In this section, we describe symbolic representations of bosonic systems in Quan

## States

A Fock state is a state with well defined number of excitation quanta of a single quantum harmonic oscillator (an eigenstate of the number operator). In the following example, we create a `FockState` with 3 quanta in an infinite-dimension Fock space:
A Fock state is a state with well defined number of excitation quanta of a single quantum harmonic oscillator (an eigenstate of the number operator). In the following example, we create a [`FockState`](@ref) with 3 quanta in an infinite-dimension Fock space:

```jldoctest
julia> f = FockState(3)
Expand All @@ -22,7 +22,7 @@ Both vacuum (ground) and single-photon states are defined as constants in both u
- `vac = F₀ = F0` $=|0\rangle$ in the number state representation,
- `F₁ = F1` $=|1\rangle$ in the number state representation.

To create quantum analogues of a classical harmonic oscillator, or monochromatic electromagnetic waves, we can define a coherent (a.k.a. semi-classical) state $|\alpha\rangle$, where $\alpha$ is a complex amplitude, with `CoherentState(α::Number)`:
To create quantum analogues of a classical harmonic oscillator, or monochromatic electromagnetic waves, we can define a coherent (a.k.a. semi-classical) state $|\alpha\rangle$, where $\alpha$ is a complex amplitude, with [`CoherentState`](@ref):

```jldoctest
julia> c = CoherentState(im)
Expand All @@ -31,9 +31,15 @@ julia> c = CoherentState(im)
!!! note "Naming convention for quantum harmonic oscillator bases"
The defined basis for arbitrary symbolic bosonic states is a `FockBasis` object, due to a shared naming interface for Quantum physics packages. For instance, the command `basis(CoherentState(im))` will output `Fock(cutoff=Inf)`. This may lead to confusion, as not all bosonic states are Fock states. However, this is simply a naming convention for the basis, and symbolic and numerical results are not affected by it.

Summarized below are supported bosonic states.

- Fock state: `FockState(idx::Int)`,
- Coherent state: `CoherentState(alpha::Number)`,
- Squeezed vacuum state: `SqueezedState(z::Number)`.

## Operators

Operations on bosonic states are supported, and can be simplified with `qsimplify` and its rewriter `qsimplify_fock`. For instance, we can apply the raising (creation) $\hat{a}^{\dagger}$ and lowering (annihilation or destroy) $\hat{a}$ operators on a Fock state as follows:
Operations on bosonic states are supported, and can be simplified with [`qsimplify`](@ref) and its rewriter `qsimplify_fock`. For instance, we can apply the raising (creation) $\hat{a}^{\dagger}$ and lowering (annihilation or destroy) $\hat{a}$ operators on a Fock state as follows:

```jldoctest
julia> f = FockState(3);
Expand Down Expand Up @@ -68,8 +74,10 @@ Constants are defined for number and ladder operators in unicode and ASCII:
- `Create = âꜛ` $=\hat{a}^{\dagger}$,
- `Destroy = â` $=\hat{a}$.

Phase-shift $U(\theta)$ and displacement $D(\alpha)$ operators, defined respectively as
Phase-shift $U(\theta)$ and displacement $D(\alpha)$ operators, defined respectively as

$$U(\theta) = \exp\left(-i\theta\hat{n}\right) \quad \text{and} \quad D(\alpha) = \exp\left(\alpha\hat{a}^{\dagger} - \alpha\hat{a}\right),$$

can be defined with usual simplification rules. Consider the following example:

```jldoctest
Expand All @@ -85,19 +93,20 @@ U(π)
julia> qsimplify(phase*c, rewriter=qsimplify_fock)
|1.2246467991473532e-16 - 1.0im⟩
```
Here, we generated a coherent state $|i\rangle$ from the vacuum state $|0\rangle$ by applying the displacement operator defined by `DisplaceOp`. Then, we shifted its phase by $\pi$ with the phase shift operator (which is called with `PhaseShiftOp`) to get the result $|-i\rangle$.
Here, we generated a coherent state $|i\rangle$ from the vacuum state $|0\rangle$ by applying the displacement operator defined by [`DisplaceOp`](@ref). Then, we shifted its phase by $\pi$ with the phase shift operator (which is called with [`PhaseShiftOp`](@ref)) to get the result $|-i\rangle$.

Summarized below are supported bosonic operators.

- Number operator: `NumberOp()`,
- Creation operator: `CreateOp()`,
- Annihilation operator: `DestroyOp()`,
- Phase-shift operator: `PhaseShiftOp(phase::Number)`,
- Displacement operator: `DisplaceOp(alpha::Number)`.
- Displacement operator: `DisplaceOp(alpha::Number)`,
- Squeezing operator: `SqueezeOp(z::Number)`.

## Numerical Conversions to QuantumOptics.jl

Bosonic systems can be translated to the ket representation with `express`. For instance:
Bosonic systems can be translated to the ket representation with [`express`](@ref). For instance:

```jldoctest
julia> f = FockState(1);
Expand Down Expand Up @@ -132,7 +141,7 @@ Ket(dim=3)
```

!!! warning "Cutoff specifications for numerical representations of quantum harmonic oscillators"
Symbolic bosonic states and operators are naturally represented in an infinite dimension basis. For numerical conversions of such quantum objects, a finite cutoff of the highest allowed state must be defined. By default, the basis dimension of numerical conversions is set to 3 (so the number representation cutoff is 2), as demonstrated above. To define a different cutoff, one must customize the `QuantumOpticsRepr` instance, e.g. provide `QuantumOpticsRepr(cutoff=n::Int)` to `express`.
Symbolic bosonic states and operators are naturally represented in an infinite dimension basis. For numerical conversions of such quantum objects, a finite cutoff of the highest allowed state must be defined. By default, the basis dimension of numerical conversions is set to 3 (so the number representation cutoff is 2), as demonstrated above. To define a different cutoff, one must customize the `QuantumOpticsRepr` instance, e.g. provide `QuantumOpticsRepr(cutoff=n::Int)` to [`express`](@ref).

If we wish to specify a different numerical cutoff, say 4, to the previous examples, then we rewrite them as follows:

Expand Down
2 changes: 2 additions & 0 deletions ext/QuantumOpticsExt/QuantumOpticsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ function finite_basis(s,r)
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(s::SqueezedState, r::QuantumOpticsRepr) = (b = finite_basis(s,r); squeeze(b, s.z)*fockstate(b, 0))
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(o::SqueezeOp, r::QuantumOpticsRepr) = squeeze(finite_basis(o,r), o.z)
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))

Expand Down
4 changes: 2 additions & 2 deletions src/QSymbolicsBase/QSymbolicsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export SymQObj,QObj,
MixedState,IdentityOp,
SApplyKet,SApplyBra,SMulOperator,SSuperOpApply,SCommutator,SAnticommutator,SBraKet,SOuterKetBra,
HGate,XGate,YGate,ZGate,CPHASEGate,CNOTGate,
XBasisState,YBasisState,ZBasisState,FockState,CoherentState,
NumberOp,CreateOp,DestroyOp,PhaseShiftOp,DisplaceOp,
XBasisState,YBasisState,ZBasisState,FockState,CoherentState,SqueezedState,
NumberOp,CreateOp,DestroyOp,PhaseShiftOp,DisplaceOp,SqueezeOp,
XCXGate,XCYGate,XCZGate,YCXGate,YCYGate,YCZGate,ZCXGate,ZCYGate,ZCZGate,
qsimplify,qsimplify_pauli,qsimplify_commutator,qsimplify_anticommutator,qsimplify_fock,
qexpand,
Expand Down
27 changes: 26 additions & 1 deletion src/QSymbolicsBase/predefined_fock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ end
CoherentState(alpha::Number) = CoherentState(alpha, inf_fock_basis)
symbollabel(x::CoherentState) = "$(x.alpha)"

"""Squeezed vacuum state in defined Fock basis."""
@withmetadata struct SqueezedState <: SpecialKet
z::Number
basis::FockBasis
end
SqueezedState(z::Number) = SqueezedState(z, inf_fock_basis)
symbollabel(x::SqueezedState) = "0,$(x.z)"

const inf_fock_basis = FockBasis(Inf,0.)
"""Vacuum basis state of n"""
const vac = const F₀ = const F0 = FockState(0)
Expand Down Expand Up @@ -136,4 +144,21 @@ const N = const n̂ = NumberOp()
There is no unicode dagger superscript, so we use the uparrow"""
const Create = const âꜛ = CreateOp()
"""Annihilation operator, also available as the constant `â`, in an infinite dimension Fock basis."""
const Destroy = const= DestroyOp()
const Destroy = const= DestroyOp()

"""Squeezing operator in defined Fock basis.
```jldoctest
julia> S = SqueezeOp(pi)
S(π)
julia> qsimplify(S*vac, rewriter=qsimplify_fock)
|0,π⟩
```
"""
@withmetadata struct SqueezeOp <: AbstractSingleBosonOp
z::Number
basis::FockBasis
end
SqueezeOp(z::Number) = SqueezeOp(z, inf_fock_basis)
symbollabel(x::SqueezeOp) = "S($(x.z))"
3 changes: 2 additions & 1 deletion src/QSymbolicsBase/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ RULES_FOCK = [
@rule(~o1::_isa(PhaseShiftOp) * ~o2::_isa(DestroyOp) * dagger(~o1) => ~o2*exp(im*((~o1).phase))),
@rule(dagger(~o1::_isa(DisplaceOp)) * ~o2::_isa(DestroyOp) * ~o1 => (~o2) + (~o1).alpha*IdentityOp((~o2).basis)),
@rule(dagger(~o1::_isa(DisplaceOp)) * ~o2::_isa(CreateOp) * ~o1 => (~o2) + conj((~o1).alpha)*IdentityOp((~o2).basis)),
@rule(~o::_isa(DisplaceOp) * ~k::((x->(isa(x,FockState) && x.idx == 0))) => CoherentState((~o).alpha))
@rule(~o::_isa(DisplaceOp) * ~k::((x->(isa(x,FockState) && x.idx == 0))) => CoherentState((~o).alpha)),
@rule(~o::_isa(SqueezeOp) * ~k::_isequal(vac) => SqueezedState((~o).z, (~o).basis))
]

RULES_SIMPLIFY = [RULES_PAULI; RULES_COMMUTATOR; RULES_ANTICOMMUTATOR; RULES_FOCK]
Expand Down
4 changes: 4 additions & 0 deletions test/test_express_opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@
@test express(Create*F1) express(Create)*express(F1)
@test express(Destroy*F1) express(Destroy)*express(F1)
@test express(displace*cstate) express(displace)*express(cstate)

squeezed = SqueezedState(pi/4)
squeezeop = SqueezeOp(pi/4)
@test express(squeezed) express(squeezeop)*express(vac)
end
6 changes: 6 additions & 0 deletions test/test_fock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
phase1 = PhaseShiftOp(0)
phase2 = PhaseShiftOp(pi)
displace = DisplaceOp(im)
squeezeop = SqueezeOp(pi)
sstate = SqueezedState(pi)

@testset "ladder and number operators" begin
@test isequal(qsimplify(Destroy*vac, rewriter=qsimplify_fock), SZeroKet())
Expand All @@ -23,4 +25,8 @@
@test isequal(qsimplify(dagger(displace)*Create*displace, rewriter=qsimplify_fock), Create - im*IdentityOp(inf_fock_basis))
@test isequal(qsimplify(displace*vac, rewriter=qsimplify_fock), cstate)
end

@testset "Squeeze operators" begin
@test isequal(qsimplify(squeezeop*vac, rewriter=qsimplify_fock), sstate)
end
end

2 comments on commit c41ff6b

@apkille
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/115324

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.4 -m "<description of version>" c41ff6be491cb285015e2bddad98aa740f7e029c
git push origin v0.4.4

Please sign in to comment.