Skip to content

Commit

Permalink
Add squeezing operator (#114)
Browse files Browse the repository at this point in the history
* Add squeezing operator

* add explicit formula in docstring for displace and squeeze

* bump version number

---------

Co-authored-by: Stefan Krastanov <[email protected]>
  • Loading branch information
akirakyle and Krastanov authored Jul 5, 2023
1 parent ab9995f commit 138e019
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "QuantumOpticsBase"
uuid = "4f57444f-1401-5e15-980d-4471b28d5678"
version = "0.4.7"
version = "0.4.8"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
4 changes: 4 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ create(::Type{C}, ::FockBasis) where C
displace
```

```@docs
squeeze
```

```@docs
fockstate
```
Expand Down
1 change: 1 addition & 0 deletions src/QuantumOpticsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export Basis, GenericBasis, CompositeBasis, basis,
FockBasis, number, destroy, create,
fockstate, coherentstate, coherentstate!,
displace, displace_analytical, displace_analytical!,
squeeze,
randstate, randoperator, thermalstate, coherentthermalstate, phase_average, passive_state,
#spin
SpinBasis, sigmax, sigmay, sigmaz, sigmap, sigmam, spinup, spindown,
Expand Down
16 changes: 15 additions & 1 deletion src/fock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ create(b::FockBasis) = create(ComplexF64, b)
"""
displace([T=ComplexF64,] b::FockBasis, alpha)
Displacement operator ``D(α)`` for the specified Fock space with optional data
Displacement operator ``D(α)=\\exp{\\left(α\\hat{a}^\\dagger-α^*\\hat{a}\\right)}`` for the specified Fock space with optional data
type `T`, computed as the matrix exponential of finite-dimensional (truncated)
creation and annihilation operators.
"""
Expand All @@ -60,6 +60,20 @@ end

displace(b::FockBasis, alpha::T) where {T <: Number} = displace(ComplexF64, b, alpha)

"""
squeeze([T=ComplexF64,] b::FockBasis, z)
Squeezing operator ``S(z)=\\exp{\\left(\\frac{z^*\\hat{a}^2-z\\hat{a}^{\\dagger2}}{2}\\right)}`` for the specified Fock space with optional data
type `T`, computed as the matrix exponential of finite-dimensional (truncated)
creation and annihilation operators.
"""
function squeeze(::Type{T}, b::FockBasis, z::Number) where T
z = T(z)/2
asq = destroy(T, b)^2
exp(dense(conj(z) * asq - z * dagger(asq)))
end

squeeze(b::FockBasis, z::T) where {T <: Number} = squeeze(ComplexF64, b, z)

# associated Laguerre polynomial, borrowed from IonSim.jl
function _alaguerre(x::Real, n::Int, k::Int)
Expand Down
8 changes: 7 additions & 1 deletion test/test_fock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ basis = FockBasis(2)
b = FockBasis(30)
alpha = complex(0.5, 0.3)
d = displace(b, alpha)
a = destroy(b)
@test 1e-12 > D(d*dagger(d), identityoperator(b))
@test 1e-12 > D(dagger(d)*d, identityoperator(b))
@test 1e-12 > D(dagger(d), displace(b, -alpha))
@test 1e-15 > norm(coherentstate(b, alpha) - displace(b, alpha)*fockstate(b, 0))

# Test squeezing operator
b = FockBasis(30)
z = complex(0.5, 0.3)
s = squeeze(b, z)
@test 1e-12 > D(s*dagger(s), identityoperator(b))
@test 1e-12 > D(dagger(s)*s, identityoperator(b))
@test 1e-12 > D(dagger(s), squeeze(b, -z))

α = complex(rand(0.0:0.1:2.0), rand(0.0:0.1:2.0))
for ofs in 0:3
Expand Down

2 comments on commit 138e019

@Krastanov
Copy link
Collaborator

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/86928

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.8 -m "<description of version>" 138e0196ad4994b69a6c6f383635047da6cd1514
git push origin v0.4.8

Please sign in to comment.