StabilizerTableau

Struct StabilizerTableau 

Source
pub struct StabilizerTableau { /* private fields */ }
Expand description

Stabilizer tableau representation

The tableau stores generators of the stabilizer group as rows. Each row represents a Pauli string with phase.

Phase encoding (Stim-compatible):

  • 0 = +1
  • 1 = +i
  • 2 = -1
  • 3 = -i

Implementations§

Source§

impl StabilizerTableau

Source

pub fn new(num_qubits: usize) -> Self

Create a new tableau in the |0…0⟩ state

Source

pub fn with_format(num_qubits: usize, stim_format: bool) -> Self

Create a new tableau with specified Pauli string format

§Arguments
  • num_qubits - Number of qubits
  • stim_format - Use Stim format (_ for identity) if true, standard format (I) if false
Source

pub fn set_stim_format(&mut self, stim_format: bool)

Set the Pauli string format

Source

pub const fn is_stim_format(&self) -> bool

Get the Pauli string format

Source

pub fn apply_h(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply a Hadamard gate

H: X → Z, Z → X, Y → -Y Phase tracking: HYH = -Y, so Y component contributes i^2 = -1

Source

pub fn apply_s(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply an S gate (phase gate)

S conjugation rules (SPS†):

  • S: X → Y (no phase change, Pauli relabeling)
  • S: Y → -X (phase negation due to SYS† = -X)
  • S: Z → Z (no change)

Note: The i in Y = iXZ is a matrix identity, not relevant to stabilizer conjugation. In stabilizer formalism, X, Y, Z are atomic Pauli labels.

Source

pub fn apply_cnot( &mut self, control: usize, target: usize, ) -> Result<(), QuantRS2Error>

Apply a CNOT gate

Source

pub fn apply_x(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply a Pauli X gate

X anticommutes with Z and Y, commutes with X Phase: adds -1 when Z or Y is present on the qubit

Source

pub fn apply_y(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply a Pauli Y gate

Y = iXZ, anticommutes with X and Z (separately), commutes with Y Phase: adds -1 when X XOR Z is present (pure X or pure Z, not Y)

Source

pub fn apply_z(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply a Pauli Z gate

Z anticommutes with X and Y, commutes with Z Phase: adds -1 when X or Y is present on the qubit

Source

pub fn apply_s_dag(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply S† (S-dagger) gate

S† conjugation rules (S†PS):

  • S†: X → -Y (phase becomes -1)
  • S†: Y → X (no phase change)
  • S†: Z → Z (no change)
Source

pub fn apply_sqrt_x(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply √X gate (SQRT_X, also called SX or V gate)

Conjugation rules:

  • √X: X → X (no change)
  • √X: Y → -Z (phase becomes -1)
  • √X: Z → Y (no phase change)
Source

pub fn apply_sqrt_x_dag(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply √X† gate (SQRT_X_DAG)

Conjugation rules:

  • √X†: X → X (no change)
  • √X†: Y → Z (no phase change)
  • √X†: Z → -Y (phase becomes -1)
Source

pub fn apply_sqrt_y(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply √Y gate (SQRT_Y)

Conjugation rules:

  • √Y: X → Z (no phase change)
  • √Y: Y → Y (no change)
  • √Y: Z → -X (phase becomes -1)
Source

pub fn apply_sqrt_y_dag(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Apply √Y† gate (SQRT_Y_DAG)

Conjugation rules:

  • √Y†: X → -Z (phase becomes -1)
  • √Y†: Y → Y (no change)
  • √Y†: Z → X (no phase change)
Source

pub fn apply_cz( &mut self, control: usize, target: usize, ) -> Result<(), QuantRS2Error>

Apply CZ (Controlled-Z) gate

CZ: X_c → X_c Z_t, X_t → Z_c X_t, Z_c → Z_c, Z_t → Z_t When both qubits have X component (product of X or Y), phase picks up -1

Source

pub fn apply_cy( &mut self, control: usize, target: usize, ) -> Result<(), QuantRS2Error>

Apply CY (Controlled-Y) gate

Source

pub fn apply_swap( &mut self, qubit1: usize, qubit2: usize, ) -> Result<(), QuantRS2Error>

Apply SWAP gate

Source

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

Measure a qubit in the computational (Z) basis Returns the measurement outcome (0 or 1)

For phases with imaginary components, we project onto real eigenvalues:

  • Phase 0 (+1) or 1 (+i) → eigenvalue +1 → outcome 0
  • Phase 2 (-1) or 3 (-i) → eigenvalue -1 → outcome 1
Source

pub fn measure_x(&mut self, qubit: usize) -> Result<bool, QuantRS2Error>

Measure a qubit in the X basis (Stim MX instruction)

Equivalent to: H · measure_z · H

Source

pub fn measure_y(&mut self, qubit: usize) -> Result<bool, QuantRS2Error>

Measure a qubit in the Y basis (Stim MY instruction)

Equivalent to: S† · H · measure_z · H · S

Source

pub fn reset(&mut self, qubit: usize) -> Result<(), QuantRS2Error>

Reset a qubit to |0⟩ state (Stim R instruction)

Performs measurement and applies X if outcome is |1⟩

Source

pub fn get_stabilizers(&self) -> Vec<String>

Get the current stabilizer generators as strings

Phase encoding in output:

  • + for phase 0 (+1)
  • +i for phase 1 (+i)
  • - for phase 2 (-1)
  • -i for phase 3 (-i)

Identity representation depends on stim_format:

  • Standard format: I for identity
  • Stim format: _ for identity
Source

pub fn get_destabilizers(&self) -> Vec<String>

Get the current destabilizer generators as strings

Same format as get_stabilizers() but for destabilizers

Trait Implementations§

Source§

impl Clone for StabilizerTableau

Source§

fn clone(&self) -> StabilizerTableau

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StabilizerTableau

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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