Skip to content

Commit

Permalink
Tests added for displaceop.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjamadagni committed Apr 19, 2015
1 parent de8d52b commit be7e3ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/arrays/ladderops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ squeeze_construct(a::AbstractQuMatrix,b::AbstractQuMatrix, z::Number) = scale!(0
squeezingop(a::AbstractQuMatrix, b::AbstractQuMatrix, z::Number) = expm(squeeze_construct(a,b,z))
squeezingop(n::Int,z::Number) = squeezingop(lowerop(n),lowerop(n),z)

displaceop(n::Int,alpha::Number) = expm(scale!(alpha,lowerop(n)')-scale!(alpha',lowerop(n)))
displaceop(n::Int,alpha::Number) = expm(scale(alpha,lowerop(n)')-scale(alpha',lowerop(n)))

export raiseop,
lowerop,
Expand Down
18 changes: 12 additions & 6 deletions test/operatortest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@

@assert coeffs(commutator(sigma_x, sigma_x)) == spzeros(2,2)

######################################
# Position & Momentum Operators Test #
######################################
####################################################
# Position, Displacement & Momentum Operators Test #
####################################################

p = positionop(2)
m = momentumop(2)
@assert coeffs(commutator(sigma_x, p)) == spzeros(2,2)
@assert coeffs(commutator(sigma_y, m)) == spzeros(2,2)

#####################################
# Squeeze, Squeezing Operators Test #
#####################################
sv1 = [0.5403023058681398,0.8414709848078965]
sv2 = [0.5403023058681398 + 0.0im,0.0 + 0.8414709848078965im]
@assert displaceop(2,1)*statevec(1,FiniteBasis(2)) == QuArray(sv1)
@assert displaceop(2,1*im)*statevec(1,FiniteBasis(2)) == QuArray(sv2)

############################
# Squeezing Operators Test #
############################

@assert squeezingop(2,1.0)== QuArray(eye(2))
@assert squeezingop(lowerop(2), lowerop(2), 1.0) == squeezingop(2,1)


0 comments on commit be7e3ce

Please sign in to comment.