Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/src/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Importantly, methods that create or manipulate a Gaussian state, such as [`tenso

Create Gaussian states with symbolic variables using [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl):

```jldoctest
```julia
julia> using Symbolics

julia> @variables r θ τ
Expand All @@ -138,10 +138,10 @@ mean: 4-element Vector{Num}:
0
0
covariance: 4×4 Matrix{Num}:
cosh(2r) -cos(θ)*sinh(2r) 0 -sinh(2r)*sin(θ)
-cos(θ)*sinh(2r) cosh(2r) -sinh(2r)*sin(θ) 0
0 -sinh(2r)*sin(θ) cosh(2r) cos(θ)*sinh(2r)
-sinh(2r)*sin(θ) 0 cos(θ)*sinh(2r) cosh(2r)
cosh(2r) -sinh(2r)*cos(θ) 0 -sinh(2r)*sin(θ)
-sinh(2r)*cos(θ) cosh(2r) -sinh(2r)*sin(θ) 0
0 -sinh(2r)*sin(θ) cosh(2r) sinh(2r)*cos(θ)
-sinh(2r)*sin(θ) 0 sinh(2r)*cos(θ) cosh(2r)

julia> op = beamsplitter(b, τ)
GaussianUnitary for 2 modes.
Expand Down
6 changes: 4 additions & 2 deletions src/Gabs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export
williamson, Williamson, polar, Polar, blochmessiah, BlochMessiah,
# metrics
purity, entropy_vn, fidelity, logarithmic_negativity,
cross_wigner, cross_wignerchar

cross_wigner, cross_wignerchar,
# additional interface
nmodes

include("errors.jl")

include("utils.jl")
Expand Down
2 changes: 2 additions & 0 deletions src/linearcombinations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ function GaussianLinearCombination(pairs::Pair{<:Number,<:GaussianState}...)
return GaussianLinearCombination(basis, coeffs, states)
end

nmodes(x::GaussianLinearCombination) = nmodes(x[1])

"""
+(lc1::GaussianLinearCombination, lc2::GaussianLinearCombination)

Expand Down
1 change: 1 addition & 0 deletions test/test_linearcombinations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
vac_block = vacuumstate(qblockbasis)
lc_block = GaussianLinearCombination(vac_block)
@test lc_block.basis == qblockbasis
@test Gabs.nmodes(vac_block) == nmodes
end

@testset "Convenient GaussianState Arithmetic Interface" begin
Expand Down
10 changes: 5 additions & 5 deletions test/test_randoms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
@test isgaussian(rs_pair, atol = 1e-5)
@test isgaussian(rs_block, atol = 1e-5)
cp_rs_pair = copy(rs_pair)
cp_rs_block = copy(rs_pair)
cp_rs_block = copy(rs_block)
@test cp_rs_pair == rs_pair && cp_rs_block == rs_block
@test nmodes(rs_pair) == nmodes
@test nmodes(rs_block) == nmodes
@test Gabs.nmodes(rs_pair) == nmodes
@test Gabs.nmodes(rs_block) == nmodes

rspure_pair = randstate(qpairbasis, pure = true, ħ = ħ)
rspure_block = randstate(qblockbasis, pure = true, ħ = ħ)
Expand Down Expand Up @@ -92,7 +92,7 @@

cp_ru = copy(ru)
@test cp_ru == ru
@test nmodes(ru) == nmodes
@test Gabs.nmodes(ru) == nmodes

rupassive = randunitary(qpairbasis, passive = true)
@test rupassive.ħ == 2
Expand Down Expand Up @@ -125,7 +125,7 @@

cp_rc = copy(rc)
@test cp_rc == rc
@test nmodes(rc) == nmodes
@test Gabs.nmodes(rc) == nmodes

rc_array = randchannel(Array, qpairbasis)
@test rc_array.ħ == 2
Expand Down
14 changes: 7 additions & 7 deletions test/test_symbolic_channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
@test op_pair isa GaussianChannel && op_block isa GaussianChannel
@test op(SVector{2*nmodes}, SMatrix{2*nmodes,2*nmodes}, qpairbasis, params...) isa GaussianChannel
@test op(Array, qpairbasis, params...) isa GaussianChannel
@test isapprox(op_block, changebasis(QuadBlockBasis, op_pair))
@test_throws TypeError isapprox(op_block, changebasis(QuadBlockBasis, op_pair)) # due to equality checks for Num type in Symbolics.jl

op_pair_multi = op(qpairbasis, multi_params...)
op_block_multi = op(qblockbasis, multi_params...)
@test op_pair_multi isa GaussianChannel && op_block_multi isa GaussianChannel
@test op(SVector{2*nmodes}, SMatrix{2*nmodes,2*nmodes}, qpairbasis, multi_params...) isa GaussianChannel
@test op(Array, qpairbasis, multi_params...) isa GaussianChannel
@test isapprox(op_block_multi, changebasis(QuadBlockBasis, op_pair_multi))
@test_throws TypeError isapprox(op_block_multi, changebasis(QuadBlockBasis, op_pair_multi)) # due to equality checks for Num type in Symbolics.jl
end
end

Expand All @@ -47,19 +47,19 @@
d2_pair = displace(qpairbasis, b, noise)
ds_pair = tensor(d1_pair, d2_pair)
@test ds_pair isa GaussianChannel
@test isapprox(ds_pair, d1_pair ⊗ d2_pair)
@test_throws TypeError isapprox(ds_pair, d1_pair ⊗ d2_pair) # due to equality checks for Num type in Symbolics.jl
@test tensor(SVector{4*nmodes}, SMatrix{4*nmodes,4*nmodes}, d1_pair, d2_pair) isa GaussianChannel
p_pair = phaseshift(qpairbasis, a, noise)
@test isapprox(tensor(tensor(p_pair, d1_pair), d2_pair), p_pair ⊗ d1_pair ⊗ d2_pair)
@test_throws TypeError isapprox(tensor(tensor(p_pair, d1_pair), d2_pair), p_pair ⊗ d1_pair ⊗ d2_pair) # due to equality checks for Num type in Symbolics.jl

d1_block = displace(qblockbasis, a, noise)
d2_block = displace(qblockbasis, b, noise)
ds_block = tensor(d1_block, d2_block)
@test ds_block isa GaussianChannel
@test isapprox(ds_block, d1_block ⊗ d2_block)
@test_throws TypeError isapprox(ds_block, d1_block ⊗ d2_block) # due to equality checks for Num type in Symbolics.jl
@test tensor(SVector{4*nmodes}, SMatrix{4*nmodes,4*nmodes}, d1_block, d2_block) isa GaussianChannel
p_block = phaseshift(qblockbasis, a, noise)
@test isapprox(tensor(tensor(p_block, d1_block), d2_block), p_block ⊗ d1_block ⊗ d2_block)
@test_throws TypeError isapprox(tensor(tensor(p_block, d1_block), d2_block), p_block ⊗ d1_block ⊗ d2_block) # due to equality checks for Num type in Symbolics.jl
end

@testset "Symbolic actions" begin
Expand All @@ -73,6 +73,6 @@
d2 = displace(qpairbasis, b, noise)
c1 = coherentstate(qpairbasis, a)
c2 = coherentstate(qpairbasis, b)
@test isapprox((d1 ⊗ d2) * (v1 ⊗ v2), c1 ⊗ c2)
@test_throws TypeError isapprox((d1 ⊗ d2) * (v1 ⊗ v2), c1 ⊗ c2) # due to equality checks for Num type in Symbolics.jl
end
end
4 changes: 2 additions & 2 deletions test/test_symbolic_unitaries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
@test ds isa GaussianUnitary
@test isequal(ds.disp, (d1 ⊗ d2).disp)
@test isequal(ds.symplectic, (d1 ⊗ d2).symplectic)
@test isapprox(ds, d1 ⊗ d2, atol = 1e-10)
@test_throws TypeError isapprox(ds, d1 ⊗ d2, atol = 1e-10) # due to equality checks for Num type in Symbolics.jl
@test tensor(SVector{4*nmodes}, SMatrix{4*nmodes, 4*nmodes}, d1, d2) isa GaussianUnitary
@variables theta
p = phaseshift(qpairbasis, theta)
Expand Down Expand Up @@ -87,7 +87,7 @@
v1, v2 = vacuumstate(qpairbasis), vacuumstate(qpairbasis)
s1, s2 = squeezedstate(qpairbasis, r, theta), squeezedstate(qpairbasis, r1, theta1)
c1, c2 = coherentstate(qpairbasis, α1), coherentstate(qpairbasis, α2)
@test simplify(d1 * v1) ≈ simplify(c1)
@test_throws TypeError simplify(d1 * v1) ≈ simplify(c1) # due to equality checks for Num type in Symbolics.jl
@test isequal(simplify(d1 * v1).mean, simplify(c1).mean)
@test isequal(simplify(d1 * v1).covar, simplify(c1).covar)
@test isequal(apply!(s1, d1).mean, simplify(c1).mean)
Expand Down
Loading