use everett::{Circuit, StabilizerBackend};
fn main() {
let n = 1000;
let mut ghz = Circuit::new(n);
ghz.h(0);
for k in 0..n - 1 {
ghz.cnot(k, k + 1);
}
let exec = StabilizerBackend::run(&ghz).expect("GHZ is a Clifford circuit");
println!("{n}-qubit GHZ state prepared on the stabilizer backend.");
println!(
"stabilizer group has {} generators.",
exec.generators().len()
);
println!("first generator: {}", exec.generators()[0]);
println!("second generator: {}", exec.generators()[1]);
let mut measured = Circuit::with_classical(n, n);
measured.compose(&ghz);
for q in 0..n {
measured.measure(q, q);
}
let exec = StabilizerBackend::run_seeded(&measured, 1).expect("still Clifford");
let bits = exec.classical();
let all_same = bits.iter().all(|&b| b == bits[0]);
println!(
"measured all {n} qubits: {} (GHZ correlation holds: {all_same})",
if bits[0] { "all ones" } else { "all zeros" },
);
let mut with_t = Circuit::new(1);
with_t.t(0);
match StabilizerBackend::run(&with_t) {
Err(e) => println!("\nas expected, a T gate is refused: {e}"),
Ok(_) => unreachable!("T is not Clifford"),
}
}