Skip to content

Commit 0f97116

Browse files
committed
fix normaliaztion condition check
1 parent fd3a6fa commit 0f97116

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ext/QuantumToolboxCairoMakieExt.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ end
147147
fock_numbers::Union{Nothing, AbstractVector} = nothing,
148148
unit_y_range::Bool = true,
149149
location::Union{GridPosition,Nothing} = nothing,
150+
atol::Real = 1e-6,
150151
kwargs...
151152
) where {SType<:Union{KetQuantumObject,OperatorQuantumObject}}
152153
@@ -156,6 +157,7 @@ Plot the [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution of
156157
- `library::Val{:CairoMakie}`: The plotting library to use.
157158
- `ρ::QuantumObject`: The quantum state for which the Fock state distribution is to be plotted. It can be either a [`Ket`](@ref), [`Bra`](@ref), or [`Operator`](@ref).
158159
- `location::Union{GridPosition,Nothing}`: The location of the plot in the layout. If `nothing`, the plot is created in a new figure. Default is `nothing`.
160+
- `atol::Real`: The tolerance for checking normalization condition. Default is `1e-6`.
159161
- `fock_numbers::Union{Nothing, AbstractVector}`: list of x ticklabels to represent fock numbers, default is `nothing`.
160162
- `unit_y_range::Bool`: Set y-axis limits [0, 1] or not, default is `true`.
161163
- `kwargs...`: Additional keyword arguments to pass to the plotting function.
@@ -195,11 +197,12 @@ function _plot_fock_distribution(
195197
fock_numbers::Union{Nothing,AbstractVector} = nothing,
196198
unit_y_range::Bool = true,
197199
location::Union{GridPosition,Nothing} = nothing,
200+
atol::Real = 1e-6,
198201
kwargs...,
199202
) where {SType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}}
200203
ρ = ket2dm(ρ)
201204
D = prod.dims)
202-
(real(tr(ρ)) > 1) && (@warn "The input ρ should be normalized.")
205+
isapprox(real(tr(ρ)), 1, atol=atol) && (@warn "The input ρ should be normalized.")
203206

204207
xvec = 0:(D-1)
205208
isnothing(fock_numbers) && (fock_numbers = string.(collect(xvec)))

0 commit comments

Comments
 (0)