You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/examples/analog_simulation.md
+26-47Lines changed: 26 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ kernelspec:
4
4
name: python3
5
5
mystnb:
6
6
number_source_lines: true
7
-
execution_timeout: 300
7
+
execution_timeout: 600
8
8
---
9
9
10
10
```{code-cell} ipython3
@@ -16,66 +16,48 @@ mystnb:
16
16
17
17
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.
18
18
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`.
20
20
21
21
## 1. Hamiltonian
22
22
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
-
25
23
```{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
31
25
32
-
# Method 1: built-in constructor
26
+
L = 5
27
+
J, g = 1.0, 0.8
33
28
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)
48
29
```
49
30
31
+
See {doc}`hamiltonians` for Pauli sums, Fermi–Hubbard, Bose–Hubbard, and coupled-transmon factories.
32
+
50
33
## 2. Initial state and noise model
51
34
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.
{"name": "lowering", "sites": [i], "strength": gamma} for i in range(L)
63
45
])
64
46
```
65
47
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`.
67
49
68
50
## 3. Simulation parameters
69
51
70
52
```{code-cell} ipython3
71
53
from mqt.yaqs import AnalogSimParams, Observable
72
54
73
55
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,
76
58
dt=0.1,
77
-
num_traj=100,
78
-
max_bond_dim=4,
59
+
num_traj=20,
60
+
max_bond_dim=16,
79
61
svd_threshold=1e-6,
80
62
order=2,
81
63
sample_timesteps=True,
@@ -91,17 +73,20 @@ Optional `tdvp_sweeps` (default `1`) runs multiple symmetric TDVP substeps per p
91
73
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):
92
74
93
75
```{code-cell} ipython3
76
+
---
77
+
tags: [remove-output]
78
+
---
94
79
import copy
95
80
96
81
import numpy as np
97
82
98
83
from mqt.yaqs import AnalogSimParams, Observable, Simulator
99
84
100
85
repro_params = AnalogSimParams(
101
-
observables=[Observable("x", site) for site in range(L)],
86
+
observables=[Observable("z", site) for site in range(L)],
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.")
126
109
```
127
110
128
111
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
147
130
148
131
heatmap = result.expectation_values
149
132
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)
0 commit comments