Skip to content

Commit 8280b91

Browse files
committed
Merge branch 'main' into compathelper/new_version/2025-05-18-01-12-40-990-02575485215
2 parents 0dbf43a + b5e8af1 commit 8280b91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1947
-100
lines changed

.github/workflows/SpellCheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
- name: Checkout Actions Repository
1111
uses: actions/checkout@v4
1212
- name: Check spelling
13-
uses: crate-ci/typos@v1.32.0
13+
uses: crate-ci/typos@v1.33.1

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)
99

10+
- Introduce `Lanczos` solver for `spectrum`. ([#476])
11+
- Add Bloch-Redfield master equation solver. ([#473])
12+
- Implement Bloch Sphere rendering and align style with qutip. ([#472], [#480], [#485], [#487], [#489])
13+
- Add `Base.copy` method for `AbstractQuantumObject`. ([#486])
14+
1015
## [v0.31.1]
1116
Release date: 2025-05-16
1217

@@ -228,3 +233,11 @@ Release date: 2024-11-13
228233
[#455]: https://github.com/qutip/QuantumToolbox.jl/issues/455
229234
[#456]: https://github.com/qutip/QuantumToolbox.jl/issues/456
230235
[#460]: https://github.com/qutip/QuantumToolbox.jl/issues/460
236+
[#472]: https://github.com/qutip/QuantumToolbox.jl/issues/472
237+
[#473]: https://github.com/qutip/QuantumToolbox.jl/issues/473
238+
[#476]: https://github.com/qutip/QuantumToolbox.jl/issues/476
239+
[#480]: https://github.com/qutip/QuantumToolbox.jl/issues/480
240+
[#485]: https://github.com/qutip/QuantumToolbox.jl/issues/485
241+
[#486]: https://github.com/qutip/QuantumToolbox.jl/issues/486
242+
[#487]: https://github.com/qutip/QuantumToolbox.jl/issues/487
243+
[#489]: https://github.com/qutip/QuantumToolbox.jl/issues/489

Project.toml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1212
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
1313
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1414
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
15+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
1516
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1617
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
1718
OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
@@ -51,9 +52,10 @@ GPUArrays = "10, 11"
5152
Graphs = "1.7"
5253
IncompleteLU = "0.2"
5354
KernelAbstractions = "0.9.2"
55+
LaTeXStrings = "1.2"
5456
LinearAlgebra = "1"
5557
LinearSolve = "2, 3"
56-
Makie = "0.20, 0.21, 0.22"
58+
Makie = "0.20, 0.21, 0.22, 0.23"
5759
OrdinaryDiffEqCore = "1"
5860
OrdinaryDiffEqTsit5 = "1"
5961
Pkg = "1"
@@ -64,11 +66,4 @@ SparseArrays = "1"
6466
SpecialFunctions = "2"
6567
StaticArraysCore = "1"
6668
StochasticDiffEq = "6"
67-
Test = "1"
6869
julia = "1.10"
69-
70-
[extras]
71-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
72-
73-
[targets]
74-
test = ["Test"]

benchmarks/correlations_and_spectrum.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function benchmark_correlations_and_spectrum!(SUITE)
1919

2020
PI_solver = PseudoInverse()
2121

22+
L_solver = Lanczos()
23+
2224
SUITE["Correlations and Spectrum"]["FFT Correlation"] =
2325
@benchmarkable _calculate_fft_spectrum($H, $t_l, $c_ops, $(a'), $a)
2426

@@ -28,5 +30,8 @@ function benchmark_correlations_and_spectrum!(SUITE)
2830
SUITE["Correlations and Spectrum"]["Spectrum"]["Pseudo Inverse"] =
2931
@benchmarkable spectrum($H, $ω_l, $c_ops, $(a'), $a, solver = $PI_solver)
3032

33+
SUITE["Correlations and Spectrum"]["Spectrum"]["Lanczos"] =
34+
@benchmarkable spectrum($H, $ω_l, $c_ops, $(a'), $a, solver = $L_solver)
35+
3136
return nothing
3237
end

docs/make.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ end
1818
DocMeta.setdocmeta!(QuantumToolbox, :DocTestSetup, doctest_setup; recursive = true)
1919

2020
# some options for `makedocs`
21-
const DRAFT = false # set `true` to disable cell evaluation
22-
const DOCTEST = true # set `false` to skip doc tests
21+
const DRAFT = get(ENV, "DRAFT", false) == "true" # `DRAFT = true` disables cell evaluation
22+
const DOCTEST = get(ENV, "DOCTEST", true) == true # `DOCTEST = false` skips doc tests
2323

2424
# generate bibliography
2525
bib = CitationBibliography(
@@ -64,6 +64,7 @@ const PAGES = [
6464
"Hierarchical Equations of Motion" => "users_guide/HEOM.md",
6565
"Solving for Steady-State Solutions" => "users_guide/steadystate.md",
6666
"Two-time correlation functions" => "users_guide/two_time_corr_func.md",
67+
"Plotting on the Bloch Sphere" => "users_guide/plotting_the_bloch_sphere.md",
6768
"QuantumToolbox Settings" => "users_guide/settings.md",
6869
"Extensions" => [
6970
"Extension for CUDA.jl" => "users_guide/extensions/cuda.md",

docs/src/resources/api.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ smesolve
208208
dfd_mesolve
209209
liouvillian
210210
liouvillian_generalized
211+
bloch_redfield_tensor
212+
brterm
213+
brmesolve
211214
```
212215

213216
### [Steady State Solvers](@id doc-API:Steady-State-Solvers)
@@ -248,6 +251,7 @@ spectrum_correlation_fft
248251
spectrum
249252
ExponentialSeries
250253
PseudoInverse
254+
Lanczos
251255
```
252256

253257
## [Entropy and Metrics](@id doc-API:Entropy-and-Metrics)
@@ -316,3 +320,17 @@ meshgrid
316320
plot_wigner
317321
plot_fock_distribution
318322
```
323+
324+
### [Bloch Sphere](@id doc-API:Bloch-Sphere)
325+
326+
```@docs
327+
Bloch
328+
plot_bloch
329+
render
330+
add_points!
331+
add_vectors!
332+
add_line!
333+
add_arc!
334+
add_states!
335+
clear!
336+
```

docs/src/resources/contributing.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ The tests are divided into several test groups, where the group names are define
3838
make GROUP=Core test
3939
```
4040

41+
### [Test Item Framework for Core tests](@id doc-Contribute:Test-Item-Framework-for-Core-tests)
42+
43+
The tests in `GROUP=Core` are provided using the [Test Item Framework](https://www.julia-vscode.org/docs/stable/userguide/testitems/), which structures the test codes into `@testitems` and makes it easier to run individually.
44+
45+
The [VS Code](https://code.visualstudio.com/) and its [Julia extension](https://www.julia-vscode.org/) provides us with options to run individual `@testitems`. It is much easier to find the specific core test that failed since the [Julia extension](https://www.julia-vscode.org/) in [VS Code](https://code.visualstudio.com/) will collect all core test failures and then display them in a structured way, directly at the place in the code where a specific core test failed. See [here](https://www.julia-vscode.org/docs/stable/userguide/testitems/) for more details.
46+
4147
## [Julia Code Format](@id doc-Contribute:Julia-Code-Format)
4248

4349
We use [`JuliaFormatter.jl`](https://github.com/domluna/JuliaFormatter.jl) to format all the source codes. The code style and extra formatting options is defined in the file `.JuliaFormatter.toml` in the repository.

docs/src/users_guide/extensions/cairomakie.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ The supported plotting functions are listed as follows:
1919
| **Plotting Function** | **Description** |
2020
|:----------------------|:----------------|
2121
| [`plot_wigner`](@ref) | [Wigner quasipropability distribution](https://en.wikipedia.org/wiki/Wigner_quasiprobability_distribution) |
22-
| [`plot_fock_distribution`](@ref) | [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution |
22+
| [`plot_fock_distribution`](@ref) | [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution |
23+
| [`plot_bloch`](@ref) | [Plotting on the Bloch Sphere](@ref doc:Plotting-on-the-Bloch-Sphere) |
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# [Plotting on the Bloch Sphere](@id doc:Plotting-on-the-Bloch-Sphere)
2+
3+
```@setup Bloch_sphere_rendering
4+
using QuantumToolbox
5+
6+
using CairoMakie
7+
CairoMakie.enable_only_mime!(MIME"image/svg+xml"())
8+
```
9+
10+
## Introduction
11+
12+
When studying the dynamics of a two-level system, it's often convenient to visualize the state of the system by plotting the state vector or density matrix on the Bloch sphere.
13+
14+
In [`QuantumToolbox`](https://qutip.org/QuantumToolbox.jl/), this can be done using the [`Bloch`](@ref) or [`plot_bloch`](@ref) methods that provide same syntax as [QuTiP](https://qutip.readthedocs.io/en/stable/guide/guide-bloch.html).
15+
16+
## Create a Bloch Sphere
17+
18+
In [`QuantumToolbox`](https://qutip.org/QuantumToolbox.jl/), creating a [`Bloch`](@ref) sphere is accomplished by calling either:
19+
20+
!!! note "Import plotting libraries"
21+
Remember to import plotting libraries first. Here, we demonstrate the functionalities with [`CairoMakie.jl`](https://docs.makie.org/stable/explanations/backends/cairomakie.html).
22+
23+
```@example Bloch_sphere_rendering
24+
b = Bloch()
25+
```
26+
27+
which will load an instance of [`Bloch`](@ref). Before getting into the details of these objects, we can simply plot the blank [`Bloch`](@ref) sphere associated with these instances via:
28+
29+
```@example Bloch_sphere_rendering
30+
fig, _ = render(b)
31+
fig
32+
```
33+
34+
See the [API documentation for Bloch sphere](@ref doc-API:Bloch-Sphere) for a full list of other available functions.
35+
36+
## Add a single data point
37+
38+
As an example, we can add a single data point via [`add_points!`](@ref):
39+
40+
```@example Bloch_sphere_rendering
41+
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)]
42+
add_points!(b, pnt)
43+
fig, _ = render(b)
44+
fig
45+
```
46+
47+
## Add a single vector
48+
49+
Add a single vector via [`add_vectors!`](@ref):
50+
51+
```@example Bloch_sphere_rendering
52+
vec = [0, 1, 0]
53+
add_vectors!(b, vec)
54+
fig, _ = render(b)
55+
fig
56+
```
57+
58+
## Add a single quantum state
59+
60+
Add another vector corresponding to the ``|0\rangle`` state:
61+
62+
```@example Bloch_sphere_rendering
63+
z0 = basis(2, 0)
64+
add_states!(b, z0)
65+
fig, _ = render(b)
66+
fig
67+
```
68+
69+
## Add multiple data
70+
71+
We can also plot multiple points, vectors, and states at the same time by passing arrays instead of individual elements via [`add_points!`](@ref), [`add_vectors!`](@ref), and [`add_states!`](@ref), respectively. Before giving an example, we can use [`clear!`](@ref) to remove the current data from our [`Bloch`](@ref) sphere instead of creating a new instance:
72+
73+
```@example Bloch_sphere_rendering
74+
clear!(b)
75+
fig, _ = render(b)
76+
fig
77+
```
78+
79+
Now on the same [`Bloch`](@ref) sphere, we can plot the three states via [`add_states!`](@ref) associated with the `x`, `y`, and `z` directions:
80+
81+
```@example Bloch_sphere_rendering
82+
x = basis(2, 0) + basis(2, 1)
83+
y = basis(2, 0) + im * basis(2, 1)
84+
z = basis(2, 0)
85+
add_states!(b, [x, y, z])
86+
fig, _ = render(b)
87+
fig
88+
```
89+
90+
!!! note "State normalization"
91+
The function [`add_states!`](@ref) will automatically normalize the given quantum state(s), while [`add_vectors!`](@ref) does not normalize the given vectors.
92+
93+
A similar method works for adding vectors:
94+
95+
```@example Bloch_sphere_rendering
96+
clear!(b)
97+
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
98+
add_vectors!(b, vecs)
99+
fig, _ = render(b)
100+
fig
101+
```
102+
103+
# Add lines and arcs
104+
105+
You can also add lines and arcs via [`add_line!`](@ref) and [`add_arc!`](@ref) respectively:
106+
107+
```@example Bloch_sphere_rendering
108+
add_line!(b, x, y)
109+
add_arc!(b, y, z)
110+
fig, _ = render(b)
111+
fig
112+
```
113+
114+
## Add multiple points
115+
116+
Adding multiple points to the [`Bloch`](@ref) sphere works slightly differently than adding multiple states or vectors. For example, lets add a set of `20` points around the equator (after calling [`clear!`](@ref)):
117+
118+
```@example Bloch_sphere_rendering
119+
clear!(b)
120+
121+
th = LinRange(0, 2π, 20)
122+
xp = cos.(th)
123+
yp = sin.(th)
124+
zp = zeros(20)
125+
pnts = [xp, yp, zp]
126+
add_points!(b, pnts)
127+
fig, lscene = render(b)
128+
fig
129+
```
130+
131+
Notice that, in contrast to states or vectors, each point remains the same color as the initial point. This is because adding multiple data points using [`add_points!`](@ref) is interpreted, by default, to correspond to a single data point (single qubit state) plotted at different times. This is very useful when visualizing the dynamics of a qubit. If we want to plot additional qubit states we can call additional [`add_points!`](@ref) function:
132+
133+
```@example Bloch_sphere_rendering
134+
xz = zeros(20)
135+
yz = sin.(th)
136+
zz = cos.(th)
137+
add_points!(b, [xz, yz, zz])
138+
fig, lscene = render(b)
139+
fig
140+
```
141+
142+
The color and shape of the data points is varied automatically by [`Bloch`](@ref). Notice how the color and point markers change for each set of data. Again, we have had to call [`add_points!`](@ref) twice because adding more than one set of multiple data points is not supported by the [`add_points!`](@ref) function.
143+
144+
What if we want to vary the color of our points. We can tell [`Bloch`](@ref) to vary the color of each point according to the colors listed in the `point_color` field (see [Configuring the Bloch sphere](@ref doc:Configuring-the-Bloch-sphere) below). Again, after [`clear!`](@ref):
145+
146+
```@example Bloch_sphere_rendering
147+
clear!(b)
148+
149+
xp = cos.(th)
150+
yp = sin.(th)
151+
zp = zeros(20)
152+
pnts = [xp, yp, zp]
153+
add_points!(b, pnts, meth=:m) # add `meth=:m` to signify 'multi' colored points
154+
fig, lscene = render(b)
155+
fig
156+
```
157+
158+
Now, the data points cycle through a variety of predefined colors. Now lets add another set of points, but this time we want the set to be a single color, representing say a qubit going from the ``|0\rangle`` state to the ``|1\rangle`` state in the `y-z` plane:
159+
160+
```@example Bloch_sphere_rendering
161+
pnts = [xz, yz, zz]
162+
add_points!(b, pnts) # no `meth=:m`
163+
fig, lscene = render(b)
164+
fig
165+
```
166+
167+
## [Configuring the Bloch sphere](@id doc:Configuring-the-Bloch-sphere)
168+
169+
At the end of the last section we saw that the colors and marker shapes of the data plotted on the Bloch sphere are automatically varied according to the number of points and vectors added. But what if you want a different choice of color, or you want your sphere to be purple with different axes labels? Well then you are in luck as the [`Bloch`](@ref) structure has many fields which one can control. Assuming `b = Bloch()`:
170+
171+
### Data storage
172+
173+
| **Field** | **Description** | **Default setting** |
174+
|:----------|:----------------|:--------------------|
175+
| `b.points` | Points to plot on the Bloch sphere (3D coordinates) | `Vector{Matrix{Float64}}()` (empty) |
176+
| `b.vectors` | Vectors to plot on the Bloch sphere | `Vector{Vector{Float64}}()` (empty) |
177+
| `b.lines` | Lines to draw on the sphere with each line given as `([start_pt, end_pt], line_format)` | `Vector{Tuple{Vector{Vector{Float64}},String}}()` (empty) |
178+
| `b.arcs` | Arcs to draw on the sphere | `Vector{Vector{Vector{Float64}}}()` (empty) |
179+
180+
### Properties
181+
182+
| **Field** | **Description** | **Default setting** |
183+
|:----------|:----------------|:--------------------|
184+
| `b.font_color` | Color of axis labels and text | `"black"` |
185+
| `b.font_size` | Font size for labels | `20` |
186+
| `b.frame_alpha` | Transparency of the wire frame | `0.2` |
187+
| `b.frame_color` | Color of the wire frame | `"gray"` |
188+
| `b.frame_width` | Width of wire frame | `1.0` |
189+
| `b.point_default_color` | Default color cycle for points | `["blue", "red", "green", "#CC6600"]` |
190+
| `b.point_color` | List of colors for Bloch point markers to cycle through | `Union{Nothing,String}[]` |
191+
| `b.point_marker` | List of point marker shapes to cycle through | `[:circle, :rect, :diamond, :utriangle]` |
192+
| `b.point_size` | List of point marker sizes (not all markers look the same size when plotted) | `[5.5, 6.2, 6.5, 7.5]` |
193+
| `b.point_style` | List of marker styles | `Symbol[]` |
194+
| `b.point_alpha` | List of marker transparencies | `Float64[]` |
195+
| `b.sphere_color` | Color of Bloch sphere surface | `0.2` |
196+
| `b.sphere_alpha` | Transparency of sphere surface | `"#FFDDDD"` |
197+
| `b.vector_color` | Colors for vectors | `["green", "#CC6600", "blue", "red"]` |
198+
| `b.vector_width` | Width of vectors | `0.025` |
199+
| `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]` |
200+
| `b.view` | Azimuthal and elevation viewing angles in degrees | `[30, 30]` |
201+
| `b.xlabel` | Labels for x-axis | `[L"x", ""]` (``+x`` and ``-x``) |
202+
| `b.xlpos` | Positions of x-axis labels | `[1.2, -1.2]` |
203+
| `b.ylabel` | Labels for y-axis | `[L"y", ""]` (``+y`` and ``-y``) |
204+
| `b.ylpos` | Positions of y-axis labels | `[1.2, -1.2]` |
205+
| `b.zlabel` | Labels for z-axis | `[L"\|0\rangle", L"\|1\rangle]"` (``+z`` and ``-z``) |
206+
| `b.zlpos` | Positions of z-axis labels | `[1.2, -1.2]` |
207+
208+
These properties can also be accessed via the `print` command:
209+
210+
```@example Bloch_sphere_rendering
211+
b = Bloch()
212+
print(b)
213+
```

0 commit comments

Comments
 (0)