Skip to content

Commit 130eafe

Browse files
Make Makie extension more general (#450)
1 parent ad8b0b8 commit 130eafe

File tree

12 files changed

+58
-71
lines changed

12 files changed

+58
-71
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
node:
6868
os: 'ubuntu-latest'
6969
arch: 'x64'
70-
group: 'CairoMakie_Ext'
70+
group: 'Makie_Ext'
7171
- version: '1'
7272
node:
7373
os: 'ubuntu-latest'

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)
99

1010
- Support different length for `to` and `from` on GeneralDimensions. ([#448])
11+
- Extend the `Makie.jl` extension to all the other available backends. ([#450])
1112

1213
## [v0.30.0]
1314
Release date: 2025-04-12
@@ -204,3 +205,4 @@ Release date: 2024-11-13
204205
[#440]: https://github.com/qutip/QuantumToolbox.jl/issues/440
205206
[#443]: https://github.com/qutip/QuantumToolbox.jl/issues/443
206207
[#448]: https://github.com/qutip/QuantumToolbox.jl/issues/448
208+
[#450]: https://github.com/qutip/QuantumToolbox.jl/issues/450

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,20 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
2727

2828
[weakdeps]
2929
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
30-
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3130
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
3231
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
3332
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
33+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
3434

3535
[extensions]
36-
QuantumToolboxCairoMakieExt = "CairoMakie"
36+
QuantumToolboxMakieExt = "Makie"
3737
QuantumToolboxChainRulesCoreExt = "ChainRulesCore"
3838
QuantumToolboxCUDAExt = "CUDA"
3939
QuantumToolboxGPUArraysExt = ["GPUArrays", "KernelAbstractions"]
4040

4141
[compat]
4242
ArrayInterface = "6, 7"
4343
CUDA = "5"
44-
CairoMakie = "0.12, 0.13"
4544
ChainRulesCore = "1"
4645
DiffEqBase = "6"
4746
DiffEqCallbacks = "4.2.1 - 4"
@@ -54,6 +53,7 @@ IncompleteLU = "0.2"
5453
KernelAbstractions = "0.9.2"
5554
LinearAlgebra = "1"
5655
LinearSolve = "2, 3"
56+
Makie = "0.20, 0.21, 0.22"
5757
OrdinaryDiffEqCore = "1"
5858
OrdinaryDiffEqTsit5 = "1"
5959
Pkg = "1"

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const PAGES = [
8181
makedocs(;
8282
modules = [
8383
QuantumToolbox,
84-
Base.get_extension(QuantumToolbox, :QuantumToolboxCairoMakieExt),
84+
Base.get_extension(QuantumToolbox, :QuantumToolboxMakieExt),
8585
],
8686
authors = "Alberto Mercurio and Yi-Te Huang",
8787
repo = Remotes.GitHub("qutip", "QuantumToolbox.jl"),

docs/src/getting_started/logo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ xvec = range(-ρ, ρ, 500) .* 1.5
7676
yvec = xvec .+ (abs(imag(α1)) - abs(imag(α2))) / 2
7777
7878
fig = Figure(size = (250, 250), figure_padding = 0)
79-
fig, ax, hm = plot_wigner(ψ, xvec = xvec, yvec = yvec, g = 2, library = Val(:CairoMakie), location = fig[1,1])
79+
fig, ax, hm = plot_wigner(ψ, xvec = xvec, yvec = yvec, g = 2, library = Val(:Makie), location = fig[1,1])
8080
hidespines!(ax)
8181
hidexdecorations!(ax)
8282
hideydecorations!(ax)
@@ -110,7 +110,7 @@ And the Wigner function becomes more uniform:
110110

111111
```@example logo
112112
fig = Figure(size = (250, 250), figure_padding = 0)
113-
fig, ax, hm = plot_wigner(sol.states[end], xvec = xvec, yvec = yvec, g = 2, library = Val(:CairoMakie), location = fig[1,1])
113+
fig, ax, hm = plot_wigner(sol.states[end], xvec = xvec, yvec = yvec, g = 2, library = Val(:Makie), location = fig[1,1])
114114
hidespines!(ax)
115115
hidexdecorations!(ax)
116116
hideydecorations!(ax)

docs/src/users_guide/extensions/cairomakie.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# [Extension for CairoMakie.jl](@id doc:CairoMakie)
1+
# [Extension for the Makie.jl ecosystem](@id doc:Makie)
22

3-
This is an extension to support visualization (plotting functions) using [`CairoMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie) library.
3+
This is an extension to support visualization (plotting functions) using [`Makie.jl`](https://github.com/MakieOrg/Makie.jl) library.
44

5-
This extension will be automatically loaded if user imports both `QuantumToolbox.jl` and [`CairoMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie):
5+
This extension will be automatically loaded if user imports both `QuantumToolbox.jl` and [`Makie.jl`](https://github.com/MakieOrg/Makie.jl). It is worth noting that the `Makie.jl` package provides only the engine for plotting, and the user has to import the specific backend. Here we demonstrate the usage of [`CairoMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie), which will automatically import `Makie.jl`.
66

77
```julia
88
using QuantumToolbox
99
using CairoMakie
1010
```
1111

12-
To plot with [`CairoMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie) library, specify the keyword argument `library = Val(:CairoMakie)` for the plotting functions.
12+
To plot with [`CairoMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie) library, specify the keyword argument `library = Val(:Makie)` for the plotting functions.
1313

1414
!!! warning "Beware of type-stability!"
15-
If you want to keep type stability, it is recommended to use `Val(:CairoMakie)` instead of `: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.
15+
If you want to keep type stability, it is recommended to use `Val(:Makie)` instead of `:Makie`. 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.
1616

1717
The supported plotting functions are listed as follows:
1818

ext/QuantumToolboxCairoMakieExt.jl renamed to ext/QuantumToolboxMakieExt.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
module QuantumToolboxCairoMakieExt
1+
module QuantumToolboxMakieExt
22

33
using QuantumToolbox
4-
using CairoMakie:
4+
using Makie:
55
Axis, Axis3, Colorbar, Figure, GridLayout, heatmap!, surface!, barplot!, GridPosition, @L_str, Reverse, ylims!
66

77
@doc raw"""
88
plot_wigner(
9-
library::Val{:CairoMakie},
9+
library::Val{:Makie},
1010
state::QuantumObject{OpType};
1111
xvec::Union{Nothing,AbstractVector} = nothing,
1212
yvec::Union{Nothing,AbstractVector} = nothing,
@@ -18,10 +18,10 @@ using CairoMakie:
1818
kwargs...
1919
) where {OpType}
2020
21-
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+
Plot the [Wigner quasipropability distribution](https://en.wikipedia.org/wiki/Wigner_quasiprobability_distribution) of `state` using the [`Makie`](https://github.com/MakieOrg/Makie.jl) plotting library.
2222
2323
# Arguments
24-
- `library::Val{:CairoMakie}`: The plotting library to use.
24+
- `library::Val{:Makie}`: The plotting library to use.
2525
- `state::QuantumObject`: The quantum state for which the Wigner function is calculated. It can be either a [`Ket`](@ref), [`Bra`](@ref), or [`Operator`](@ref).
2626
- `xvec::AbstractVector`: The x-coordinates of the phase space grid. Defaults to a linear range from -7.5 to 7.5 with 200 points.
2727
- `yvec::AbstractVector`: The y-coordinates of the phase space grid. Defaults to a linear range from -7.5 to 7.5 with 200 points.
@@ -38,13 +38,13 @@ Plot the [Wigner quasipropability distribution](https://en.wikipedia.org/wiki/Wi
3838
- `hm`: Either the heatmap or surface object, depending on the projection.
3939
4040
!!! note "Import library first"
41-
[`CairoMakie`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie) must first be imported before using this function.
41+
[`Makie.jl`](https://github.com/MakieOrg/Makie.jl) must first be imported before using this function. This can be done by importing one of the available backends, such as [`CairoMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie), [`GLMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/GLMakie), or [`WGLMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/WGLMakie).
4242
4343
!!! warning "Beware of type-stability!"
44-
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.
44+
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(:Makie)` 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.
4545
"""
4646
function QuantumToolbox.plot_wigner(
47-
library::Val{:CairoMakie},
47+
library::Val{:Makie},
4848
state::QuantumObject{OpType};
4949
xvec::Union{Nothing,AbstractVector} = LinRange(-7.5, 7.5, 200),
5050
yvec::Union{Nothing,AbstractVector} = LinRange(-7.5, 7.5, 200),
@@ -74,7 +74,7 @@ function QuantumToolbox.plot_wigner(
7474
end
7575

7676
function _plot_wigner(
77-
::Val{:CairoMakie},
77+
::Val{:Makie},
7878
state::QuantumObject{OpType},
7979
xvec::AbstractVector,
8080
yvec::AbstractVector,
@@ -107,7 +107,7 @@ function _plot_wigner(
107107
end
108108

109109
function _plot_wigner(
110-
::Val{:CairoMakie},
110+
::Val{:Makie},
111111
state::QuantumObject{OpType},
112112
xvec::AbstractVector,
113113
yvec::AbstractVector,
@@ -142,7 +142,7 @@ end
142142

143143
@doc raw"""
144144
plot_fock_distribution(
145-
library::Val{:CairoMakie},
145+
library::Val{:Makie},
146146
ρ::QuantumObject{SType};
147147
fock_numbers::Union{Nothing, AbstractVector} = nothing,
148148
unit_y_range::Bool = true,
@@ -153,7 +153,7 @@ end
153153
Plot the [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution of `ρ`.
154154
155155
# Arguments
156-
- `library::Val{:CairoMakie}`: The plotting library to use.
156+
- `library::Val{:Makie}`: The plotting library to use.
157157
- `ρ::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).
158158
- `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`.
159159
- `fock_numbers::Union{Nothing, AbstractVector}`: list of x ticklabels to represent fock numbers, default is `nothing`.
@@ -166,13 +166,13 @@ Plot the [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution of
166166
- `bp`: The barplot object.
167167
168168
!!! note "Import library first"
169-
[`CairoMakie`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie) must first be imported before using this function.
169+
[`Makie.jl`](https://github.com/MakieOrg/Makie.jl) must first be imported before using this function. This can be done by importing one of the available backends, such as [`CairoMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie), [`GLMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/GLMakie), or [`WGLMakie.jl`](https://github.com/MakieOrg/Makie.jl/tree/master/WGLMakie).
170170
171171
!!! warning "Beware of type-stability!"
172-
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.
172+
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(:Makie)` 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.
173173
"""
174174
function QuantumToolbox.plot_fock_distribution(
175-
library::Val{:CairoMakie},
175+
library::Val{:Makie},
176176
ρ::QuantumObject{SType};
177177
fock_numbers::Union{Nothing,AbstractVector} = nothing,
178178
unit_y_range::Bool = true,
@@ -190,7 +190,7 @@ function QuantumToolbox.plot_fock_distribution(
190190
end
191191

192192
function _plot_fock_distribution(
193-
::Val{:CairoMakie},
193+
::Val{:Makie},
194194
ρ::QuantumObject{SType};
195195
fock_numbers::Union{Nothing,AbstractVector} = nothing,
196196
unit_y_range::Bool = true,

src/visualization.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ export plot_wigner, plot_fock_distribution
33
@doc raw"""
44
plot_wigner(
55
state::QuantumObject{OpType};
6-
library::Union{Val,Symbol}=Val(:CairoMakie),
6+
library::Union{Val,Symbol}=Val(:Makie),
77
kwargs...
88
) where {OpType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}
99
1010
Plot the [Wigner quasipropability distribution](https://en.wikipedia.org/wiki/Wigner_quasiprobability_distribution) of `state` using the [`wigner`](@ref) function.
1111
12-
The `library` keyword argument specifies the plotting library to use, defaulting to [`CairoMakie`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie).
12+
The `library` keyword argument specifies the plotting library to use, defaulting to [`Makie.jl`](https://github.com/MakieOrg/Makie.jl).
1313
1414
# Arguments
1515
- `state::QuantumObject`: The quantum state for which to plot the Wigner distribution.
16-
- `library::Union{Val,Symbol}`: The plotting library to use. Default is `Val(:CairoMakie)`.
16+
- `library::Union{Val,Symbol}`: The plotting library to use. Default is `Val(:Makie)`.
1717
- `kwargs...`: Additional keyword arguments to pass to the plotting function. See the documentation for the specific plotting library for more information.
1818
1919
!!! note "Import library first"
2020
The plotting libraries must first be imported before using them with this function.
2121
2222
!!! warning "Beware of type-stability!"
23-
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.
23+
If you want to keep type stability, it is recommended to use `Val(:Makie)` instead of `:Makie` 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.
2424
"""
2525
plot_wigner(
2626
state::QuantumObject{OpType};
27-
library::Union{Val,Symbol} = Val(:CairoMakie),
27+
library::Union{Val,Symbol} = Val(:Makie),
2828
kwargs...,
2929
) where {OpType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}} =
3030
plot_wigner(makeVal(library), state; kwargs...)
@@ -39,28 +39,28 @@ plot_wigner(
3939
@doc raw"""
4040
plot_fock_distribution(
4141
ρ::QuantumObject{SType};
42-
library::Union{Val, Symbol} = Val(:CairoMakie),
42+
library::Union{Val, Symbol} = Val(:Makie),
4343
kwargs...
4444
) where {SType<:Union{KetQuantumObject,OperatorQuantumObject}}
4545
4646
Plot the [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution of `ρ`.
4747
48-
The `library` keyword argument specifies the plotting library to use, defaulting to [`CairoMakie`](https://github.com/MakieOrg/Makie.jl/tree/master/CairoMakie).
48+
The `library` keyword argument specifies the plotting library to use, defaulting to [`Makie`](https://github.com/MakieOrg/Makie.jl).
4949
5050
# Arguments
5151
- `ρ::QuantumObject`: The quantum state for which to plot the Fock state distribution.
52-
- `library::Union{Val,Symbol}`: The plotting library to use. Default is `Val(:CairoMakie)`.
52+
- `library::Union{Val,Symbol}`: The plotting library to use. Default is `Val(:Makie)`.
5353
- `kwargs...`: Additional keyword arguments to pass to the plotting function. See the documentation for the specific plotting library for more information.
5454
5555
!!! note "Import library first"
5656
The plotting libraries must first be imported before using them with this function.
5757
5858
!!! warning "Beware of type-stability!"
59-
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.
59+
If you want to keep type stability, it is recommended to use `Val(:Makie)` instead of `:Makie` 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.
6060
"""
6161
plot_fock_distribution(
6262
ρ::QuantumObject{SType};
63-
library::Union{Val,Symbol} = Val(:CairoMakie),
63+
library::Union{Val,Symbol} = Val(:Makie),
6464
kwargs...,
6565
) where {SType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}} =
6666
plot_fock_distribution(makeVal(library), ρ; kwargs...)

test/ext-test/cpu/cairomakie/Project.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/ext-test/cpu/makie/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
3+
QuantumToolbox = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"

0 commit comments

Comments
 (0)