Skip to content

Commit 9b89dc4

Browse files
authored
Merge branch 'main' into david/stim-no-qubit
2 parents 139c2bf + b11fe88 commit 9b89dc4

12 files changed

Lines changed: 297 additions & 44 deletions

File tree

crates/ppvm-pauli-sum/benches/trotter-scaling.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ fn trotter_func<T: Config<Coeff = f64, Strategy = CoefficientThreshold>>(
2222
for _ in 0..steps {
2323
// perform trotter step
2424

25-
// truncate after each gate application to be consistent with PP.jl
25+
// truncate after each operation to be consistent with PP.jl
2626
for i in 0..n {
27-
state.rx(i, theta_x);
27+
state.pauli_error(i, noise_params);
2828
state.truncate();
2929

30-
state.pauli_error(i, noise_params);
30+
state.rx(i, theta_x);
3131
state.truncate();
3232
}
3333
for i in 0..n - 1 {
34-
state.rzz(i, i + 1, theta_zz);
34+
state.pauli_error(i + 1, noise_params);
3535
state.truncate();
3636

3737
state.pauli_error(i, noise_params);
3838
state.truncate();
3939

40-
state.pauli_error(i + 1, noise_params);
40+
state.rzz(i, i + 1, theta_zz);
4141
state.truncate();
4242
}
4343
}

crates/ppvm-pauli-sum/benches/trotter.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ fn trotter_func<
2424
for _ in 0..steps {
2525
// perform trotter step
2626

27-
// truncate after each gate application to be consistent with PP.jl
27+
// truncate after each operation to be consistent with PP.jl
2828
for i in 0..n {
29-
state.rx(i, theta_x);
29+
state.pauli_error(i, noise_params);
3030
state.truncate();
3131

32-
state.pauli_error(i, noise_params);
32+
state.rx(i, theta_x);
3333
state.truncate();
3434
}
3535
for i in 0..n - 1 {
36-
state.rzz(i, i + 1, theta_zz);
36+
state.pauli_error(i + 1, noise_params);
3737
state.truncate();
3838

3939
state.pauli_error(i, noise_params);
4040
state.truncate();
4141

42-
state.pauli_error(i + 1, noise_params);
42+
state.rzz(i, i + 1, theta_zz);
4343
state.truncate();
4444
}
4545
}

crates/ppvm-pauli-sum/examples/hash_quality.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ where
4747
let theta_x = DT * H;
4848
for _ in 0..steps {
4949
for i in 0..n {
50-
state.rx(i, theta_x);
51-
state.truncate();
5250
state.pauli_error(i, NOISE);
5351
state.truncate();
52+
state.rx(i, theta_x);
53+
state.truncate();
5454
}
5555
for i in 0..n - 1 {
56-
state.rzz(i, i + 1, theta_zz);
56+
state.pauli_error(i + 1, NOISE);
5757
state.truncate();
5858
state.pauli_error(i, NOISE);
5959
state.truncate();
60-
state.pauli_error(i + 1, NOISE);
60+
state.rzz(i, i + 1, theta_zz);
6161
state.truncate();
6262
}
6363
}

crates/ppvm-pauli-sum/examples/trotter_qubit_sweep.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ where
131131
let t0 = Instant::now();
132132
for _ in 0..p.steps {
133133
for i in 0..n {
134-
state.rx(i, p.theta_x);
135-
state.truncate();
136134
state.pauli_error(i, NOISE);
137135
state.truncate();
136+
state.rx(i, p.theta_x);
137+
state.truncate();
138138
}
139139
for i in 0..n - 1 {
140-
state.rzz(i, i + 1, p.theta_zz);
140+
state.pauli_error(i + 1, NOISE);
141141
state.truncate();
142142
state.pauli_error(i, NOISE);
143143
state.truncate();
144-
state.pauli_error(i + 1, NOISE);
144+
state.rzz(i, i + 1, p.theta_zz);
145145
state.truncate();
146146
}
147147
}

crates/ppvm-pauli-sum/examples/trotter_storage_cliff.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ macro_rules! run_tier {
7373
let t0 = Instant::now();
7474
for _ in 0..steps {
7575
for i in 0..n {
76-
state.rx(i, theta_x);
77-
state.truncate();
7876
state.pauli_error(i, NOISE);
7977
state.truncate();
78+
state.rx(i, theta_x);
79+
state.truncate();
8080
}
8181
for i in 0..n - 1 {
82-
state.rzz(i, i + 1, theta_zz);
82+
state.pauli_error(i + 1, NOISE);
8383
state.truncate();
8484
state.pauli_error(i, NOISE);
8585
state.truncate();
86-
state.pauli_error(i + 1, NOISE);
86+
state.rzz(i, i + 1, theta_zz);
8787
state.truncate();
8888
}
8989
}

crates/ppvm-pauli-sum/tests/trotter.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
//!
77
//! The benchmark itself only times `trotter_func` — it never reads the
88
//! propagated observable back, so nothing there guards the *result*. These
9-
//! tests run the same gate sequence (`rx` + `rzz` + `pauli_error`, truncating
10-
//! after every gate as the bench does) on a small chain and check:
9+
//! tests run the same noisy gate sequence as the bench (physical gate then
10+
//! noise, propagated as noise then gate in Heisenberg order, truncating after
11+
//! every operation) on a small chain and check:
1112
//!
1213
//! 1. **Math regression** — the exact (untruncated, `NoStrategy`) expectation
1314
//! value matches a frozen golden constant.
@@ -35,17 +36,17 @@ macro_rules! trotter_evolve {
3536
($state:expr) => {{
3637
for _ in 0..STEPS {
3738
for i in 0..N {
38-
$state.rx(i, THETA_X);
39-
$state.truncate();
4039
$state.pauli_error(i, NOISE);
4140
$state.truncate();
41+
$state.rx(i, THETA_X);
42+
$state.truncate();
4243
}
4344
for i in 0..N - 1 {
44-
$state.rzz(i, i + 1, THETA_ZZ);
45+
$state.pauli_error(i + 1, NOISE);
4546
$state.truncate();
4647
$state.pauli_error(i, NOISE);
4748
$state.truncate();
48-
$state.pauli_error(i + 1, NOISE);
49+
$state.rzz(i, i + 1, THETA_ZZ);
4950
$state.truncate();
5051
}
5152
}
@@ -97,10 +98,10 @@ fn trotter_result_is_stable_and_truncation_is_faithful() {
9798
let approx_val = expect_on_zero!(approx);
9899

99100
// (1) Math-regression guard: frozen golden for the exact circuit. Any
100-
// change to the gate math (a wrong sign, bit-flip, or addressing bug in
101-
// rx/rzz/pauli_error) moves this by O(1e-3) or more; the bound is far
101+
// change to the gate math (a wrong sign, bit-flip, addressing bug, or
102+
// gate/noise ordering mistake) moves this by O(1e-3) or more; the bound is far
102103
// tighter than that yet far looser than cross-platform trig last-bit noise.
103-
const GOLDEN: f64 = 2.161056303575631;
104+
const GOLDEN: f64 = 2.1610566562692544;
104105
assert!(
105106
(exact_val - GOLDEN).abs() < 1e-9,
106107
"exact Trotter expectation {exact_val} drifted from golden {GOLDEN}"

docs/notebooks/trotter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ def trotter_step(state, n, theta_x, theta_zz):
148148

149149
def noisy_trotter_step(state, n, theta_x, theta_zz):
150150
for i in range(n):
151-
state.rx(i, theta=theta_x)
152-
state.pauli_error(i, p=noise_1q)
153151
state.loss_channel(i, p_loss)
152+
state.pauli_error(i, p=noise_1q)
153+
state.rx(i, theta=theta_x)
154154

155155
for i in range(n - 1):
156-
state.rzz(i, i + 1, theta=theta_zz)
157-
state.two_qubit_pauli_error(i, i + 1, p=noise_2q)
158-
state.loss_channel(i, p_loss)
159156
state.loss_channel(i + 1, p_loss)
157+
state.loss_channel(i, p_loss)
158+
state.two_qubit_pauli_error(i, i + 1, p=noise_2q)
159+
state.rzz(i, i + 1, theta=theta_zz)
160160

161161

162162
# %% [markdown]

examples/trotter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ fn trotter(
7070

7171
// perform trotter step
7272
for i in 0..n {
73-
state.rx(i, theta_x);
7473
state.pauli_error(i, noise_params);
74+
state.rx(i, theta_x);
7575
}
7676
for i in 0..n - 1 {
77-
state.rzz(i, i + 1, theta_zz);
78-
state.pauli_error(i, noise_params);
7977
state.pauli_error(i + 1, noise_params);
78+
state.pauli_error(i, noise_params);
79+
state.rzz(i, i + 1, theta_zz);
8080
}
8181

8282
// truncate state in each iteration

ppvm-python/test/benchmarks/test_trotter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ def trotter(state):
4646
# application, to stay consistent with the Rust benchmark / PP.jl.
4747
for _ in range(steps):
4848
for i in range(N_QUBITS):
49-
state.rx(i, theta=theta_x)
5049
state.pauli_error(i, p=NOISE)
50+
state.rx(i, theta=theta_x)
5151
for i in range(N_QUBITS - 1):
52-
state.rzz(i, i + 1, theta=theta_zz)
53-
state.pauli_error(i, p=NOISE)
5452
state.pauli_error(i + 1, p=NOISE)
53+
state.pauli_error(i, p=NOISE)
54+
state.rzz(i, i + 1, theta=theta_zz)
5555

5656

5757
@pytest.mark.benchmark(group="trotter")

0 commit comments

Comments
 (0)