Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/ppvm-pauli-sum/benches/trotter-scaling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ fn trotter_func<T: Config<Coeff = f64, Strategy = CoefficientThreshold>>(
for _ in 0..steps {
// perform trotter step

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

state.pauli_error(i, noise_params);
state.rx(i, theta_x);
state.truncate();
}
for i in 0..n - 1 {
state.rzz(i, i + 1, theta_zz);
state.pauli_error(i + 1, noise_params);
state.truncate();

state.pauli_error(i, noise_params);
state.truncate();

state.pauli_error(i + 1, noise_params);
state.rzz(i, i + 1, theta_zz);
state.truncate();
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/ppvm-pauli-sum/benches/trotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ fn trotter_func<
for _ in 0..steps {
// perform trotter step

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

state.pauli_error(i, noise_params);
state.rx(i, theta_x);
state.truncate();
}
for i in 0..n - 1 {
state.rzz(i, i + 1, theta_zz);
state.pauli_error(i + 1, noise_params);
state.truncate();

state.pauli_error(i, noise_params);
state.truncate();

state.pauli_error(i + 1, noise_params);
state.rzz(i, i + 1, theta_zz);
state.truncate();
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ppvm-pauli-sum/examples/hash_quality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ where
let theta_x = DT * H;
for _ in 0..steps {
for i in 0..n {
state.rx(i, theta_x);
state.truncate();
state.pauli_error(i, NOISE);
state.truncate();
state.rx(i, theta_x);
state.truncate();
}
for i in 0..n - 1 {
state.rzz(i, i + 1, theta_zz);
state.pauli_error(i + 1, NOISE);
state.truncate();
state.pauli_error(i, NOISE);
state.truncate();
state.pauli_error(i + 1, NOISE);
state.rzz(i, i + 1, theta_zz);
state.truncate();
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ppvm-pauli-sum/examples/trotter_qubit_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ where
let t0 = Instant::now();
for _ in 0..p.steps {
for i in 0..n {
state.rx(i, p.theta_x);
state.truncate();
state.pauli_error(i, NOISE);
state.truncate();
state.rx(i, p.theta_x);
state.truncate();
}
for i in 0..n - 1 {
state.rzz(i, i + 1, p.theta_zz);
state.pauli_error(i + 1, NOISE);
state.truncate();
state.pauli_error(i, NOISE);
state.truncate();
state.pauli_error(i + 1, NOISE);
state.rzz(i, i + 1, p.theta_zz);
state.truncate();
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ppvm-pauli-sum/examples/trotter_storage_cliff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ macro_rules! run_tier {
let t0 = Instant::now();
for _ in 0..steps {
for i in 0..n {
state.rx(i, theta_x);
state.truncate();
state.pauli_error(i, NOISE);
state.truncate();
state.rx(i, theta_x);
state.truncate();
}
for i in 0..n - 1 {
state.rzz(i, i + 1, theta_zz);
state.pauli_error(i + 1, NOISE);
state.truncate();
state.pauli_error(i, NOISE);
state.truncate();
state.pauli_error(i + 1, NOISE);
state.rzz(i, i + 1, theta_zz);
state.truncate();
}
}
Expand Down
19 changes: 10 additions & 9 deletions crates/ppvm-pauli-sum/tests/trotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
//!
//! The benchmark itself only times `trotter_func` — it never reads the
//! propagated observable back, so nothing there guards the *result*. These
//! tests run the same gate sequence (`rx` + `rzz` + `pauli_error`, truncating
//! after every gate as the bench does) on a small chain and check:
//! tests run the same noisy gate sequence as the bench (physical gate then
//! noise, propagated as noise then gate in Heisenberg order, truncating after
//! every operation) on a small chain and check:
//!
//! 1. **Math regression** — the exact (untruncated, `NoStrategy`) expectation
//! value matches a frozen golden constant.
Expand Down Expand Up @@ -35,17 +36,17 @@ macro_rules! trotter_evolve {
($state:expr) => {{
for _ in 0..STEPS {
for i in 0..N {
$state.rx(i, THETA_X);
$state.truncate();
$state.pauli_error(i, NOISE);
$state.truncate();
$state.rx(i, THETA_X);
$state.truncate();
}
for i in 0..N - 1 {
$state.rzz(i, i + 1, THETA_ZZ);
$state.pauli_error(i + 1, NOISE);
$state.truncate();
$state.pauli_error(i, NOISE);
$state.truncate();
$state.pauli_error(i + 1, NOISE);
$state.rzz(i, i + 1, THETA_ZZ);
$state.truncate();
}
}
Expand Down Expand Up @@ -97,10 +98,10 @@ fn trotter_result_is_stable_and_truncation_is_faithful() {
let approx_val = expect_on_zero!(approx);

// (1) Math-regression guard: frozen golden for the exact circuit. Any
// change to the gate math (a wrong sign, bit-flip, or addressing bug in
// rx/rzz/pauli_error) moves this by O(1e-3) or more; the bound is far
// change to the gate math (a wrong sign, bit-flip, addressing bug, or
// gate/noise ordering mistake) moves this by O(1e-3) or more; the bound is far
// tighter than that yet far looser than cross-platform trig last-bit noise.
const GOLDEN: f64 = 2.161056303575631;
const GOLDEN: f64 = 2.1610566562692544;
assert!(
(exact_val - GOLDEN).abs() < 1e-9,
"exact Trotter expectation {exact_val} drifted from golden {GOLDEN}"
Expand Down
10 changes: 5 additions & 5 deletions docs/notebooks/trotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ def trotter_step(state, n, theta_x, theta_zz):

def noisy_trotter_step(state, n, theta_x, theta_zz):
for i in range(n):
state.rx(i, theta=theta_x)
state.pauli_error(i, p=noise_1q)
state.loss_channel(i, p_loss)
state.pauli_error(i, p=noise_1q)
state.rx(i, theta=theta_x)

for i in range(n - 1):
state.rzz(i, i + 1, theta=theta_zz)
state.two_qubit_pauli_error(i, i + 1, p=noise_2q)
state.loss_channel(i, p_loss)
state.loss_channel(i + 1, p_loss)
state.loss_channel(i, p_loss)
state.two_qubit_pauli_error(i, i + 1, p=noise_2q)
state.rzz(i, i + 1, theta=theta_zz)


# %% [markdown]
Expand Down
6 changes: 3 additions & 3 deletions examples/trotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ fn trotter(

// perform trotter step
for i in 0..n {
state.rx(i, theta_x);
state.pauli_error(i, noise_params);
state.rx(i, theta_x);
}
for i in 0..n - 1 {
state.rzz(i, i + 1, theta_zz);
state.pauli_error(i, noise_params);
state.pauli_error(i + 1, noise_params);
state.pauli_error(i, noise_params);
state.rzz(i, i + 1, theta_zz);
}

// truncate state in each iteration
Expand Down
6 changes: 3 additions & 3 deletions ppvm-python/test/benchmarks/test_trotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def trotter(state):
# application, to stay consistent with the Rust benchmark / PP.jl.
for _ in range(steps):
for i in range(N_QUBITS):
state.rx(i, theta=theta_x)
state.pauli_error(i, p=NOISE)
state.rx(i, theta=theta_x)
for i in range(N_QUBITS - 1):
state.rzz(i, i + 1, theta=theta_zz)
state.pauli_error(i, p=NOISE)
state.pauli_error(i + 1, p=NOISE)
state.pauli_error(i, p=NOISE)
state.rzz(i, i + 1, theta=theta_zz)


@pytest.mark.benchmark(group="trotter")
Expand Down
Loading
Loading