Skip to content

Commit

Permalink
rename gaussian sampler kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
foldfelis committed Jul 19, 2021
1 parent b0fecda commit 15abe9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ export
###########################

"""
gaussian_state_sampler(state::AbstractState, n::Integer; bias_phase=0.)
gaussian_state_sampler(state::AbstractState, n::Integer; θ_offset=0.)
Random points sampled from quadrature probability density function of Gaussian `state`.
* `state`: Quantum state.
* `n`: N points.
* `bias_phase`: The offset of the θ coordinate
* `θ_offset`: The offset of the θ coordinate
"""
function gaussian_state_sampler(state::AbstractState, n::Integer; bias_phase=0.)
function gaussian_state_sampler(state::AbstractState, n::Integer; θ_offset=0.)
points = Matrix{Float64}(undef, 2, n)

return gaussian_state_sampler!(points, state, bias_phase)
return gaussian_state_sampler!(points, state, θ_offset)
end

function gaussian_state_sampler!(
points::AbstractMatrix{T},
state::StateMatrix, bias_phase::T
state::StateMatrix, θ_offset::T
) where {T}
n = size(points, 2)

# θs
points[1, :] .= sort!(2π*rand(n) .+ bias_phase)
points[1, :] .= sort!(2π*rand(n) .+ θ_offset)

# μ and σ given θ
μ = π̂ₓ_μ(points[1, :], state)
Expand All @@ -47,9 +47,9 @@ end

function gaussian_state_sampler!(
points::AbstractMatrix{T},
state::StateVector, bias_phase::T
state::StateVector, θ_offset::T
) where {T}
return gaussian_state_sampler!(points, StateMatrix(state), bias_phase)
return gaussian_state_sampler!(points, StateMatrix(state), θ_offset)
end

##############################
Expand Down
4 changes: 2 additions & 2 deletions test/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ end
state = VacuumState()
@test size(rand(state, IsGaussian)) == (2, 1)
@test size(rand(state, 4096, IsGaussian)) == (2, 4096)
@test size(rand(state, 4100, IsGaussian, bias_phase=π/4)) == (2, 4100)
@test size(rand(state, 4100, IsGaussian, θ_offset=π/4)) == (2, 4100)
state = VacuumState(rep=StateMatrix)
@test size(rand(state, IsGaussian)) == (2, 1)
@test size(rand(state, 4096, IsGaussian)) == (2, 4096)
@test size(rand(state, 4100, IsGaussian, bias_phase=π/4)) == (2, 4100)
@test size(rand(state, 4100, IsGaussian, θ_offset=π/4)) == (2, 4100)

state = SinglePhotonState()
@test size(rand(state)) == (2, 1)
Expand Down

0 comments on commit 15abe9a

Please sign in to comment.