pub struct StabilizerState { /* private fields */ }Expand description
Stabilizer state for efficient Clifford circuit simulation.
Uses the Aaronson-Gottesman tableau representation to simulate Clifford circuits in O(n^2) time per gate, enabling simulation of millions of qubits.
Implementations§
Source§impl StabilizerState
impl StabilizerState
Sourcepub fn new(num_qubits: usize) -> Result<Self>
pub fn new(num_qubits: usize) -> Result<Self>
Create a new stabilizer state representing |00…0>.
The initial tableau has destabilizer i = X_i, stabilizer i = Z_i, and all phase bits set to 0.
Sourcepub fn new_with_seed(num_qubits: usize, seed: u64) -> Result<Self>
pub fn new_with_seed(num_qubits: usize, seed: u64) -> Result<Self>
Create a new stabilizer state with a specific RNG seed.
Sourcepub fn hadamard(&mut self, qubit: usize)
pub fn hadamard(&mut self, qubit: usize)
Apply a Hadamard gate on qubit.
Conjugation rules: H X H = Z, H Z H = X, H Y H = -Y. Tableau update: swap X and Z columns for this qubit in every row, and flip the phase bit where both X and Z were set (Y -> -Y).
Sourcepub fn phase_gate(&mut self, qubit: usize)
pub fn phase_gate(&mut self, qubit: usize)
Apply the phase gate (S gate) on qubit.
Conjugation rules: S X S^dag = Y, S Z S^dag = Z, S Y S^dag = -X. Tableau update: Z_j -> Z_j XOR X_j, phase flipped where X and Z are both set.
Sourcepub fn cnot(&mut self, control: usize, target: usize)
pub fn cnot(&mut self, control: usize, target: usize)
Apply a CNOT gate with control and target.
Conjugation rules: X_c -> X_c X_t, Z_t -> Z_c Z_t, X_t -> X_t, Z_c -> Z_c. Tableau update for every row: phase ^= x_c AND z_t AND (x_t XOR z_c XOR 1) x_t ^= x_c z_c ^= z_t
Sourcepub fn x_gate(&mut self, qubit: usize)
pub fn x_gate(&mut self, qubit: usize)
Apply a Pauli-X gate on qubit.
Conjugation: X commutes with X, anticommutes with Z and Y. Tableau update: flip phase where Z bit is set for this qubit.
Sourcepub fn y_gate(&mut self, qubit: usize)
pub fn y_gate(&mut self, qubit: usize)
Apply a Pauli-Y gate on qubit.
Conjugation: Y anticommutes with both X and Z. Tableau update: flip phase where X or Z (but via XOR: where x XOR z).
Sourcepub fn z_gate(&mut self, qubit: usize)
pub fn z_gate(&mut self, qubit: usize)
Apply a Pauli-Z gate on qubit.
Conjugation: Z commutes with Z, anticommutes with X and Y. Tableau update: flip phase where X bit is set for this qubit.
Sourcepub fn cz(&mut self, q1: usize, q2: usize)
pub fn cz(&mut self, q1: usize, q2: usize)
Apply a CZ (controlled-Z) gate on q1 and q2.
CZ = (I x H) . CNOT . (I x H). Implemented by decomposition.
Sourcepub fn swap(&mut self, q1: usize, q2: usize)
pub fn swap(&mut self, q1: usize, q2: usize)
Apply a SWAP gate on q1 and q2.
SWAP = CNOT(q1,q2) . CNOT(q2,q1) . CNOT(q1,q2).
Sourcepub fn measure(&mut self, qubit: usize) -> Result<MeasurementOutcome>
pub fn measure(&mut self, qubit: usize) -> Result<MeasurementOutcome>
Measure qubit in the computational (Z) basis.
Follows the Aaronson-Gottesman algorithm:
- Check if any stabilizer generator anticommutes with Z on the measured qubit (i.e. has its X bit set for that qubit).
- If yes (random outcome): collapse the state and record the result.
- If no (deterministic outcome): compute the result from phases.
Sourcepub fn num_qubits(&self) -> usize
pub fn num_qubits(&self) -> usize
Return the number of qubits in this stabilizer state.
Sourcepub fn measurement_record(&self) -> &[MeasurementOutcome]
pub fn measurement_record(&self) -> &[MeasurementOutcome]
Return the measurement record accumulated so far.
Sourcepub fn clone_with_seed(&self, seed: u64) -> Result<Self>
pub fn clone_with_seed(&self, seed: u64) -> Result<Self>
Create a copy of this stabilizer state with a new RNG seed.
The quantum state (tableau) is duplicated exactly; only the RNG and measurement record are reset. This is used by the Clifford+T backend to fork stabilizer terms during T-gate decomposition.
Sourcepub fn is_clifford_gate(gate: &Gate) -> bool
pub fn is_clifford_gate(gate: &Gate) -> bool
Check whether a gate is a Clifford gate (simulable by this backend).
Clifford gates are: H, X, Y, Z, S, Sdg, CNOT, CZ, SWAP. Measure and Reset are also supported (non-unitary but handled). T, Tdg, Rx, Ry, Rz, Phase, Rzz, and custom unitaries are NOT Clifford in general.
Sourcepub fn apply_gate(&mut self, gate: &Gate) -> Result<Vec<MeasurementOutcome>>
pub fn apply_gate(&mut self, gate: &Gate) -> Result<Vec<MeasurementOutcome>>
Apply a gate from the Gate enum, returning measurement outcomes if any.
Returns an error for non-Clifford gates.