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
impl CliffordCircuit
Sourcepub fn new(num_qubits: usize) -> Self
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.
Sourcepub fn tensor(&self, other: &CliffordCircuit) -> Self
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.
Sourcepub fn append(&mut self, other: &CliffordCircuit)
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.
Sourcepub fn add_gate(&mut self, gate: CliffordGate)
pub fn add_gate(&mut self, gate: CliffordGate)
Sourcepub fn add_gates(&mut self, gates: Vec<CliffordGate>)
pub fn add_gates(&mut self, gates: Vec<CliffordGate>)
Sourcepub fn apply_h(&mut self, qarg: usize)
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.
Sourcepub fn apply_x(&mut self, qarg: usize)
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.
Sourcepub fn apply_y(&mut self, qarg: usize)
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.
Sourcepub fn apply_z(&mut self, qarg: usize)
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.
Sourcepub fn apply_s(&mut self, qarg: usize)
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.
Sourcepub fn apply_sdg(&mut self, qarg: usize)
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.
Sourcepub fn apply_sqrt_x(&mut self, qarg: usize)
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.
Sourcepub fn apply_sqrt_xdg(&mut self, qarg: usize)
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.
Sourcepub fn apply_cx(&mut self, control: usize, target: usize)
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.
Sourcepub fn apply_cz(&mut self, qarg1: usize, qarg2: usize)
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.
Sourcepub fn apply_swap(&mut self, qarg1: usize, qarg2: usize)
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.
Sourcepub fn from_qasm_file(path: &str) -> Result<Self>
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.
Sourcepub fn from_qasm_str(qasm_str: &str) -> Result<Self>
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.
Sourcepub fn to_qasm_str(&self, reg_name: &str) -> String
pub fn to_qasm_str(&self, reg_name: &str) -> String
Sourcepub fn random_clifford(num_qubits: usize, seed: Option<[u8; 32]>) -> Self
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. IfNone, a seed will be generated from system entropy.
§Returns
A CliffordCircuit object representing the random Clifford operator.
§Reference
- S. Bravyi and D. Maslov, “Hadamard-free circuits expose the structure of the Clifford group,” IEEE Trans. Inf. Theory 67, 5800 (2021). https://doi.org/10.1109/TIT.2021.3081415
Trait Implementations§
Source§impl Clone for CliffordCircuit
impl Clone for CliffordCircuit
Source§fn clone(&self) -> CliffordCircuit
fn clone(&self) -> CliffordCircuit
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more