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) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new circuit with estimated capacity
Sourcepub fn add_gate<G: GateOp + Clone + Send + Sync + 'static>(
&mut self,
gate: G,
) -> QuantRS2Result<&mut Self>
pub fn add_gate<G: GateOp + Clone + Send + Sync + 'static>( &mut self, gate: G, ) -> QuantRS2Result<&mut Self>
Add a gate to the circuit
Sourcepub fn add_gate_arc(
&mut self,
gate: Arc<dyn GateOp + Send + Sync>,
) -> QuantRS2Result<&mut Self>
pub fn add_gate_arc( &mut self, gate: Arc<dyn GateOp + Send + Sync>, ) -> QuantRS2Result<&mut Self>
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 + Send + Sync>>
pub fn gates_on_qubit( &self, target_qubit: QubitId, ) -> Vec<&Arc<dyn GateOp + Send + Sync>>
Get gates that operate on a specific qubit
Sourcepub fn gates_in_range(
&self,
start: usize,
end: usize,
) -> &[Arc<dyn GateOp + Send + Sync>]
pub fn gates_in_range( &self, start: usize, end: usize, ) -> &[Arc<dyn GateOp + Send + Sync>]
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 get_single_qubit_for_gate(
&self,
gate_type: &str,
index: usize,
) -> PyResult<u32>
pub fn get_single_qubit_for_gate( &self, gate_type: &str, index: usize, ) -> PyResult<u32>
Get a qubit for a specific single-qubit gate by gate type and index
Sourcepub fn get_rotation_params_for_gate(
&self,
gate_type: &str,
index: usize,
) -> PyResult<(u32, f64)>
pub fn get_rotation_params_for_gate( &self, gate_type: &str, index: usize, ) -> PyResult<(u32, f64)>
Get rotation parameters (qubit, angle) for a specific gate by gate type and index
Sourcepub fn get_two_qubit_params_for_gate(
&self,
gate_type: &str,
index: usize,
) -> PyResult<(u32, u32)>
pub fn get_two_qubit_params_for_gate( &self, gate_type: &str, index: usize, ) -> PyResult<(u32, u32)>
Get two-qubit parameters (control, target) for a specific gate by gate type and index
Sourcepub fn get_controlled_rotation_params_for_gate(
&self,
gate_type: &str,
index: usize,
) -> PyResult<(u32, u32, f64)>
pub fn get_controlled_rotation_params_for_gate( &self, gate_type: &str, index: usize, ) -> PyResult<(u32, u32, f64)>
Get controlled rotation parameters (control, target, angle) for a specific gate
Sourcepub fn get_three_qubit_params_for_gate(
&self,
gate_type: &str,
index: usize,
) -> PyResult<(u32, u32, u32)>
pub fn get_three_qubit_params_for_gate( &self, gate_type: &str, index: usize, ) -> PyResult<(u32, u32, u32)>
Get three-qubit parameters for gates like Toffoli or Fredkin
Sourcepub fn h(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn h(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Hadamard gate to a qubit
Sourcepub fn x(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn x(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Pauli-X gate to a qubit
Sourcepub fn y(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn y(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Pauli-Y gate to a qubit
Sourcepub fn z(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn z(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Pauli-Z gate to a qubit
Sourcepub fn rx(
&mut self,
target: impl Into<QubitId>,
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn rx( &mut self, target: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
Apply a rotation around X-axis
Sourcepub fn ry(
&mut self,
target: impl Into<QubitId>,
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn ry( &mut self, target: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
Apply a rotation around Y-axis
Sourcepub fn rz(
&mut self,
target: impl Into<QubitId>,
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn rz( &mut self, target: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
Apply a rotation around Z-axis
Sourcepub fn s(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn s(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Phase gate (S gate)
Sourcepub fn sdg(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn sdg(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Phase-dagger gate (S† gate)
Sourcepub fn t(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn t(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a T gate
Sourcepub fn tdg(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn tdg(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a T-dagger gate (T† gate)
Sourcepub fn sx(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn sx(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Square Root of X gate (√X)
Sourcepub fn sxdg(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn sxdg(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply a Square Root of X Dagger gate (√X†)
Sourcepub fn cnot(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn cnot( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a CNOT gate
Sourcepub fn cx(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn cx( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a CNOT gate (alias for cnot)
Sourcepub fn cy(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn cy( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a CY gate (Controlled-Y)
Sourcepub fn cz(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn cz( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a CZ gate (Controlled-Z)
Sourcepub fn ch(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn ch( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a CH gate (Controlled-Hadamard)
Sourcepub fn cs(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn cs( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a CS gate (Controlled-Phase/S)
Sourcepub fn crx(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn crx( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
Apply a controlled rotation around X-axis (CRX)
Sourcepub fn cry(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn cry( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
Apply a controlled rotation around Y-axis (CRY)
Sourcepub fn crz(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn crz( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
Apply a controlled rotation around Z-axis (CRZ)
Sourcepub fn cp(
&mut self,
control: impl Into<QubitId>,
target: impl Into<QubitId>,
lambda: f64,
) -> QuantRS2Result<&mut Self>
pub fn cp( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, lambda: f64, ) -> QuantRS2Result<&mut Self>
Apply a controlled phase gate
Sourcepub fn swap(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn swap( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a SWAP gate
Sourcepub fn toffoli(
&mut self,
control1: impl Into<QubitId>,
control2: impl Into<QubitId>,
target: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn toffoli( &mut self, control1: impl Into<QubitId>, control2: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a Toffoli (CCNOT) gate
Sourcepub fn cswap(
&mut self,
control: impl Into<QubitId>,
target1: impl Into<QubitId>,
target2: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn cswap( &mut self, control: impl Into<QubitId>, target1: impl Into<QubitId>, target2: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a Fredkin (CSWAP) gate
Sourcepub fn u(
&mut self,
target: impl Into<QubitId>,
theta: f64,
phi: f64,
lambda: f64,
) -> QuantRS2Result<&mut Self>
pub fn u( &mut self, target: impl Into<QubitId>, theta: f64, phi: f64, lambda: f64, ) -> QuantRS2Result<&mut Self>
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,
) -> QuantRS2Result<&mut Self>
pub fn p( &mut self, target: impl Into<QubitId>, lambda: f64, ) -> QuantRS2Result<&mut Self>
Apply a P gate (phase gate with parameter)
P(λ) = [[1, 0], [0, e^(iλ)]]
Sourcepub fn id(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
pub fn id(&mut self, target: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
Apply an Identity gate
Sourcepub fn iswap(
&mut self,
qubit1: impl Into<QubitId>,
qubit2: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn iswap( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
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>,
) -> QuantRS2Result<&mut Self>
pub fn ecr( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
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,
) -> QuantRS2Result<&mut Self>
pub fn rxx( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
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,
) -> QuantRS2Result<&mut Self>
pub fn ryy( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
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,
) -> QuantRS2Result<&mut Self>
pub fn rzz( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
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,
) -> QuantRS2Result<&mut Self>
pub fn rzx( &mut self, control: impl Into<QubitId>, target: impl Into<QubitId>, theta: f64, ) -> QuantRS2Result<&mut Self>
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>,
) -> QuantRS2Result<&mut Self>
pub fn dcx( &mut self, qubit1: impl Into<QubitId>, qubit2: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
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>,
) -> QuantRS2Result<&mut Self>
pub fn ccx( &mut self, control1: impl Into<QubitId>, control2: impl Into<QubitId>, target: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a CCX gate (alias for Toffoli)
Sourcepub fn fredkin(
&mut self,
control: impl Into<QubitId>,
target1: impl Into<QubitId>,
target2: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn fredkin( &mut self, control: impl Into<QubitId>, target1: impl Into<QubitId>, target2: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
Apply a Fredkin gate (alias for cswap)
Sourcepub fn measure(
&mut self,
qubit: impl Into<QubitId>,
) -> QuantRS2Result<&mut Self>
pub fn measure( &mut self, qubit: impl Into<QubitId>, ) -> QuantRS2Result<&mut Self>
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>) -> QuantRS2Result<&mut Self>
pub fn reset(&mut self, _qubit: impl Into<QubitId>) -> QuantRS2Result<&mut Self>
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]) -> QuantRS2Result<&mut Self>
pub fn barrier(&mut self, qubits: &[QubitId]) -> QuantRS2Result<&mut Self>
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: Simulator<N>>(&self, simulator: S) -> QuantRS2Result<Register<N>>
pub fn run<S: Simulator<N>>(&self, simulator: S) -> QuantRS2Result<Register<N>>
Run the circuit on a simulator
Sourcepub fn decompose(&self) -> QuantRS2Result<Self>
pub fn decompose(&self) -> QuantRS2Result<Self>
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) -> QuantRS2Result<Self>
pub fn optimize(&self) -> QuantRS2Result<Self>
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,
) -> QuantRS2Result<CompositeGate>
pub fn create_composite( &self, start_idx: usize, end_idx: usize, name: &str, ) -> QuantRS2Result<CompositeGate>
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,
) -> QuantRS2Result<&mut Self>
pub fn add_composite( &mut self, composite: &CompositeGate, ) -> QuantRS2Result<&mut Self>
Add all gates from a composite gate to this circuit
Sourcepub fn measure_all(&mut self) -> QuantRS2Result<&mut Self>
pub fn measure_all(&mut self) -> QuantRS2Result<&mut Self>
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 h_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn h_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Sourcepub fn x_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn x_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Sourcepub fn y_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn y_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Apply Pauli-Y gates to multiple qubits at once
Sourcepub fn z_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn z_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Apply Pauli-Z gates to multiple qubits at once
Sourcepub fn h_range(&mut self, range: Range<u32>) -> QuantRS2Result<&mut Self>
pub fn h_range(&mut self, range: Range<u32>) -> QuantRS2Result<&mut Self>
Sourcepub fn x_range(&mut self, range: Range<u32>) -> QuantRS2Result<&mut Self>
pub fn x_range(&mut self, range: Range<u32>) -> QuantRS2Result<&mut Self>
Apply Pauli-X gates to a range of qubits
Sourcepub fn bell_state(
&mut self,
qubit1: u32,
qubit2: u32,
) -> QuantRS2Result<&mut Self>
pub fn bell_state( &mut self, qubit1: u32, qubit2: u32, ) -> QuantRS2Result<&mut Self>
Sourcepub fn ghz_state(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn ghz_state(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Sourcepub fn w_state(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn w_state(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
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) -> QuantRS2Result<&mut Self>
pub fn plus_state_all(&mut self) -> QuantRS2Result<&mut Self>
Sourcepub fn rx_all(
&mut self,
qubits: &[u32],
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn rx_all( &mut self, qubits: &[u32], theta: f64, ) -> QuantRS2Result<&mut Self>
Apply a rotation gate to multiple qubits with the same angle
Sourcepub fn ry_all(
&mut self,
qubits: &[u32],
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn ry_all( &mut self, qubits: &[u32], theta: f64, ) -> QuantRS2Result<&mut Self>
Apply RY rotation to multiple qubits
Sourcepub fn rz_all(
&mut self,
qubits: &[u32],
theta: f64,
) -> QuantRS2Result<&mut Self>
pub fn rz_all( &mut self, qubits: &[u32], theta: f64, ) -> QuantRS2Result<&mut Self>
Apply RZ rotation to multiple qubits
Sourcepub fn cnot_ladder(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn cnot_ladder(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Sourcepub fn cnot_ring(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn cnot_ring(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
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]) -> QuantRS2Result<&mut Self>
pub fn swap_ladder(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Sourcepub fn cz_ladder(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn cz_ladder(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
Sourcepub fn swap_all(&mut self, pairs: &[(u32, u32)]) -> QuantRS2Result<&mut Self>
pub fn swap_all(&mut self, pairs: &[(u32, u32)]) -> QuantRS2Result<&mut Self>
Sourcepub fn cz_all(&mut self, pairs: &[(u32, u32)]) -> QuantRS2Result<&mut Self>
pub fn cz_all(&mut self, pairs: &[(u32, u32)]) -> QuantRS2Result<&mut Self>
Sourcepub fn cnot_all(&mut self, pairs: &[(u32, u32)]) -> QuantRS2Result<&mut Self>
pub fn cnot_all(&mut self, pairs: &[(u32, u32)]) -> QuantRS2Result<&mut Self>
Sourcepub fn barrier_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
pub fn barrier_all(&mut self, qubits: &[u32]) -> QuantRS2Result<&mut Self>
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> 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<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.