Skip to content

Commit

Permalink
Merge pull request #130 from karolpezet/squeezefix
Browse files Browse the repository at this point in the history
proper squeeze update
  • Loading branch information
ChristophHotter authored Aug 23, 2023
2 parents 5539823 + 9bb478f commit fe00cb9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/spin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@ Spin down state for the given Spin basis.
"""
spindown(::Type{T}, b::SpinBasis) where T = basisstate(T, b, b.shape[1])
spindown(b::SpinBasis) = spindown(ComplexF64, b)


"""
squeeze([T=ComplexF64,] b::SpinBasis, z)
Squeezing operator ``S(z)=\\exp{\\left(\\frac{z^*\\hat{J_-}^2 - z\\hat{J}_+}{2 N}\\right)}`` for the
specified Spin-``N/2`` basis with optional data type `T`, computed as the matrix exponential. Too
large squeezing (``|z| > \\sqrt{N}``) will create an oversqueezed state.
"""
function squeeze(::Type{T}, b::SpinBasis, z::Number) where T
N = Int(length(b)-1)
z = T(z)/2N
Jm = sigmam(b)/2
Jp = sigmap(b)/2
exp(conj(z)*dense(Jm)^2 - z*dense(Jp)^2)
end
squeeze(b::SpinBasis, z::T) where {T <: Number} = squeeze(ComplexF64, b, z)
17 changes: 17 additions & 0 deletions test/test_spin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,21 @@ antikommutator(x, y) = x*y + y*x
@test 1e-11 > norm(sm*spinup(spinbasis) - spindown(spinbasis))
@test 1e-11 > norm(sp*spindown(spinbasis) - spinup(spinbasis))

# squeeze operator test SPIN
Nspins = 500
b_spin = SpinBasis(Nspins//2)
s1 = squeeze(b_spin,0.23*sqrt(Nspins)*exp(1im*0.23*pi))
s2 = s1*spindown(b_spin);

# Heisenberg uncertainty test
@test abs(variance(sigmax(b_spin)/2,s2)*variance(sigmay(b_spin)/2,s2)) abs2(expect(sigmaz(b_spin)/2,s2))/4

# small squeezing test
x1 = 0.023
s1 = squeeze(b_spin,x1*sqrt(Nspins));
s2 = s1*spindown(b_spin);

@test isapprox(2*log(real(variance(sigmax(b_spin)/2,s2))/Nspins*4) , -x1*sqrt(Nspins), atol=1e-2)
@test isapprox(2*log(real(variance(sigmay(b_spin)/2,s2))/Nspins*4) , x1*sqrt(Nspins), atol=1e-2)

end # testset

0 comments on commit fe00cb9

Please sign in to comment.