Skip to content

Commit 4de7264

Browse files
committed
add codereview suggestions
1 parent 5b8c30a commit 4de7264

File tree

3 files changed

+72
-38
lines changed

3 files changed

+72
-38
lines changed

ext/QuantumToolboxMakieExt.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ Add one or more quantum states to the Bloch sphere visualization by converting t
446446
- `b::Bloch`: The Bloch sphere object to modify
447447
- `states::QuantumObject...`: One or more quantum states (Ket, Bra, or Operator)
448448
449+
# Example
450+
451+
```julia
452+
x = basis(2, 0) + basis(2, 1);
453+
y = basis(2, 0) - im * basis(2, 1);
454+
z = basis(2, 0);
455+
b = Bloch();
456+
add_states!(b, [x, y, z])
457+
```
449458
"""
450459
function QuantumToolbox.add_states!(b::Bloch, states::Vector{<:QuantumObject})
451460
vecs = map(states) do state
@@ -596,7 +605,7 @@ function _draw_axes(ax)
596605
axes = [
597606
([Point3f(0, -1.01, 0), Point3f(0, 1.01, 0)], "y"), # Y-axis
598607
([Point3f(-1.01, 0, 0), Point3f(1.01, 0, 0)], "x"), # X-axis
599-
([Point3f(0, 0, -1.01), Point3f(0, 0, 1.01)], "z"), # Z-axis
608+
([Point3f(0, 0, -1.01), Point3f(0, 0, 1.01)], "z"), # Z-axis
600609
]
601610
for (points, _) in axes
602611
lines!(ax, points; color = axis_color, linewidth = axis_width)
@@ -724,7 +733,7 @@ function _plot_vectors(b::Bloch, ax)
724733
color = get(b.vector_color, i, RGBAf(0.2, 0.5, 0.8, 0.9))
725734
vec = Vec3f(v[2], -v[1], v[3])
726735
length = norm(vec)
727-
max_length = r * 0.85
736+
max_length = r * 0.90
728737
vec = length > max_length ? (vec/length) * max_length : vec
729738
arrows!(
730739
ax,
@@ -754,10 +763,10 @@ function _add_labels(ax)
754763
label_font = "TeX Gyre Heros"
755764

756765
labels = [
757-
(Point3f(1.04, 0, 0), "y"),
758-
(Point3f(0, -1.10, 0), "x"),
759-
(Point3f(0, 0, -1.10), "|1⟩"),
760-
(Point3f(0, 0, 1.08), "|0⟩"),
766+
(Point3f(1.04, 0, 0), L"\textbf{y}"),
767+
(Point3f(0, -1.10, 0), L"\textbf{x}"),
768+
(Point3f(0, 0, -1.10), L"\mathbf{|1\rangle}"),
769+
(Point3f(0, 0, 1.08), L"\mathbf{|0\rangle}"),
761770
]
762771
for (pos, text) in labels
763772
text!(ax, text; position = pos, color = label_color, fontsize = label_size, font = label_font)

src/visualization.jl

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,42 +89,42 @@ A structure representing a Bloch sphere visualization for quantum states."""
8989
arcs::Vector{Vector{Vector{Float64}}} = Vector{Vector{Vector{Float64}}}()
9090

9191
# Style properties
92-
"""Color of axis labels and text (default: '#2E3440')"""
92+
"""Color of axis labels and text"""
9393
font_color::String = "#2E3440"
9494
"""Font size for labels (default: 18)"""
9595
font_size::Int = 18
96-
"""Transparency of wireframe (default: 0.1)"""
96+
"""Transparency of wireframe"""
9797
frame_alpha::Float64 = 0.1
98-
"""Color of wireframe (default: '#E5E9F')"""
98+
"""Color of wireframe"""
9999
frame_color::String = "#E5E9F0"
100-
""" Width of wireframe lines (default: 1)"""
100+
""" Width of wireframe lines"""
101101
frame_width::Int = 1
102102

103103
# Point properties
104-
"""Default color cycle for points (default: ["blue", "red", "green", "orange"])"""
105-
point_default_color::Vector{String} = ["blue", "red", "green", "orange"]
106-
"""Colors for point markers (default: ["blue", "red", "green", "orange"])"""
107-
point_color::Vector{String} = ["blue", "red", "green", "orange"]
104+
"""Default color cycle for points"""
105+
point_default_color::Vector{String} = ["blue", "red", "green", "orange", "cyan", "magenta", "yellow", "black"]
106+
"""Colors for point markers"""
107+
point_color::Vector{String} = ["blue", "red", "green", "orange", "cyan", "magenta", "yellow", "black"]
108108
"""Marker shapes (default: [:circle, :rect, :diamond, :utriangle])"""
109109
point_marker::Vector{Symbol} = [:circle, :rect, :diamond, :utriangle]
110-
"""Marker sizes (default: [40, 48, 50, 60])"""
110+
"""Marker sizes"""
111111
point_size::Vector{Int} = [40, 48, 50, 60]
112-
"""Marker styles (default: Symbol[])"""
112+
"""Marker styles"""
113113
point_style::Vector{Symbol} = Symbol[]
114-
"""Marker transparencies (default: Float64[])"""
114+
"""Marker transparencies"""
115115
point_alpha::Vector{Float64} = Float64[]
116116

117117
# Sphere properties
118-
"""Transparency of Bloch sphere surface (default: 0.8)"""
119-
sphere_alpha::Float64 = 0.8
120-
"""Color of Bloch sphere surface (default: '#ECEFF4')"""
118+
"""Transparency of Bloch sphere surface"""
119+
sphere_alpha::Float64 = 0.9
120+
"""Color of Bloch sphere surface"""
121121
sphere_color::String = "#ECEFF4"
122122

123123
# Layout properties
124-
"""Figure size in pixels (default: (1000, 1000))"""
125-
size::Tuple{Int,Int} = (1000, 1000)
126-
"""Colors for vectors (default: ["green", "blue", "orange"])"""
127-
vector_color::Vector{String} = ["green", "blue", "orange"]
124+
"""Figure size in pixels"""
125+
size::Tuple{Int,Int} = (700, 700)
126+
"""Colors for vectors"""
127+
vector_color::Vector{String} = ["green", "blue", "orange", "red", "cyan", "magenta", "yellow", "black"]
128128
"""Width of vectors (default: 2)"""
129129
vector_width::Int = 2
130130
"""Azimuthal and elevation viewing angles in degrees (default: (-60, 30))"""
@@ -133,15 +133,15 @@ A structure representing a Bloch sphere visualization for quantum states."""
133133
# Label properties
134134
"""Labels for x-axis (default: ["x", ""])"""
135135
xlabel::Vector{String} = ["x", ""]
136-
"""Positions of x-axis labels (default: [1.2, -1.2])"""
136+
"""Positions of x-axis labels"""
137137
xlpos::Vector{Float64} = [1.2, -1.2]
138138
"""Labels for y-axis (default: ["y", ""])"""
139139
ylabel::Vector{String} = ["y", ""]
140-
"""Positions of y-axis labels (default: [1.2, -1.2])"""
140+
"""Positions of y-axis labels)"""
141141
ylpos::Vector{Float64} = [1.2, -1.2]
142142
"""Labels for z-axis (default: ["|0⟩", "|1⟩"])"""
143143
zlabel::Vector{String} = ["|0⟩", "|1⟩"]
144-
"""Positions of z-axis labels (default: [1.2, -1.2])"""
144+
"""Positions of z-axis labels"""
145145
zlpos::Vector{Float64} = [1.2, -1.2]
146146
end
147147

@@ -241,16 +241,6 @@ Add a line between two points on the Bloch sphere.
241241
- p2::Vector{<:Real}: Second 3D point
242242
- fmt="k": Line format string (matplotlib style)
243243
- kwargs...: Additional line properties
244-
245-
# Examples
246-
247-
```jldoctest
248-
julia> b = Bloch();
249-
250-
julia> add_line!(b, [1, 0, 0], [0, 1, 0])
251-
1-element Vector{Tuple{Vector{Vector{Float64}}, String, Dict{Any, Any}}}:
252-
([[0.0, 1.0], [-1.0, 0.0], [0.0, 0.0]], "k", Dict())
253-
```
254244
"""
255245
function add_line!(b::Bloch, p1::Vector{<:Real}, p2::Vector{<:Real}; fmt = "k", kwargs...)
256246
if length(p1) != 3 || length(p2) != 3

test/ext-test/cpu/makie/makie_ext.jl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
@test isempty(b.vectors)
121121
@test isempty(b.lines)
122122
@test isempty(b.arcs)
123-
124123
b = Bloch()
125124
add_points!(b, hcat([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]))
126125
add_vectors!(b, [[1, 1, 0], [0, 1, 1]])
@@ -134,4 +133,40 @@
134133
@test false
135134
@info "Render threw unexpected error" exception=e
136135
end
136+
b = Bloch()
137+
ψ₁ = normalize(basis(2, 0) + basis(2, 1))
138+
ψ₂ = normalize(basis(2, 0) - im * basis(2, 1))
139+
add_line!(b, ψ₁, ψ₂; fmt = "r--")
140+
try
141+
fig, ax = QuantumToolbox.render(b)
142+
@test !isnothing(fig)
143+
@test !isnothing(ax)
144+
catch e
145+
@test false
146+
@info "Render threw unexpected error" exception=e
147+
end
148+
b = Bloch()
149+
x = basis(2, 0) + basis(2, 1)
150+
y = basis(2, 0) - im * basis(2, 1)
151+
z = basis(2, 0)
152+
add_states!(b, [x, y, z])
153+
th = range(0, 2π; length=20);
154+
xp = cos.(th);
155+
yp = sin.(th);
156+
zp = zeros(20);
157+
pnts = [xp, yp, zp] ;
158+
pnts = Matrix(hcat(xp, yp, zp)');
159+
add_points!(b, pnts);
160+
vec = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
161+
add_vectors!(b, vec);
162+
add_line!(b, [1,0,0], [0,1,0])
163+
add_arc!(b, [1, 0, 0], [0, 1, 0], [0, 0, 1])
164+
try
165+
fig, ax = QuantumToolbox.render(b)
166+
@test !isnothing(fig)
167+
@test !isnothing(ax)
168+
catch e
169+
@test false
170+
@info "Render threw unexpected error" exception=e
171+
end
137172
end

0 commit comments

Comments
 (0)