Skip to content

Commit 23c7bb2

Browse files
formatting
1 parent 1a21ab3 commit 23c7bb2

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

ext/QuantumToolboxCairoMakieExt.jl

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Note that CairoMakie must first be imported before using this function.
2424
# Arguments
2525
- `library::Val{:CairoMakie}`: The plotting library to use.
2626
- `state::QuantumObject`: The quantum state for which the Wigner function is calculated. It can be either a [`KetQuantumObject`](@ref), [`BraQuantumObject`](@ref), or [`OperatorQuantumObject`](@ref).
27-
- `xvec::AbstractVector`: The x-coordinates of the phase space grid. Default is # TODO
28-
- `yvec::AbstractVector`: The y-coordinates of the phase space grid. Default is # TODO
27+
- `xvec::AbstractVector`: The x-coordinates of the phase space grid. Defaults to a linear range from -7.5 to 7.5 with 200 points.
28+
- `yvec::AbstractVector`: The y-coordinates of the phase space grid. Defaults to a linear range from -7.5 to 7.5 with 200 points.
2929
- `g::Real`: The scaling factor related to the value of ``\hbar`` in the commutation relation ``[x, y] = i \hbar`` via ``\hbar=2/g^2``.
3030
- `method::WignerSolver`: The method used to calculate the Wigner function. It can be either `WignerLaguerre()` or `WignerClenshaw()`, with `WignerClenshaw()` as default. The `WignerLaguerre` method has the optional `parallel` and `tol` parameters, with default values `true` and `1e-14`, respectively.
3131
- `projection::Union{Val,Symbol}`: Wheather to plot the Wigner function in 2D or 3D. It can be either `Val(:two_dim)` or `Val(:three_dim)`, with `Val(:two_dim)` as default.
@@ -44,8 +44,8 @@ Note that CairoMakie must first be imported before using this function.
4444
function QuantumToolbox.plot_wigner(
4545
library::Val{:CairoMakie},
4646
state::QuantumObject{<:AbstractArray{T},OpType};
47-
xvec::Union{Nothing,AbstractVector} = nothing,
48-
yvec::Union{Nothing,AbstractVector} = nothing,
47+
xvec::Union{Nothing,AbstractVector} = LinRange(-7.5, 7.5, 200),
48+
yvec::Union{Nothing,AbstractVector} = LinRange(-7.5, 7.5, 200),
4949
g::Real = 2,
5050
method::WignerSolver = WignerClenshaw(),
5151
projection::Union{Val,Symbol} = Val(:two_dim),
@@ -138,17 +138,77 @@ function _plot_wigner(
138138
return fig, ax, surf
139139
end
140140

141+
@doc raw"""
142+
_getFigAndLocation(location::Nothing)
143+
144+
Create a new figure and return it, together with the GridPosition object pointing to the first cell.
145+
146+
# Arguments
147+
- `location::Nothing`
148+
149+
# Returns
150+
- `fig`: The figure object.
151+
- `location`: The GridPosition object pointing to the first cell.
152+
"""
141153
function _getFigAndLocation(location::Nothing)
142154
fig = Figure()
143155
return fig, fig[1, 1]
144156
end
157+
158+
@doc raw"""
159+
_getFigAndLocation(location::GridPosition)
160+
161+
Compute which figure does the location belong to and return it, together with the location itself.
162+
163+
# Arguments
164+
- `location::GridPosition`
165+
166+
# Returns
167+
- `fig`: The figure object.
168+
- `location`: The GridPosition object.
169+
"""
145170
function _getFigAndLocation(location::GridPosition)
146171
fig = _figFromChildren(location.layout)
147172
return fig, location
148173
end
149174

175+
@doc raw"""
176+
_figFromChildren(children::GridLayout)
177+
178+
Recursively find the figure object from the children layout.
179+
180+
# Arguments
181+
- `children::GridLayout`
182+
183+
# Returns
184+
- Union{Nothing, Figure, GridLayout}: The children's parent object.
185+
"""
150186
_figFromChildren(children) = _figFromChildren(children.parent)
187+
188+
@doc raw"""
189+
_figFromChildren(fig::Figure)
190+
191+
Return the figure object
192+
193+
# Arguments
194+
- `fig::Figure`
195+
196+
# Returns
197+
- `fig`: The figure object.
198+
"""
151199
_figFromChildren(fig::Figure) = fig
200+
201+
@doc raw"""
202+
_figFromChildren(::Nothing)
203+
204+
Throw an error if no figure has been found.
205+
206+
# Arguments
207+
- `::Nothing`
208+
209+
# Throws
210+
- `ArgumentError`: If no figure has been found.
211+
"""
152212
_figFromChildren(::Nothing) = throw(ArgumentError("No Figure has been found at the top of the layout hierarchy."))
153213

154-
end
214+
end

src/visualization.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ The `library` keyword argument specifies the plotting library to use, defaulting
1515
- `state::QuantumObject{<:AbstractArray{T},OpType}`: The quantum state for which to plot the Wigner distribution.
1616
- `library::Union{Val,Symbol}`: The plotting library to use. Default is `Val(:CairoMakie)`.
1717
- `kwargs...`: Additional keyword arguments to pass to the plotting function. See the documentation for the specific plotting library for more information.
18+
19+
!!! warning "Beware of type-stability!"
20+
If you want to keep type stability, it is recommended to use `Val(:CairoMakie)` instead of `:CairoMakie` as the plotting library. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details.
1821
"""
1922
plot_wigner(
2023
state::QuantumObject{<:AbstractArray{T},OpType};

0 commit comments

Comments
 (0)