pub enum Instruction {
Standard(StandardGate),
McGate(Box<MCGate>),
UnitaryGate(Box<UnitaryGate>),
CircuitGate(Box<CircuitGate>),
Directive(Directive),
ClassicalData(ClassicalDataOp),
ClassicalControl(ClassicalControlOp),
Delay,
}Expand description
A unified representation of any operation in a quantum circuit.
This enum acts as a sum type for all possible instructions.
- Prefer
Instruction::Standardfor common gates to leverage simulator optimizations. - Use
Instruction::McGatefor generalized controls over standard gates. - Use
Instruction::UnitaryGateorInstruction::CircuitGatefor custom unitary behavior. - Use
Instruction::Directivefor non-reversible actions such as measurement and reset. - Use
Instruction::ClassicalControlfor expression-based dynamic control flow.
Variants§
Standard(StandardGate)
A standard, natively supported quantum gate (e.g., H, CX).
McGate(Box<MCGate>)
An extended gate, such as a multi-controlled gate or a user-defined unitary.
UnitaryGate(Box<UnitaryGate>)
User-defined unitary gate backed by a matrix or circuit definition.
CircuitGate(Box<CircuitGate>)
Reusable gate defined by a frozen circuit body.
Directive(Directive)
A non-unitary operation, such as Measure, Barrier, or Reset.
ClassicalData(ClassicalDataOp)
Runtime classical data operation such as assignment or measurement into typed classical storage.
ClassicalControl(ClassicalControlOp)
Structured classical control flow.
This variant carries expression-based IR such as if, while, for,
switch, break, and continue. It is a runtime control instruction,
not a unitary gate: it has no fixed arity, cannot be represented as a
matrix, has no static inverse, and cannot be promoted to a
quantum-controlled instruction.
Delay
I gate in QCIS, represented here as Delay, unit is 0.5ns
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
Returns the stable concrete operation name or user-defined gate label.
Unlike Self::instruction_type, this distinguishes individual gates.
It is independent of Debug and of presentation-only formatting.
Sourcepub const fn instruction_type(&self) -> &'static str
pub const fn instruction_type(&self) -> &'static str
Returns a stable category name for this instruction.
pub const fn is_standard(&self) -> bool
pub const fn is_mcgate(&self) -> bool
pub const fn is_unitary(&self) -> bool
pub const fn is_circuit_gate(&self) -> bool
pub const fn is_directive(&self) -> bool
pub const fn is_classical_data(&self) -> bool
pub const fn is_classical_control(&self) -> bool
pub const fn is_delay(&self) -> bool
Sourcepub const fn is_quantum_gate(&self) -> bool
pub const fn is_quantum_gate(&self) -> bool
Returns whether this instruction is a unitary quantum gate.
Sourcepub fn standard_gate(&self) -> Option<StandardGate>
pub fn standard_gate(&self) -> Option<StandardGate>
Returns the standard gate represented directly by this instruction.
Sourcepub fn mc_gate(&self) -> Option<&MCGate>
pub fn mc_gate(&self) -> Option<&MCGate>
Returns the multi-controlled gate when this is an McGate instruction.
Sourcepub fn unitary_gate(&self) -> Option<&UnitaryGate>
pub fn unitary_gate(&self) -> Option<&UnitaryGate>
Returns the user-defined unitary gate when this is a UnitaryGate instruction.
Sourcepub fn circuit_gate(&self) -> Option<&CircuitGate>
pub fn circuit_gate(&self) -> Option<&CircuitGate>
Returns the circuit-backed gate when this is a CircuitGate instruction.
Sourcepub fn directive(&self) -> Option<Directive>
pub fn directive(&self) -> Option<Directive>
Returns the directive when this is a Directive instruction.
Sourcepub fn classical_data(&self) -> Option<&ClassicalDataOp>
pub fn classical_data(&self) -> Option<&ClassicalDataOp>
Returns the classical data operation when this is a ClassicalData instruction.
Sourcepub fn classical_control(&self) -> Option<&ClassicalControlOp>
pub fn classical_control(&self) -> Option<&ClassicalControlOp>
Returns the classical control operation when this is a ClassicalControl instruction.
Sourcepub fn has_measurement(&self) -> bool
pub fn has_measurement(&self) -> bool
Returns true when this instruction directly or recursively contains a measurement.
Sourcepub fn reads_value(&self, value: ClassicalValue) -> bool
pub fn reads_value(&self, value: ClassicalValue) -> bool
Returns true when this instruction directly or recursively reads value.
Sourcepub fn gate_arity(&self) -> Option<(usize, usize)>
pub fn gate_arity(&self) -> Option<(usize, usize)>
Returns the fixed (qubit_count, parameter_count) for gate-like instructions.
This method describes arity that is intrinsic to the instruction itself.
It returns None for instructions whose qubit count is variable or
context-dependent, such as barriers and classical control operations.
Callers that need the qubits used by a classical control body should use
ClassicalControlOp::used_qubits instead.
Sourcepub fn matrix(&self, params: &[f64]) -> Option<Cow<'_, Array2<Complex64>>>
pub fn matrix(&self, params: &[f64]) -> Option<Cow<'_, Array2<Complex64>>>
Computes the unitary matrix representation of the instruction.
The first qubit argument is the most-significant bit of the local matrix for every supported gate, including circuit-backed UnitaryGate definitions. Full circuit matrices instead use an LSB-first basis.
§Arguments
params- A slice of floating-point parameters (e.g., rotation angles). CircuitGate values bind positionally to its declared signature.
§Returns
Some(Cow<Array2>): A numeric matrix for a supported gate instruction.None: If parameters are invalid or unresolved, or the instruction has no matrix (e.g.,Measure,Barrier,Reset, or classical control).
Sourcepub fn inverse(
&self,
params: &[Parameter],
) -> Option<(Instruction, SmallVec<[Parameter; 3]>)>
pub fn inverse( &self, params: &[Parameter], ) -> Option<(Instruction, SmallVec<[Parameter; 3]>)>
Computes the inverse (Hermitian conjugate) of the instruction.
§Arguments
params- The parameters of the instruction instance.
§Returns
Some(...): The inverse instruction and its transformed parameters.None: If the instruction is non-invertible (e.g.,Measureor classical control) or if the inverse cannot be symbolically determined (e.g., some custom unitaries).
Sourcepub fn control(&self, num_new_ctrls: usize) -> Option<Instruction>
pub fn control(&self, num_new_ctrls: usize) -> Option<Instruction>
Returns a new instruction that applies the current operation conditioned on extra control qubits.
This method employs a canonicalization strategy to return the most optimized gate representation:
- Promotion: If adding controls to a
StandardGateresults in anotherStandardGate(e.g., $X \xrightarrow{+1} CX \xrightarrow{+1} CCX$), it returns the upgraded standard gate. - Fallback: If no standard equivalent exists (e.g., $C^3-X$), it returns
an
Instruction::McGate. - Aggregation: If the instruction is already an
MCGate, the new controls are merged into it.
§Arguments
num_new_ctrls- The number of additional control qubits to add.
§Returns
Some(Instruction): The new controlled instruction.None: If the instruction cannot be controlled (e.g.,Barrier,Measure, or classical control).
Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§impl Debug for Instruction
impl Debug for Instruction
Source§impl Display for Instruction
impl Display for Instruction
Source§impl From<ClassicalControlOp> for Instruction
impl From<ClassicalControlOp> for Instruction
Source§fn from(cf: ClassicalControlOp) -> Self
fn from(cf: ClassicalControlOp) -> Self
Source§impl From<ClassicalDataOp> for Instruction
impl From<ClassicalDataOp> for Instruction
Source§fn from(op: ClassicalDataOp) -> Self
fn from(op: ClassicalDataOp) -> Self
Source§impl From<Directive> for Instruction
impl From<Directive> for Instruction
Source§impl From<Instruction> for ValueInstruction
impl From<Instruction> for ValueInstruction
Source§fn from(inst: Instruction) -> Self
fn from(inst: Instruction) -> Self
Converts a non-control-flow Instruction into a ValueInstruction.
§Panics
Panics in debug builds if the instruction is Instruction::ClassicalControl.
Source§impl From<StandardGate> for Instruction
impl From<StandardGate> for Instruction
Source§fn from(g: StandardGate) -> Self
fn from(g: StandardGate) -> Self
Source§impl PartialEq for Instruction
impl PartialEq for Instruction
impl StructuralPartialEq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnsafeUnpin for Instruction
impl UnwindSafe for Instruction
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.impl<T, U> Imply<T> for U
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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> StdoutFmt for Twhere
T: Display,
impl<T> StdoutFmt for Twhere
T: Display,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.