Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Improve efficiency of `bloch_redfield_tensor` by avoiding unnecessary conversions. ([#509])
- Support `SciMLOperators v1.4+`. ([#470])
- Fix compatibility with `Makie v0.24+`. ([#513])

## [v0.33.0]
Release date: 2025-07-22
Expand Down Expand Up @@ -272,3 +273,4 @@ Release date: 2024-11-13
[#506]: https://github.com/qutip/QuantumToolbox.jl/issues/506
[#507]: https://github.com/qutip/QuantumToolbox.jl/issues/507
[#509]: https://github.com/qutip/QuantumToolbox.jl/issues/509
[#513]: https://github.com/qutip/QuantumToolbox.jl/issues/513
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ KernelAbstractions = "0.9.2"
LaTeXStrings = "1.2"
LinearAlgebra = "1"
LinearSolve = "2, 3"
Makie = "0.20, 0.21, 0.22, 0.23"
Makie = "0.24"
OrdinaryDiffEqCore = "1"
OrdinaryDiffEqTsit5 = "1"
Pkg = "1"
Expand Down
5 changes: 3 additions & 2 deletions docs/src/users_guide/plotting_the_bloch_sphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ At the end of the last section we saw that the colors and marker shapes of the d
| `b.sphere_color` | Color of Bloch sphere surface | `0.2` |
| `b.sphere_alpha` | Transparency of sphere surface | `"#FFDDDD"` |
| `b.vector_color` | Colors for vectors | `["green", "#CC6600", "blue", "red"]` |
| `b.vector_width` | Width of vectors | `0.025` |
| `b.vector_arrowsize` | Scales the size of the arrow head. The first two elements scale the radius (in `x/y` direction) and the last one is the length of the cone. | `[0.07, 0.08, 0.08]` |
| `b.vector_width` | Width of vectors | `0.02` |
| `b.vector_tiplength` | Length of vector arrow head | `0.08` |
| `b.vector_tipradius` | Radius of vector arrow head | `0.05` |
| `b.view` | Azimuthal and elevation viewing angles in degrees | `[30, 30]` |
| `b.xlabel` | Labels for x-axis | `[L"x", ""]` (``+x`` and ``-x``) |
| `b.xlpos` | Positions of x-axis labels | `[1.2, -1.2]` |
Expand Down
21 changes: 6 additions & 15 deletions ext/QuantumToolboxMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Makie:
Sphere,
lines!,
scatter!,
arrows!,
arrows3d!,
text!,
Point3f,
mesh!,
Expand Down Expand Up @@ -656,26 +656,17 @@ Scales vectors appropriately and adds `3D` arrow markers.
function _plot_vectors!(b::Bloch, lscene)
isempty(b.vectors) && return nothing

arrow_head_length = b.vector_arrowsize[3]
for (i, v) in enumerate(b.vectors)
color = get(b.vector_color, i, RGBAf(0.2, 0.5, 0.8, 0.9))
nv = norm(v)
(arrow_head_length < nv) || throw(
ArgumentError(
"The length of vector arrow head (Bloch.vector_arrowsize[3]=$arrow_head_length) should be shorter than vector norm: $nv",
),
)

# multiply by the following factor makes the end point of arrow head represent the actual vector position.
vec = (1 - arrow_head_length / nv) * Vec3f(v...)
arrows!(
arrows3d!(
lscene,
[Point3f(0, 0, 0)],
[vec],
[v],
color = color,
linewidth = b.vector_width,
arrowsize = Vec3f(b.vector_arrowsize...),
arrowcolor = color,
shaftradius = b.vector_width,
tiplength = b.vector_tiplength,
tipradius = b.vector_tipradius,
rasterize = 3,
)
end
Expand Down
10 changes: 6 additions & 4 deletions src/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ A structure representing a Bloch sphere visualization for quantum states. Availa
## Vector properties

- `vector_color::Vector{String}`: Colors for vectors. Default: `["green", "#CC6600", "blue", "red"]`
- `vector_width::Float64`: Width of vectors. Default: `0.025`
- `vector_arrowsize::Vector{Float64}`: Scales the size of the arrow head. The first two elements scale the radius (in `x/y` direction) and the last one is the length of the cone. Default: `[0.07, 0.08, 0.08]`
- `vector_width::Float64`: Width of vectors. Default: `0.02`
- `vector_tiplength::Float64`: Length of vector arrow head. Default: `0.08`
- `vector_tipradius::Float64`: Radius of vector arrow head. Default: `0.05`

## Layout properties

Expand Down Expand Up @@ -137,8 +138,9 @@ A structure representing a Bloch sphere visualization for quantum states. Availa
sphere_alpha::Float64 = 0.2
sphere_color::String = "#FFDDDD"
vector_color::Vector{String} = ["green", "#CC6600", "blue", "red"]
vector_width::Float64 = 0.025
vector_arrowsize::Vector{Float64} = [0.07, 0.08, 0.08]
vector_width::Float64 = 0.02
vector_tiplength::Float64 = 0.08
vector_tipradius::Float64 = 0.05
view::Vector{Int} = [30, 30]
xlabel::Vector{AbstractString} = [L"x", ""]
xlpos::Vector{Float64} = [1.2, -1.2]
Expand Down
6 changes: 2 additions & 4 deletions test/ext-test/cpu/makie/makie_ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
@test fig isa Figure
@test ax isa Axis
@test hm isa Heatmap
@test all(isapprox.(hm[3].val, wig, atol = 1e-6))
@test all(isapprox.(hm[3].value.x, wig, atol = 1e-6))

fig, ax, surf =
plot_wigner(ψ; library = Val(:Makie), xvec = xvec, yvec = yvec, projection = Val(:three_dim), colorbar = true)
@test fig isa Figure
@test ax isa Axis3
@test surf isa Surface
@test all(isapprox.(surf[3].val, wig, atol = 1e-6))
@test all(isapprox.(surf[3].value.x, wig, atol = 1e-6))

fig = Figure()
pos = fig[2, 3]
Expand Down Expand Up @@ -150,8 +150,6 @@ end
@test false
@info "Render threw unexpected error" exception=e
end
b.vector_arrowsize = [0.7, 0.8, 1.5] # 1.5 is the length of arrow head (too long)
@test_throws ArgumentError render(b)

b = Bloch()
ψ₁ = normalize(basis(2, 0) + basis(2, 1))
Expand Down
Loading