CliffordCircuit

Struct CliffordCircuit 

Source
pub struct CliffordCircuit {
    pub num_qubits: usize,
    pub gates: Vec<CliffordGate>,
}
Expand description

A struct representing a Clifford circuit composed of Clifford gates. CliffordCircuit only stores the sequence of gates and does not calculate the resulting stabilizer state.

§Example usage:

use stabilizer_ch_form_rust::circuit::CliffordCircuit;
use stabilizer_ch_form_rust::circuit::CliffordGate::{ H, CX };

let mut circuit = CliffordCircuit::new(2);
circuit.apply_h(0);
circuit.apply_cx(0, 1);

assert_eq!(circuit.gates[0], H(0));
assert_eq!(circuit.gates[1], CX(0, 1));

// `CliffordCircuit` is intended to be converted to `StabilizerCHForm` for simulation
use stabilizer_ch_form_rust::StabilizerCHForm;
let ch_form = StabilizerCHForm::from_clifford_circuit(&circuit).unwrap();

Fields§

§num_qubits: usize§gates: Vec<CliffordGate>

Implementations§

Source§

impl CliffordCircuit

Source

pub fn new(num_qubits: usize) -> Self

Creates a new Clifford circuit with the specified number of qubits.

§Arguments
  • num_qubits - The number of qubits in the circuit.
Source

pub fn tensor(&self, other: &CliffordCircuit) -> Self

creates a new Clifford circuit by taking the tensor product of this circuit and another. Gates from self are applied to the first self.num_qubits qubits, and gates from other are applied to the next other.num_qubits qubits.

§Arguments
  • other - The other Clifford circuit to tensor with.
§Returns

A new CliffordCircuit representing the tensor product.

Source

pub fn append(&mut self, other: &CliffordCircuit)

Appends the gates from another CliffordCircuit to this one.

§Arguments
  • other - The other Clifford circuit whose gates are to be appended.
Source

pub fn add_gate(&mut self, gate: CliffordGate)

Adds a Clifford gate to the circuit.

§Arguments
  • gate - The Clifford gate to add.
Source

pub fn add_gates(&mut self, gates: Vec<CliffordGate>)

Adds multiple Clifford gates to the circuit.

§Arguments
  • gates - A vector of Clifford gates to add.
Source

pub fn apply_h(&mut self, qarg: usize)

Applies a Hadamard gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_x(&mut self, qarg: usize)

Applies a Pauli-X gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_y(&mut self, qarg: usize)

Applies a Pauli-Y gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_z(&mut self, qarg: usize)

Applies a Pauli-Z gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_s(&mut self, qarg: usize)

Applies a Phase (S) gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_sdg(&mut self, qarg: usize)

Applies a conjugate Phase (Sdg) gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_sqrt_x(&mut self, qarg: usize)

Applies a square root of X (SqrtX) gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_sqrt_xdg(&mut self, qarg: usize)

Applies a conjugate square root of X (SqrtXdg) gate to the specified qubit.

§Arguments
  • qarg - The index of the qubit to apply the gate to.
Source

pub fn apply_cx(&mut self, control: usize, target: usize)

Applies a controlled-X (CX) gate between the specified control and target qubits.

§Arguments
  • control - The index of the control qubit.
  • target - The index of the target qubit.
Source

pub fn apply_cz(&mut self, qarg1: usize, qarg2: usize)

Applies a controlled-Z (CZ) gate between the specified qubits.

§Arguments
  • qarg1 - The index of the first qubit.
  • qarg2 - The index of the second qubit.
Source

pub fn apply_swap(&mut self, qarg1: usize, qarg2: usize)

Applies a SWAP gate between the specified qubits.

§Arguments
  • qarg1 - The index of the first qubit.
  • qarg2 - The index of the second qubit.
Source

pub fn from_qasm_file(path: &str) -> Result<Self>

Parses an OpenQASM 2.0 file into a CliffordCircuit.

§Arguments
  • path - A path to the QASM file.
§Returns

A Result containing the parsed CliffordCircuit or an Error.

Source

pub fn from_qasm_str(qasm_str: &str) -> Result<Self>

Parses an OpenQASM 2.0 string into a CliffordCircuit.

§Arguments
  • qasm_str - A string slice containing the OpenQASM 2.0 circuit description.
§Returns

A Result containing the parsed CliffordCircuit or an Error.

Source

pub fn to_qasm_str(&self, reg_name: &str) -> String

Converts the circuit to an OpenQASM 2.0 string.

§Arguments
  • reg_name - The name of the quantum register (e.g., “q”).
§Returns

A String containing the OpenQASM 2.0 representation of the circuit.

Source

pub fn to_qasm_file(&self, path: &str, reg_name: &str) -> Result<()>

Writes the circuit to an OpenQASM 2.0 file.

§Arguments
  • path - The path to the output file.
  • reg_name - The name of the quantum register (e.g., “q”).
§Returns

A Result indicating success or failure.

Source

pub fn random_clifford(num_qubits: usize, seed: Option<[u8; 32]>) -> Self

Generates a uniformly random n-qubit Clifford circuit.

This function implements the O(n^2) algorithm described in the paper to sample a Clifford operator uniformly at random from the n-qubit Clifford group. The resulting circuit is structured according to the canonical form U = F1 * H * S * F2. See the reference for details.

§Arguments
  • n - The number of qubits. Must be greater than 0.
  • seed - An optional seed for the random number generator to ensure reproducibility. If None, a seed will be generated from system entropy.
§Returns

A CliffordCircuit object representing the random Clifford operator.

§Reference

Trait Implementations§

Source§

impl Clone for CliffordCircuit

Source§

fn clone(&self) -> CliffordCircuit

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 CliffordCircuit

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for CliffordCircuit

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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

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

§

fn vzip(self) -> V