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
impl StabilizerTableau
Sourcepub fn with_format(num_qubits: usize, stim_format: bool) -> Self
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 qubitsstim_format- Use Stim format (_for identity) if true, standard format (I) if false
Sourcepub fn set_stim_format(&mut self, stim_format: bool)
pub fn set_stim_format(&mut self, stim_format: bool)
Set the Pauli string format
Sourcepub const fn is_stim_format(&self) -> bool
pub const fn is_stim_format(&self) -> bool
Get the Pauli string format
Sourcepub fn apply_h(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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
Sourcepub fn apply_s(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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.
Sourcepub fn apply_cnot(
&mut self,
control: usize,
target: usize,
) -> Result<(), QuantRS2Error>
pub fn apply_cnot( &mut self, control: usize, target: usize, ) -> Result<(), QuantRS2Error>
Apply a CNOT gate
Sourcepub fn apply_x(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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
Sourcepub fn apply_y(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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)
Sourcepub fn apply_z(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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
Sourcepub fn apply_s_dag(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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)
Sourcepub fn apply_sqrt_x(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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)
Sourcepub fn apply_sqrt_x_dag(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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)
Sourcepub fn apply_sqrt_y(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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)
Sourcepub fn apply_sqrt_y_dag(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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)
Sourcepub fn apply_cz(
&mut self,
control: usize,
target: usize,
) -> Result<(), QuantRS2Error>
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
Sourcepub fn apply_cy(
&mut self,
control: usize,
target: usize,
) -> Result<(), QuantRS2Error>
pub fn apply_cy( &mut self, control: usize, target: usize, ) -> Result<(), QuantRS2Error>
Apply CY (Controlled-Y) gate
Sourcepub fn apply_swap(
&mut self,
qubit1: usize,
qubit2: usize,
) -> Result<(), QuantRS2Error>
pub fn apply_swap( &mut self, qubit1: usize, qubit2: usize, ) -> Result<(), QuantRS2Error>
Apply SWAP gate
Sourcepub fn measure(&mut self, qubit: usize) -> Result<bool, QuantRS2Error>
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
Sourcepub fn measure_x(&mut self, qubit: usize) -> Result<bool, QuantRS2Error>
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
Sourcepub fn measure_y(&mut self, qubit: usize) -> Result<bool, QuantRS2Error>
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
Sourcepub fn reset(&mut self, qubit: usize) -> Result<(), QuantRS2Error>
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⟩
Sourcepub fn get_stabilizers(&self) -> Vec<String>
pub fn get_stabilizers(&self) -> Vec<String>
Get the current stabilizer generators as strings
Phase encoding in output:
+for phase 0 (+1)+ifor phase 1 (+i)-for phase 2 (-1)-ifor phase 3 (-i)
Identity representation depends on stim_format:
- Standard format:
Ifor identity - Stim format:
_for identity
Sourcepub fn get_destabilizers(&self) -> Vec<String>
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
impl Clone for StabilizerTableau
Source§fn clone(&self) -> StabilizerTableau
fn clone(&self) -> StabilizerTableau
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for StabilizerTableau
impl RefUnwindSafe for StabilizerTableau
impl Send for StabilizerTableau
impl Sync for StabilizerTableau
impl Unpin for StabilizerTableau
impl UnwindSafe for StabilizerTableau
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.