//! The smallest complete thing: build a circuit, simulate it exactly, and get a //! hash that is the same on every machine. //! //! cargo run --example bell use wai_quantum::quantum::{circuit_hash, Circuit}; use wai_quantum::quantum_toolchain as qt; fn main() { // A new circuit is in the circuit2 gateset, whose phase table is correctly // rounded; `Circuit::with_gateset(2, Gateset::V1)` reproduces circuit/1. let mut c = Circuit::new(2); c.h(0).cx(0, 1); // a Bell pair let sv = c.simulate().expect("simulate"); // The circuit's identity covers its capability; a circuit that simulates // always has one. let id = circuit_hash(&c).expect("a valid circuit has a hash"); println!("circuit {} qubits, {} gates, {}", c.n_qubits, c.ops.len(), c.gateset.capability()); print!("circuit-id "); for b in id { print!("{b:02x}"); } println!(); let (backend, why) = qt::recommend_backend(&c); println!("backend {backend:?} — {why}"); println!("outcomes"); for (state, p) in qt::top_outcomes(&sv, 4) { if p > 0.0 { println!(" |{state:02b}> {p:.6}"); } } // Not "a hash of this run" — the reconstruction is byte-exact, so this is the // same value natively, in a browser, and in a WASI component at the edge. let h = sv.statevector_hash(); print!("state-hash "); for b in h { print!("{b:02x}"); } println!(); }