Skip to main content

StabilizerState

Struct StabilizerState 

Source
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

Source

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.

Source

pub fn new_with_seed(num_qubits: usize, seed: u64) -> Result<Self>

Create a new stabilizer state with a specific RNG seed.

Source

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).

Source

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.

Source

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

Source

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.

Source

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).

Source

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.

Source

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.

Source

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).

Source

pub fn measure(&mut self, qubit: usize) -> Result<MeasurementOutcome>

Measure qubit in the computational (Z) basis.

Follows the Aaronson-Gottesman algorithm:

  1. Check if any stabilizer generator anticommutes with Z on the measured qubit (i.e. has its X bit set for that qubit).
  2. If yes (random outcome): collapse the state and record the result.
  3. If no (deterministic outcome): compute the result from phases.
Source

pub fn num_qubits(&self) -> usize

Return the number of qubits in this stabilizer state.

Source

pub fn measurement_record(&self) -> &[MeasurementOutcome]

Return the measurement record accumulated so far.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V