Skip to content

Commit

Permalink
Add function for computing symplectic spectrum of a Gaussian state (#22)
Browse files Browse the repository at this point in the history
* symplectic spectrum

* update project.toml and changelog.md

* use det in test_states.jl

* adjust tolerances for det test
  • Loading branch information
apkille authored Dec 25, 2024
1 parent 31864af commit c310e27
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# News

## v1.2.1 - dev
## v1.2.2 - 2024-12-25

- Add `sympspectrum` function to compute symplectic spectrum of `GaussianState` object.

## v1.2.1 - 2024-12-17

- Add `issymplectic` and `isgaussian` checks.
- **(fix)** Generate correct Williamson matrix in `randstate` generation for `QuadBlockBasis`.
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 = "Gabs"
uuid = "0eb812ee-a11f-4f5e-b8d4-bb8a44f06f50"
authors = ["Andrew Kille"]
version = "1.2.1"
version = "1.2.2"

[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Expand Down
2 changes: 1 addition & 1 deletion src/Gabs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export
# wigner functions
wigner, wignerchar,
# symplectic form and checks
symplecticform, issymplectic, isgaussian,
symplecticform, issymplectic, isgaussian, sympspectrum,
# metrics
purity

Expand Down
13 changes: 13 additions & 0 deletions src/states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,16 @@ function _changebasis(state::GaussianState{B1,M,V}, ::Type{B2}) where {B1<:QuadP
covar = T * state.covar * transpose(T)
return GaussianState(B2(nmodes), mean, covar)
end

"""
sympspectrum(state::GaussianState)
Compute the symplectic spectrum of a Gaussian state.
"""
function sympspectrum(state::GaussianState)
basis = state.basis
form = symplecticform(basis)
M = form * state.covar
spectrum = filter(x -> x > 0, imag.(eigvals(M)))
return spectrum
end
19 changes: 19 additions & 0 deletions test/test_states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Gabs: _changebasis
using Gabs
using StaticArrays
using LinearAlgebra: det

nmodes = rand(1:5)
qpairbasis = QuadPairBasis(nmodes)
Expand Down Expand Up @@ -114,4 +115,22 @@
@test ptrace(SVector{2}, SMatrix{2,2}, state_qpair, 1) isa GaussianState
@test ptrace(SVector{4}, SMatrix{4,4}, state_qpair, [1, 3]) isa GaussianState
end

@testset "symplectic spectrum" begin
nmodes = rand(1:20)
qpairbasis = QuadPairBasis(nmodes)
qblockbasis = QuadBlockBasis(nmodes)

s_qpair = randstate(qpairbasis)
s_qblock = randstate(qblockbasis)

spec_qpair = sympspectrum(s_qpair)
spec_qblock = sympspectrum(s_qblock)

@test all(i > 1 || isapprox(i, 1, atol=1e-5) for i in spec_qpair)
@test all(i > 1 || isapprox(i, 1, atol=1e-5) for i in spec_qblock)

@test isapprox(det(s_qpair.covar), prod(abs2, spec_qpair), atol=1e-3)
@test isapprox(det(s_qblock.covar), prod(abs2, spec_qblock), atol=1e-3)
end
end

2 comments on commit c310e27

@apkille
Copy link
Owner 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/121966

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 v1.2.2 -m "<description of version>" c310e27e28965d7721ea8d769f317cf555dcb0ed
git push origin v1.2.2

Please sign in to comment.