pub struct Circuit<const N: usize> { /* private fields */ }Expand description
A quantum circuit with a fixed number of qubits
Implementations§
Source§impl<const N: usize> Circuit<N>
impl<const N: usize> Circuit<N>
Sourcepub fn with_capacity(capacity: usize) -> Circuit<N>
pub fn with_capacity(capacity: usize) -> Circuit<N>
Create a new circuit with estimated capacity
Sourcepub fn add_gate<G>(&mut self, gate: G) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn add_gate<G>(&mut self, gate: G) -> Result<&mut Circuit<N>, QuantRS2Error>
Add a gate to the circuit
Sourcepub fn add_gate_arc(
&mut self,
gate: Arc<dyn GateOp + Sync + Send>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn add_gate_arc( &mut self, gate: Arc<dyn GateOp + Sync + Send>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Add a gate from an Arc (for copying gates between circuits)
Sourcepub fn gates_as_boxes(&self) -> Vec<Box<dyn GateOp>>
pub fn gates_as_boxes(&self) -> Vec<Box<dyn GateOp>>
Get gates as Vec for compatibility with existing optimization code
Sourcepub fn count_gates_by_type(&self) -> HashMap<String, usize>
pub fn count_gates_by_type(&self) -> HashMap<String, usize>
Circuit introspection methods for optimization Count gates by type
Sourcepub fn calculate_depth(&self) -> usize
pub fn calculate_depth(&self) -> usize
Calculate circuit depth (longest sequential path)
Sourcepub fn count_two_qubit_gates(&self) -> usize
pub fn count_two_qubit_gates(&self) -> usize
Count two-qubit gates
Sourcepub fn count_multi_qubit_gates(&self) -> usize
pub fn count_multi_qubit_gates(&self) -> usize
Count multi-qubit gates (3 or more qubits)
Sourcepub fn calculate_critical_path(&self) -> usize
pub fn calculate_critical_path(&self) -> usize
Calculate the critical path length (same as depth for now, but could be enhanced)
Sourcepub fn calculate_gate_density(&self) -> f64
pub fn calculate_gate_density(&self) -> f64
Calculate gate density (gates per qubit)
Sourcepub fn get_used_qubits(&self) -> HashSet<QubitId>
pub fn get_used_qubits(&self) -> HashSet<QubitId>
Get all unique qubits used in the circuit
Sourcepub fn uses_all_qubits(&self) -> bool
pub fn uses_all_qubits(&self) -> bool
Check if the circuit uses all available qubits
Sourcepub fn gates_on_qubit(
&self,
target_qubit: QubitId,
) -> Vec<&Arc<dyn GateOp + Sync + Send>>
pub fn gates_on_qubit( &self, target_qubit: QubitId, ) -> Vec<&Arc<dyn GateOp + Sync + Send>>
Get gates that operate on a specific qubit
Sourcepub fn gates_in_range(
&self,
start: usize,
end: usize,
) -> &[Arc<dyn GateOp + Sync + Send>]
pub fn gates_in_range( &self, start: usize, end: usize, ) -> &[Arc<dyn GateOp + Sync + Send>]
Get gates between two indices (inclusive)
Sourcepub fn get_stats(&self) -> CircuitStats
pub fn get_stats(&self) -> CircuitStats
Get circuit statistics summary
Sourcepub const fn num_qubits(&self) -> usize
pub const fn num_qubits(&self) -> usize
Get the number of qubits in the circuit
Sourcepub fn get_gate_names(&self) -> Vec<String>
pub fn get_gate_names(&self) -> Vec<String>
Get the names of all gates in the circuit
Sourcepub fn h(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn h( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Hadamard gate to a qubit
Sourcepub fn x(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn x( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Pauli-X gate to a qubit
Sourcepub fn y(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn y( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Pauli-Y gate to a qubit
Sourcepub fn z(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn z( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Pauli-Z gate to a qubit
Sourcepub fn rx(
&mut self,
target: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn rx( &mut self, target: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a rotation around X-axis
Sourcepub fn ry(
&mut self,
target: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn ry( &mut self, target: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a rotation around Y-axis
Sourcepub fn rz(
&mut self,
target: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn rz( &mut self, target: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a rotation around Z-axis
Sourcepub fn s(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn s( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Phase gate (S gate)
Sourcepub fn sdg(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn sdg( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Phase-dagger gate (S† gate)
Sourcepub fn t(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn t( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a T gate
Sourcepub fn tdg(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn tdg( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a T-dagger gate (T† gate)
Sourcepub fn sx(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn sx( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Square Root of X gate (√X)
Sourcepub fn sxdg(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn sxdg( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Square Root of X Dagger gate (√X†)
Sourcepub fn cnot(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cnot( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a CNOT gate
Sourcepub fn cx(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cx( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a CNOT gate (alias for cnot)
Sourcepub fn cy(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cy( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a CY gate (Controlled-Y)
Sourcepub fn cz(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cz( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a CZ gate (Controlled-Z)
Sourcepub fn ch(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn ch( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a CH gate (Controlled-Hadamard)
Sourcepub fn cs(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cs( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a CS gate (Controlled-Phase/S)
Sourcepub fn crx(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn crx( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a controlled rotation around X-axis (CRX)
Sourcepub fn cry(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cry( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a controlled rotation around Y-axis (CRY)
Sourcepub fn crz(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn crz( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a controlled rotation around Z-axis (CRZ)
Sourcepub fn cp(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
lambda: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cp( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, lambda: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a controlled phase gate
Sourcepub fn swap(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn swap( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a SWAP gate
Sourcepub fn toffoli(
&mut self,
control1: impl Into<QubitId>,
control2: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn toffoli( &mut self, control1: impl Into<QubitId>, control2: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Toffoli (CCNOT) gate
Sourcepub fn cswap(
&mut self,
control: impl Into<QubitId>,
target1: impl Into<QubitId>,
target2: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cswap( &mut self, control: impl Into<QubitId>, target1: impl Into<QubitId>, target2: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Fredkin (CSWAP) gate
Sourcepub fn u(
&mut self,
target: impl Into<QubitId>,
theta: f64,
phi: f64,
lambda: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn u( &mut self, target: impl Into<QubitId>, theta: f64, phi: f64, lambda: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a U gate (general single-qubit rotation)
U(θ, φ, λ) = [[cos(θ/2), -e^(iλ)·sin(θ/2)], [e^(iφ)·sin(θ/2), e^(i(φ+λ))·cos(θ/2)]]
Sourcepub fn p(
&mut self,
target: impl Into<QubitId>,
lambda: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn p( &mut self, target: impl Into<QubitId>, lambda: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a P gate (phase gate with parameter)
P(λ) = [[1, 0], [0, e^(iλ)]]
Sourcepub fn id(
&mut self,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn id( &mut self, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply an Identity gate
Sourcepub fn iswap(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn iswap( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply an iSWAP gate
iSWAP swaps two qubits and phases |01⟩ and |10⟩ by i
Sourcepub fn ecr(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn ecr( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply an ECR gate (IBM native echoed cross-resonance gate)
Sourcepub fn rxx(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn rxx( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply an RXX gate (two-qubit XX rotation)
RXX(θ) = exp(-i * θ/2 * X⊗X)
Sourcepub fn ryy(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn ryy( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply an RYY gate (two-qubit YY rotation)
RYY(θ) = exp(-i * θ/2 * Y⊗Y)
Sourcepub fn rzz(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn rzz( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply an RZZ gate (two-qubit ZZ rotation)
RZZ(θ) = exp(-i * θ/2 * Z⊗Z)
Sourcepub fn rzx(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn rzx( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply an RZX gate (two-qubit ZX rotation / cross-resonance)
RZX(θ) = exp(-i * θ/2 * Z⊗X)
Sourcepub fn dcx(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn dcx( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a DCX gate (double CNOT gate)
DCX = CNOT(0,1) @ CNOT(1,0)
Sourcepub fn ccx(
&mut self,
control1: impl Into<QubitId>,
control2: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn ccx( &mut self, control1: impl Into<QubitId>, control2: impl Into<QubitId>, target: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a CCX gate (alias for Toffoli)
Sourcepub fn fredkin(
&mut self,
control: impl Into<QubitId>,
target1: impl Into<QubitId>,
target2: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn fredkin( &mut self, control: impl Into<QubitId>, target1: impl Into<QubitId>, target2: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a Fredkin gate (alias for cswap)
Sourcepub fn measure(
&mut self,
qubit: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn measure( &mut self, qubit: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Measure a qubit (currently adds a placeholder measure gate)
Note: This is currently a placeholder implementation for QASM export compatibility. For actual quantum measurements, use the measurement module functionality.
Sourcepub fn reset(
&mut self,
_qubit: impl Into<QubitId>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn reset( &mut self, _qubit: impl Into<QubitId>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Reset a qubit to |0⟩ state
Note: This operation is not yet fully implemented. Reset operations are complex and require special handling in quantum circuits.
Sourcepub fn barrier(
&mut self,
qubits: &[QubitId],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn barrier( &mut self, qubits: &[QubitId], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Add a barrier to prevent optimization across this point
Barriers are used to prevent gate optimization algorithms from reordering gates across specific points in the circuit. This is useful for maintaining timing constraints or preserving specific circuit structure.
Sourcepub fn run<S>(&self, simulator: S) -> Result<Register<N>, QuantRS2Error>where
S: Simulator<N>,
pub fn run<S>(&self, simulator: S) -> Result<Register<N>, QuantRS2Error>where
S: Simulator<N>,
Run the circuit on a simulator
Sourcepub fn decompose(&self) -> Result<Circuit<N>, QuantRS2Error>
pub fn decompose(&self) -> Result<Circuit<N>, QuantRS2Error>
Decompose the circuit into a sequence of standard gates
This method will return a new circuit with complex gates decomposed into sequences of simpler gates.
Sourcepub fn optimize(&self) -> Result<Circuit<N>, QuantRS2Error>
pub fn optimize(&self) -> Result<Circuit<N>, QuantRS2Error>
Optimize the circuit by combining or removing gates
This method will return a new circuit with simplified gates by removing unnecessary gates or combining adjacent gates.
Sourcepub fn create_composite(
&self,
start_idx: usize,
end_idx: usize,
name: &str,
) -> Result<CompositeGate, QuantRS2Error>
pub fn create_composite( &self, start_idx: usize, end_idx: usize, name: &str, ) -> Result<CompositeGate, QuantRS2Error>
Create a composite gate from a subsequence of this circuit
This method allows creating a custom gate that combines several other gates, which can be applied as a single unit to a circuit.
Sourcepub fn add_composite(
&mut self,
composite: &CompositeGate,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn add_composite( &mut self, composite: &CompositeGate, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Add all gates from a composite gate to this circuit
Sourcepub fn measure_all(&mut self) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn measure_all(&mut self) -> Result<&mut Circuit<N>, QuantRS2Error>
Measure all qubits in the circuit
Sourcepub fn with_classical_control(self) -> ClassicalCircuit<N>
pub fn with_classical_control(self) -> ClassicalCircuit<N>
Convert this circuit to a ClassicalCircuit with classical control support
Sourcepub fn y_all(
&mut self,
qubits: &[u32],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn y_all( &mut self, qubits: &[u32], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply Pauli-Y gates to multiple qubits at once
Sourcepub fn z_all(
&mut self,
qubits: &[u32],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn z_all( &mut self, qubits: &[u32], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply Pauli-Z gates to multiple qubits at once
Sourcepub fn x_range(
&mut self,
range: Range<u32>,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn x_range( &mut self, range: Range<u32>, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply Pauli-X gates to a range of qubits
Sourcepub fn bell_state(
&mut self,
qubit1: u32,
qubit2: u32,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn bell_state( &mut self, qubit1: u32, qubit2: u32, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Sourcepub fn w_state(
&mut self,
qubits: &[u32],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn w_state( &mut self, qubits: &[u32], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Prepare a W state on specified qubits
W state: (|100…⟩ + |010…⟩ + |001…⟩ + …)/√n
This is an approximation using rotation gates.
Sourcepub fn plus_state_all(&mut self) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn plus_state_all(&mut self) -> Result<&mut Circuit<N>, QuantRS2Error>
Sourcepub fn rx_all(
&mut self,
qubits: &[u32],
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn rx_all( &mut self, qubits: &[u32], theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply a rotation gate to multiple qubits with the same angle
Sourcepub fn ry_all(
&mut self,
qubits: &[u32],
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn ry_all( &mut self, qubits: &[u32], theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply RY rotation to multiple qubits
Sourcepub fn rz_all(
&mut self,
qubits: &[u32],
theta: f64,
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn rz_all( &mut self, qubits: &[u32], theta: f64, ) -> Result<&mut Circuit<N>, QuantRS2Error>
Apply RZ rotation to multiple qubits
Sourcepub fn cnot_ladder(
&mut self,
qubits: &[u32],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cnot_ladder( &mut self, qubits: &[u32], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Sourcepub fn cnot_ring(
&mut self,
qubits: &[u32],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn cnot_ring( &mut self, qubits: &[u32], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Create a ring of CNOT gates connecting qubits in a cycle
Like CNOT ladder but also connects last to first qubit.
Sourcepub fn swap_ladder(
&mut self,
qubits: &[u32],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn swap_ladder( &mut self, qubits: &[u32], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Sourcepub fn barrier_all(
&mut self,
qubits: &[u32],
) -> Result<&mut Circuit<N>, QuantRS2Error>
pub fn barrier_all( &mut self, qubits: &[u32], ) -> Result<&mut Circuit<N>, QuantRS2Error>
Add barriers to multiple qubits
Barriers prevent optimization across them and can be used to visualize circuit structure.
§Example
let mut circuit = Circuit::<5>::new();
circuit.h_all(&[0, 1, 2])?;
circuit.barrier_all(&[0, 1, 2])?; // Prevent optimization across this point
circuit.cnot_ladder(&[0, 1, 2])?;Source§impl<const N: usize> Circuit<N>
Extension trait for circuit slicing
impl<const N: usize> Circuit<N>
Extension trait for circuit slicing
Sourcepub fn slice(&self, strategy: SlicingStrategy) -> SlicingResult
pub fn slice(&self, strategy: SlicingStrategy) -> SlicingResult
Slice this circuit using the given strategy
Source§impl<const N: usize> Circuit<N>
Extension methods for circuits
impl<const N: usize> Circuit<N>
Extension methods for circuits
Sourcepub fn topological_analysis(&self) -> TopologicalAnalysis
pub fn topological_analysis(&self) -> TopologicalAnalysis
Perform topological analysis
Sourcepub fn topological_sort(&self, strategy: TopologicalStrategy) -> Vec<usize>
pub fn topological_sort(&self, strategy: TopologicalStrategy) -> Vec<usize>
Get topological order with specific strategy
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> Freeze for Circuit<N>
impl<const N: usize> !RefUnwindSafe for Circuit<N>
impl<const N: usize> Send for Circuit<N>
impl<const N: usize> Sync for Circuit<N>
impl<const N: usize> Unpin for Circuit<N>
impl<const N: usize> !UnwindSafe for Circuit<N>
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
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.