Skip to main content

Gate

Enum Gate 

Source
pub enum Gate {
Show 29 variants Id, X, Y, Z, H, S, Sdg, T, Tdg, SX, SXdg, Rx(f64), Ry(f64), Rz(f64), P(f64), Rzz(f64), Cx, Cz, Swap, Cu(Box<[[Complex64; 2]; 2]>), Mcu(Box<McuData>), Fused(Box<[[Complex64; 2]; 2]>), BatchPhase(Box<BatchPhaseData>), BatchRzz(Box<BatchRzzData>), DiagonalBatch(Box<DiagonalBatchData>), MultiFused(Box<MultiFusedData>), Fused2q(Box<[[Complex64; 4]; 4]>), Multi2q(Box<Multi2qData>), QftBlock { start: u8, num: u8, },
}
Expand description

Quantum gate identifier.

Covers the v0 supported gate set. Most variants are data-free or carry an f64 parameter inline. The Fused variant uses Box to keep the enum at 16 bytes.

Variants§

§

Id

Identity.

§

X

Pauli-X (bit flip).

§

Y

Pauli-Y.

§

Z

Pauli-Z (phase flip).

§

H

Hadamard.

§

S

S gate (√Z).

§

Sdg

S† gate.

§

T

T gate (π/8).

§

Tdg

T† gate.

§

SX

√X gate.

§

SXdg

√X† gate.

§

Rx(f64)

Rotation about X-axis by angle (radians).

§

Ry(f64)

Rotation about Y-axis by angle (radians).

§

Rz(f64)

Rotation about Z-axis by angle (radians).

§

P(f64)

Phase gate [[1,0],[0,e^{iθ}]].

§

Rzz(f64)

ZZ rotation: diag(e^{-iθ/2}, e^{iθ/2}, e^{iθ/2}, e^{-iθ/2}). Qubit order: [q0, q1] (symmetric).

§

Cx

Controlled-X (CNOT). Qubit order: [control, target].

§

Cz

Controlled-Z. Qubit order: [q0, q1] (symmetric).

§

Swap

SWAP. Qubit order: [q0, q1] (symmetric).

§

Cu(Box<[[Complex64; 2]; 2]>)

Controlled-unitary. Applies the boxed 2×2 matrix to the target qubit only when the control qubit is |1⟩. Qubit order: [control, target]. Boxed to keep Gate at 16 bytes.

§

Mcu(Box<McuData>)

Multi-controlled unitary. Applies the 2×2 matrix to the target qubit only when all control qubits are |1⟩. Qubit order: [ctrl_0, ctrl_1, ..., ctrl_{k-1}, target]. Boxed to keep Gate at 16 bytes.

§

Fused(Box<[[Complex64; 2]; 2]>)

Pre-fused single-qubit unitary (product of consecutive gates on the same target). Boxed to keep Gate at 16 bytes for cache-friendly instruction streams.

§

BatchPhase(Box<BatchPhaseData>)

Batched controlled-phase: multiple cphase gates sharing a control qubit, fused into a single pass over the statevector. Created by the cphase fusion pass. Targets: [control]. The BatchPhaseData holds per-target phases. Boxed to keep Gate at 16 bytes.

§

BatchRzz(Box<BatchRzzData>)

Batched ZZ rotations: multiple Rzz gates fused into a single pass. Created by the batch-Rzz fusion pass. The BatchRzzData holds per-edge angles. Boxed to keep Gate at 16 bytes.

§

DiagonalBatch(Box<DiagonalBatchData>)

Batched diagonal gates: a contiguous run of diagonal 1q and 2q gates collapsed into a single state-vector sweep with a precomputed phase LUT. Subsumes BatchPhase and BatchRzz for mixed diagonal runs. Created by the diagonal batch fusion pass. Boxed to keep Gate at 16 bytes.

§

MultiFused(Box<MultiFusedData>)

Multiple single-qubit gates on distinct qubits, batched for a single tiled pass over the statevector. Created by the multi-gate fusion pass. Boxed to keep Gate at 16 bytes.

§

Fused2q(Box<[[Complex64; 4]; 4]>)

Pre-fused two-qubit unitary (4×4 matrix). Created by the 2q fusion pass which absorbs adjacent single-qubit gates into a two-qubit gate. Boxed to keep Gate at 16 bytes.

§

Multi2q(Box<Multi2qData>)

Multiple two-qubit gates batched for a single tiled pass over the statevector. Created by the multi-2q fusion pass. Each entry stores (q0, q1, 4×4 matrix). Boxed to keep Gate at 16 bytes.

§

QftBlock

Quantum Fourier Transform on start..start+num.

The CPU statevector backend has a fast whole-state FFT path. Subrange blocks and non-native backends expand to textbook H, cphase, and swap gates before execution. Boxless: (u8, u8) fits within the 16-byte enum slot.

Fields

§start: u8
§num: u8

Implementations§

Source§

impl Gate

Source

pub fn num_qubits(&self) -> usize

Number of qubits this gate acts on.

Source

pub fn matrix_2x2(&self) -> [[Complex64; 2]; 2]

Returns the 2×2 unitary matrix for single-qubit gates.

§Panics

Panics if called on a multi-qubit or batch gate (Cx, Cz, Swap, Cu, Mcu, BatchPhase, MultiFused, Fused2q, Multi2q).

Source

pub fn matrix_4x4(&self) -> [[Complex64; 4]; 4]

Returns the 4×4 unitary matrix for two-qubit gates.

Matrix indices follow the convention: row/col i*2+j where i indexes targets[0] and j indexes targets[1].

§Panics

Panics on gates other than Cx, Cz, Swap, Cu, or Fused2q.

Source

pub fn name(&self) -> &'static str

Human-readable gate name (for errors, logs, and OpenQASM round-tripping).

Source

pub fn inverse(&self) -> Gate

Compute the inverse (adjoint) of this gate.

Source

pub fn matrix_power(&self, k: i64) -> Gate

Compute integer power of a single-qubit gate.

Returns the gate raised to the k-th power. Negative k inverts first. Only valid for single-qubit gates.

Source

pub fn cu(mat: [[Complex64; 2]; 2]) -> Gate

Create a single-controlled unitary gate with the given 2x2 matrix.

Source

pub fn mcu(mat: [[Complex64; 2]; 2], num_controls: u8) -> Gate

Create a multi-controlled unitary gate with num_controls control qubits.

Source

pub fn cphase(theta: f64) -> Gate

Create a controlled-phase gate CPhase(θ) = Cu([[1,0],[0,e^{iθ}]]).

Applies phase e^{iθ} to |11⟩ and identity to all other basis states.

Source

pub fn controlled_phase(&self) -> Option<Complex64>

Returns the phase if this is a controlled-phase gate (Cu/Mcu with diagonal matrix [[1,0],[0,e^{iθ}]]).

Used by backends to dispatch to optimized phase-only kernels that touch half the memory of the generic controlled-unitary kernel.

Source

pub fn is_diagonal_1q(&self) -> bool

True if this is a diagonal single-qubit gate (matrix is [[a,0],[0,b]]).

Diagonal gates commute with CX on the control qubit and with CZ on either qubit. Used by the commutation-aware reordering pass.

Source

pub fn is_self_inverse_2q(&self) -> bool

True if this is a self-inverse two-qubit gate (applying it twice = identity).

Source

pub fn preserves_sparsity(&self) -> bool

True if this gate maps computational basis states to computational basis states (with at most a phase). Such gates preserve the number of non-zero amplitudes, making the sparse backend optimal (O(1) memory for |0…0⟩).

Includes diagonal gates (Z, S, T, Rz, P, CZ) and permutation gates (X, Y, CX, SWAP). Excludes superposition-creating gates (H, Rx, Ry, SX).

Source

pub fn recognize_matrix(mat: &[[Complex64; 2]; 2]) -> Option<Gate>

Try to recognize a 2x2 unitary matrix as a named gate (up to global phase).

Used by the fusion pass to emit named gate variants instead of opaque Gate::Fused matrices, enabling downstream passes (e.g. clifford_prefix_split) to identify Clifford gates that arose from fusion (e.g. T·T → S).

Source

pub fn is_clifford(&self) -> bool

True if this gate is a Clifford gate (relevant for stabilizer backend).

Trait Implementations§

Source§

impl Clone for Gate

Source§

fn clone(&self) -> Gate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Gate

Source§

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

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

impl Display for Gate

Source§

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

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

impl PartialEq for Gate

Source§

fn eq(&self, other: &Gate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Gate

Auto Trait Implementations§

§

impl Freeze for Gate

§

impl RefUnwindSafe for Gate

§

impl Send for Gate

§

impl Sync for Gate

§

impl Unpin for Gate

§

impl UnsafeUnpin for Gate

§

impl UnwindSafe for Gate

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.
Source§

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

Source§

fn vzip(self) -> V