Sweep a fixed set of random Clifford circuits¶
clinr.circuits.random_clifford() draws uniformly random Cliffords, but Stim’s sampler behind it takes no seed.
This guide draws a set once, saves it, and runs both implementations over it.
Draw and save the circuits¶
from clinr import circuits
n = 3
circuits.save_circuits(circuits.random_cliffords(n, 5), "cliffords.json")
Load them¶
Later runs load the same circuits instead of drawing new ones:
cliffords = circuits.load_circuits("cliffords.json")
For circuits reproducible from a seed instead, use clinr.circuits.random_gate_sequence(), which takes a NumPy generator.
Run both implementations over the set¶
clinr.estimators.sweep_direct() and clinr.estimators.sweep_clinr() return one estimate per circuit, in order:
import numpy as np
from clinr import estimators, noise_models
noise = noise_models.asymmetric_noise(1e-3)
rng = np.random.default_rng(7)
direct = estimators.sweep_direct(cliffords, n, noise, 20_000, rng)
clinr = estimators.sweep_clinr(cliffords, n, 1, 4, noise, 20_000, rng)
for index, (plain, protected) in enumerate(zip(direct, clinr)):
print(f"circuit {index}: {protected.s1 + protected.s2} gates, "
f"direct {plain.p_log:.4f}, CliNR {protected.p_log:.4f}")
circuit 0: 31 gates, direct 0.0127, CliNR 0.0086
circuit 1: 18 gates, direct 0.0046, CliNR 0.0066
circuit 2: 19 gates, direct 0.0078, CliNR 0.0074
circuit 3: 22 gates, direct 0.0118, CliNR 0.0069
circuit 4: 18 gates, direct 0.0063, CliNR 0.0066