From 68ce845160c1060a2812ab277f4a1ca1730c44b8 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Thu, 5 Jun 2025 11:08:49 +0200 Subject: [PATCH 1/3] Fix Bloch Sphere rendering --- Project.toml | 2 -- docs/make.jl | 4 ++-- ext/QuantumToolboxMakieExt.jl | 3 ++- src/visualization.jl | 12 ++++++------ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Project.toml b/Project.toml index 6f53877f9..3159c0b3a 100644 --- a/Project.toml +++ b/Project.toml @@ -12,7 +12,6 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895" -LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" @@ -52,7 +51,6 @@ GPUArrays = "10, 11" Graphs = "1.7" IncompleteLU = "0.2" KernelAbstractions = "0.9.2" -LaTeXStrings = "1.2" LinearAlgebra = "1" LinearSolve = "2, 3" Makie = "0.20, 0.21, 0.22" diff --git a/docs/make.jl b/docs/make.jl index 0a8354412..8308c9cb2 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -18,8 +18,8 @@ end DocMeta.setdocmeta!(QuantumToolbox, :DocTestSetup, doctest_setup; recursive = true) # some options for `makedocs` -const DRAFT = false # set `true` to disable cell evaluation -const DOCTEST = true # set `false` to skip doc tests +const DRAFT = get(ENV, "DRAFT", false) == "true" # set `true` to disable cell evaluation +const DOCTEST = get(ENV, "DOCTEST", true) == "true" # set `false` to skip doc tests # generate bibliography bib = CitationBibliography( diff --git a/ext/QuantumToolboxMakieExt.jl b/ext/QuantumToolboxMakieExt.jl index 2200fc26f..c77aceff9 100644 --- a/ext/QuantumToolboxMakieExt.jl +++ b/ext/QuantumToolboxMakieExt.jl @@ -417,7 +417,7 @@ function _draw_bloch_sphere!(b::Bloch, ax) base_color = parse(RGBf, b.sphere_color) sphere_color = RGBAf(base_color, b.sphere_alpha) sphere_mesh = Sphere(Point3f(0), radius) - mesh!(ax, sphere_mesh; color = sphere_color, shading = NoShading, transparency = true) + mesh!(ax, sphere_mesh; color = sphere_color, shading = NoShading, transparency = true, rasterize = 3) θ_vals = range(0.0f0, 2π, length = n_lon + 1)[1:(end-1)] φ_curve = range(0.0f0, π, length = 600) line_alpha = max(0.05, b.sphere_alpha * 0.5) @@ -644,6 +644,7 @@ function _plot_vectors!(b::Bloch, ax) linewidth = b.vector_width, arrowsize = arrowsize_vec, arrowcolor = color, + rasterize = 3, ) end end diff --git a/src/visualization.jl b/src/visualization.jl index 3605f21c5..34d5c4252 100644 --- a/src/visualization.jl +++ b/src/visualization.jl @@ -110,11 +110,11 @@ A structure representing a Bloch sphere visualization for quantum states. - `view::Tuple{Int,Int}}`: Azimuthal and elevation viewing angles in degrees (default: (-60, 30)) ## Label properties -- `xlabel::Vector{AbstractString}}`: Labels for x-axis (default: [L"x", ""]) +- `xlabel::Vector{String}}`: Labels for x-axis (default: [raw"$x$", ""]) - `xlpos::Vector{Float64}}`: Positions of x-axis labels (default: [1.0, -1.0]) -- `ylabel::Vector{AbstractString}}`: Labels for y-axis (default: [L"y", ""]) +- `ylabel::Vector{String}}`: Labels for y-axis (default: [raw"$y$", ""]) - `ylpos::Vector{Float64}}`: Positions of y-axis labels (default: [1.0, -1.0]) -- `zlabel::Vector{AbstractString}}`: Labels for z-axis (default: [L"|0\rangle", L"|1\rangle"]) +- `zlabel::Vector{String}}`: Labels for z-axis (default: [raw"$|0\rangle$", raw"$|1\rangle$"]) - `zlpos::Vector{Float64}}`: Positions of z-axis labels (default: [1.0, -1.0]) """ @kwdef mutable struct Bloch @@ -139,11 +139,11 @@ A structure representing a Bloch sphere visualization for quantum states. vector_width::Float64 = 0.025 vector_arrowsize::NTuple{3,Real} = (0.07, 0.08, 0.08) view::Tuple{Int,Int} = (-60, 30) - xlabel::Vector{AbstractString} = [L"x", ""] + xlabel::Vector{String} = [raw"$x$", raw""] xlpos::Vector{Float64} = [1.0, -1.0] - ylabel::Vector{AbstractString} = [L"y", ""] + ylabel::Vector{String} = [raw"$y$", ""] ylpos::Vector{Float64} = [1.0, -1.0] - zlabel::Vector{AbstractString} = [L"|0\rangle", L"|1\rangle"] + zlabel::Vector{String} = [raw"$|0\rangle$", raw"$|1\rangle$"] zlpos::Vector{Float64} = [1.0, -1.0] end From 0f2bb5678f1b547dfc17fe639eec12a1ba28c8d4 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Thu, 5 Jun 2025 11:17:41 +0200 Subject: [PATCH 2/3] Remove LaTeXStrings import --- src/QuantumToolbox.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/QuantumToolbox.jl b/src/QuantumToolbox.jl index 915c4abe8..0944175b3 100644 --- a/src/QuantumToolbox.jl +++ b/src/QuantumToolbox.jl @@ -58,7 +58,6 @@ import Distributed: RemoteChannel import FFTW: fft, ifft, fftfreq, fftshift import Graphs: connected_components, DiGraph import IncompleteLU: ilu -import LaTeXStrings: @L_str import Pkg import Random: AbstractRNG, default_rng, seed! import SpecialFunctions: loggamma From 1da945de0a076ef0e0a6f0fd1acb459d20b11426 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Thu, 5 Jun 2025 11:25:09 +0200 Subject: [PATCH 3/3] Convert labels to latexstrings --- ext/QuantumToolboxMakieExt.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/QuantumToolboxMakieExt.jl b/ext/QuantumToolboxMakieExt.jl index c77aceff9..229acf835 100644 --- a/ext/QuantumToolboxMakieExt.jl +++ b/ext/QuantumToolboxMakieExt.jl @@ -14,7 +14,6 @@ import Makie: surface!, barplot!, GridPosition, - @L_str, Reverse, ylims!, RGBAf, @@ -28,7 +27,8 @@ import Makie: RGBf, Vec3f, Point3f, - NoShading + NoShading, + latexstring @doc raw""" plot_wigner( @@ -666,7 +666,7 @@ function _add_labels!(b::Bloch, ax) if !isempty(b.xlabel) && !isempty(b.xlabel[1]) text!( ax, - L"\textbf{x}", + latexstring(b.xlabel[1]), position = Point3f(0, -offset_scale * b.xlpos[1], 0), color = label_color, fontsize = label_size, @@ -676,7 +676,7 @@ function _add_labels!(b::Bloch, ax) if length(b.xlabel) > 1 && !isempty(b.xlabel[2]) text!( ax, - L"\textbf{-x}", + latexstring(b.xlabel[2]), position = Point3f(0, -offset_scale * b.xlpos[2], 0), color = label_color, fontsize = label_size, @@ -686,7 +686,7 @@ function _add_labels!(b::Bloch, ax) if !isempty(b.ylabel) && !isempty(b.ylabel[1]) text!( ax, - L"\textbf{y}", + latexstring(b.ylabel[1]), position = Point3f(offset_scale * b.ylpos[1], 0, 0), color = label_color, fontsize = label_size, @@ -696,7 +696,7 @@ function _add_labels!(b::Bloch, ax) if length(b.ylabel) > 1 && !isempty(b.ylabel[2]) text!( ax, - L"\textbf{-y}", + latexstring(b.ylabel[2]), position = Point3f(offset_scale * b.ylpos[2], 0, 0), color = label_color, fontsize = label_size, @@ -706,7 +706,7 @@ function _add_labels!(b::Bloch, ax) if !isempty(b.zlabel) && !isempty(b.zlabel[1]) text!( ax, - L"\mathbf{|0\rangle}", + latexstring(b.zlabel[1]), position = Point3f(0, 0, offset_scale * b.zlpos[1]), color = label_color, fontsize = label_size, @@ -716,7 +716,7 @@ function _add_labels!(b::Bloch, ax) if length(b.zlabel) > 1 && !isempty(b.zlabel[2]) text!( ax, - L"\mathbf{|1\rangle}", + latexstring(b.zlabel[2]), position = Point3f(0, 0, offset_scale * b.zlpos[2]), color = label_color, fontsize = label_size,