Skip to content

Commit 5d19a90

Browse files
updated docs (#480)
## Description This PR updates the examples in the docs based on some mistakes that were noticed. This type of PR will be done periodicially.
2 parents a0ebdf3 + 92810b0 commit 5d19a90

33 files changed

Lines changed: 930 additions & 496 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
3030

3131
### Changed
3232

33+
- added trapped-ion position-grid guide and `hamiltonians` factory section ([#476]) ([**@linusschulte**])
3334
- simplified user-facing top-level imports ([#467]) ([**@aaronleesander**])
3435
- updated documentation structure and content ([#465]) ([**@aaronleesander**])
3536
- changed analog simulation default mode to 2TDVP ([#458]) ([**@aaronleesander**])

docs/conf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"examples/strong_circuit_simulation": "examples/circuit_simulation.html",
6767
"examples/sample_observable_digital_tjm": "examples/circuit_simulation.html#mid-circuit-observables",
6868
"examples/solver_comparison": "examples/representation_comparison.html",
69+
"examples/fermi_hubbard_mpo": "examples/hamiltonians.html#fermi-hubbard-1d",
6970
}
7071

7172
source_suffix = [".rst", ".md"]
@@ -116,6 +117,18 @@
116117
("latex", "image/svg+xml", 15),
117118
]
118119
nb_execution_raise_on_error = True
120+
# Suppress noisy but harmless warnings during notebook execution (complex casts, etc.).
121+
nb_prolog = """
122+
import warnings
123+
124+
warnings.filterwarnings("ignore", message=".*cast.*complex.*")
125+
warnings.filterwarnings("ignore", message=".*Casting complex values to real.*")
126+
try:
127+
from numpy.exceptions import ComplexWarning
128+
except ImportError:
129+
from numpy import ComplexWarning
130+
warnings.filterwarnings("ignore", category=ComplexWarning)
131+
"""
119132

120133

121134
class CDAStyle(UnsrtStyle):

docs/examples/analog_simulation.md

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kernelspec:
44
name: python3
55
mystnb:
66
number_source_lines: true
7-
execution_timeout: 300
7+
execution_timeout: 600
88
---
99

1010
```{code-cell} ipython3
@@ -16,66 +16,48 @@ mystnb:
1616

1717
This guide walks through an open-system **analog** simulation with the tensor jump method (TJM): build a Hamiltonian, attach a noise model, configure {class}`~mqt.yaqs.core.data_structures.simulation_parameters.AnalogSimParams`, and visualize time-resolved observables.
1818

19-
For Gaussian (bell-curve) noise strengths and static disorder, see {doc}`realistic_noise_models`. For execution options (parallelism, progress bars), see {doc}`simulator_initialization`.
19+
For log-normal disorder on strengths and static calibration spread, see {doc}`realistic_noise_models`. For execution options (parallelism, progress bars), see {doc}`simulator_initialization`. To build Ising, Hubbard, Pauli-string, or hardware Hamiltonians, see {doc}`hamiltonians`.
2020

2121
## 1. Hamiltonian
2222

23-
Three equivalent ways to define the transverse-field Ising model $H = -J \sum_i Z_i Z_{i+1} - g \sum_i X_i$ on an open chain:
24-
2523
```{code-cell} ipython3
26-
from mqt.yaqs import Hamiltonian, MPO
27-
28-
L = 3
29-
J = 1
30-
g = 0.5
24+
from mqt.yaqs import Hamiltonian
3125
32-
# Method 1: built-in constructor
26+
L = 5
27+
J, g = 1.0, 0.8
3328
H_0 = Hamiltonian.ising(L, J, g)
34-
35-
# Method 2: generic Pauli interface
36-
H_0 = Hamiltonian.pauli(
37-
length=L,
38-
two_body=[(-J, "Z", "Z")],
39-
one_body=[(-g, "X")],
40-
bc="open",
41-
)
42-
43-
# Method 3: explicit Pauli-string MPO
44-
terms = [(-J, f"Z{i} Z{i+1}") for i in range(L - 1)] + [(-g, f"X{i}") for i in range(L)]
45-
mpo = MPO()
46-
mpo.from_pauli_sum(terms=terms, length=L)
47-
H_0 = Hamiltonian.from_mpo(mpo)
4829
```
4930

31+
See {doc}`hamiltonians` for Pauli sums, Fermi–Hubbard, Bose–Hubbard, and coupled-transmon factories.
32+
5033
## 2. Initial state and noise model
5134

35+
We prepare a Néel state $\ket{01010\ldots}$ and track staggered magnetization under a transverse-field Ising model with on-site amplitude damping. The alternating $\langle Z_i \rangle$ pattern at $t=0$ spreads and decays in a site-dependent way.
36+
5237
```{code-cell} ipython3
5338
from mqt.yaqs import NoiseModel, State
5439
55-
state = State(L, initial="zeros")
56-
# Alternative: State(L, initial="haar-random", pad=4)
40+
state = State(L, initial="Neel")
5741
58-
gamma = 0.1
42+
gamma = 0.08
5943
noise_model = NoiseModel([
60-
{"name": name, "sites": [i], "strength": gamma}
61-
for i in range(L)
62-
for name in ["lowering", "pauli_z"]
44+
{"name": "lowering", "sites": [i], "strength": gamma} for i in range(L)
6345
])
6446
```
6547

66-
Pass a float for each `strength` here. For distribution-valued strengths (Gaussian and other distributions), see {doc}`realistic_noise_models`.
48+
Pass a float for each `strength` here. For distribution-valued strengths (log-normal and other distributions), see {doc}`realistic_noise_models`.
6749

6850
## 3. Simulation parameters
6951

7052
```{code-cell} ipython3
7153
from mqt.yaqs import AnalogSimParams, Observable
7254
7355
sim_params = AnalogSimParams(
74-
observables=[Observable("x", site) for site in range(L)],
75-
elapsed_time=10,
56+
observables=[Observable("z", site) for site in range(L)],
57+
elapsed_time=6.0,
7658
dt=0.1,
77-
num_traj=100,
78-
max_bond_dim=4,
59+
num_traj=20,
60+
max_bond_dim=16,
7961
svd_threshold=1e-6,
8062
order=2,
8163
sample_timesteps=True,
@@ -91,17 +73,20 @@ Optional `tdvp_sweeps` (default `1`) runs multiple symmetric TDVP substeps per p
9173
With `num_traj > 1`, each {meth}`~mqt.yaqs.Simulator.run` call averages independent quantum-jump trajectories. Set {attr}`~mqt.yaqs.core.data_structures.simulation_parameters.AnalogSimParams.random_seed` to fix the pseudorandom stream across trajectories (and for distribution-valued noise strengths):
9274

9375
```{code-cell} ipython3
76+
---
77+
tags: [remove-output]
78+
---
9479
import copy
9580
9681
import numpy as np
9782
9883
from mqt.yaqs import AnalogSimParams, Observable, Simulator
9984
10085
repro_params = AnalogSimParams(
101-
observables=[Observable("x", site) for site in range(L)],
86+
observables=[Observable("z", site) for site in range(L)],
10287
elapsed_time=1.0,
10388
dt=0.1,
104-
num_traj=50,
89+
num_traj=16,
10590
max_bond_dim=4,
10691
svd_threshold=1e-6,
10792
order=2,
@@ -121,8 +106,6 @@ def run_reproducible() -> list[np.ndarray]:
121106
122107
first_run = run_reproducible()
123108
second_run = run_reproducible()
124-
assert all(np.allclose(a, b) for a, b in zip(first_run, second_run, strict=True))
125-
print("Both runs produced identical trajectory-averaged observables.")
126109
```
127110

128111
The same `random_seed` field exists on {class}`~mqt.yaqs.core.data_structures.simulation_parameters.StrongSimParams` and {class}`~mqt.yaqs.core.data_structures.simulation_parameters.WeakSimParams`.
@@ -147,22 +130,18 @@ import matplotlib.pyplot as plt
147130
148131
heatmap = result.expectation_values
149132
150-
fig, ax = plt.subplots(figsize=(5, 3))
151-
im = ax.imshow(heatmap, aspect="auto", extent=(0, 10, L, 0), vmin=0, vmax=0.5)
133+
fig, ax = plt.subplots(figsize=(7, 4), layout="constrained")
134+
im = ax.imshow(heatmap, aspect="auto", extent=(0, 6, L, 0), vmin=-1, vmax=1)
152135
ax.set_xlabel("Time")
153136
ax.set_yticks([x - 0.5 for x in range(1, L + 1)], [str(x) for x in range(L)])
154137
ax.set_ylabel("Site")
155-
156-
fig.subplots_adjust(top=0.95, right=0.88)
157-
cbar_ax = fig.add_axes(rect=(0.9, 0.11, 0.025, 0.8))
158-
cbar = fig.colorbar(im, cax=cbar_ax)
159-
cbar.ax.set_title(r"$\langle X \rangle$")
160-
plt.tight_layout()
138+
fig.colorbar(im, ax=ax, shrink=0.9, label=r"$\langle Z \rangle$")
161139
plt.show()
162140
```
163141

164142
## Related topics
165143

144+
- {doc}`hamiltonians` — Pauli, Hubbard, and hardware Hamiltonians
166145
- {doc}`representation_comparison` — MPS, MCWF, and Lindblad backends
167146
- {doc}`scheduled_jumps` — deterministic jumps at specified times
168147
- {doc}`ensemble_evolution` — unitary ensemble correlations

0 commit comments

Comments
 (0)