Skip to content

Commit 1a21ab3

Browse files
docs
1 parent 2cc344b commit 1a21ab3

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

ext/QuantumToolboxCairoMakieExt.jl

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@ module QuantumToolboxCairoMakieExt
33
using QuantumToolbox
44
using CairoMakie
55

6+
@doc raw"""
7+
plot_wigner(
8+
library::Val{:CairoMakie},
9+
state::QuantumObject{<:AbstractArray{T},OpType};
10+
xvec::Union{Nothing,AbstractVector} = nothing,
11+
yvec::Union{Nothing,AbstractVector} = nothing,
12+
g::Real = √2,
13+
method::WignerSolver = WignerClenshaw(),
14+
projection::Union{Val,Symbol} = Val(:two_dim),
15+
location::Union{GridPosition,Nothing} = nothing,
16+
colorbar::Bool = false,
17+
kwargs...
18+
)
19+
20+
Plot the [Wigner quasipropability distribution](https://en.wikipedia.org/wiki/Wigner_quasiprobability_distribution) of `state` using the [CairoMakie](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie) plotting library.
21+
22+
Note that CairoMakie must first be imported before using this function.
23+
24+
# Arguments
25+
- `library::Val{:CairoMakie}`: The plotting library to use.
26+
- `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
29+
- `g::Real`: The scaling factor related to the value of ``\hbar`` in the commutation relation ``[x, y] = i \hbar`` via ``\hbar=2/g^2``.
30+
- `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.
31+
- `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.
32+
- `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`.
33+
- `colorbar::Bool`: Whether to include a colorbar in the plot. Default is `false`.
34+
- `kwargs...`: Additional keyword arguments to pass to the plotting function.
35+
36+
# Returns
37+
- `fig`: The figure object.
38+
- `ax`: The axis object.
39+
- `hm`: Either the heatmap or surface object, depending on the projection.
40+
41+
!!! warning "Beware of type-stability!"
42+
If you want to keep type stability, it is recommended to use `Val(:two_dim)` and `Val(:three_dim)` instead of `:two_dim` and `:three_dim`, respectively. Also, specify the library as `Val(:CairoMakie)` 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.
43+
"""
644
function QuantumToolbox.plot_wigner(
745
library::Val{:CairoMakie},
846
state::QuantumObject{<:AbstractArray{T},OpType};
@@ -54,8 +92,8 @@ function _plot_wigner(
5492
wig = wigner(state, xvec, yvec; g = g, method = method)
5593
wlim = maximum(abs, wig)
5694

57-
kwargs = merge(Dict(:colormap => :RdBu, :colorrange => (-wlim, wlim)), kwargs)
58-
hm = heatmap!(ax, xvec, yvec, wig; kwargs...)
95+
kwargs = merge(Dict(:colormap => Reverse(:RdBu), :colorrange => (-wlim, wlim)), kwargs)
96+
hm = heatmap!(ax, xvec, yvec, wig'; kwargs...)
5997

6098
if colorbar
6199
Colorbar(lyt[1, 2], hm)
@@ -88,7 +126,7 @@ function _plot_wigner(
88126
wlim = maximum(abs, wig)
89127

90128
kwargs = merge(Dict(:colormap => :RdBu, :colorrange => (-wlim, wlim)), kwargs)
91-
surf = surface!(ax, xvec, yvec, wig; kwargs...)
129+
surf = surface!(ax, xvec, yvec, wig'; kwargs...)
92130

93131
if colorbar
94132
Colorbar(lyt[1, 2], surf)

src/visualization.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
export plot_wigner
22

3+
@doc raw"""
4+
plot_wigner(
5+
state::QuantumObject{<:AbstractArray{T},OpType};
6+
library::Union{Val,Symbol}=Val(:CairoMakie),
7+
kwargs...
8+
)
9+
10+
Plot the [Wigner quasipropability distribution](https://en.wikipedia.org/wiki/Wigner_quasiprobability_distribution) of `state` using the [`wigner`](@ref) function.
11+
12+
The `library` keyword argument specifies the plotting library to use, defaulting to `CairoMakie`. Note that plotting libraries must first be imported before using them with this function.
13+
14+
# Arguments
15+
- `state::QuantumObject{<:AbstractArray{T},OpType}`: The quantum state for which to plot the Wigner distribution.
16+
- `library::Union{Val,Symbol}`: The plotting library to use. Default is `Val(:CairoMakie)`.
17+
- `kwargs...`: Additional keyword arguments to pass to the plotting function. See the documentation for the specific plotting library for more information.
18+
"""
319
plot_wigner(
420
state::QuantumObject{<:AbstractArray{T},OpType};
521
library::Union{Val,Symbol} = Val(:CairoMakie),

0 commit comments

Comments
 (0)