pub enum Gate {
Operator(Box<dyn Operator>, Vec<usize>, Vec<usize>),
Measurement(MeasurementBasis, Vec<usize>),
Parametric(Box<dyn ParametricGate>, Vec<usize>, Vec<usize>),
PauliString(PauliString),
PauliTimeEvolution(PauliString, f64),
}Expand description
Represents a quantum gate as part of a quantum circuit.
Variants§
Operator(Box<dyn Operator>, Vec<usize>, Vec<usize>)
Represents an operator gate.
§Fields
-
operator- A boxed dynamic operator trait object. -
target_indices- The indices of the qubits on which the operator acts. -
control_indices- Optional control qubit indices for controlled gates. If empty, the gate is applied unconditionally.
Measurement(MeasurementBasis, Vec<usize>)
Represents a measurement gate.
§Fields
MeasurementBasis- The basis of measurement (e.g., computational basis).indices- The indices of the measured qubits.
Parametric(Box<dyn ParametricGate>, Vec<usize>, Vec<usize>)
Represents a parametric gate.
PauliString(PauliString)
PauliTimeEvolution(PauliString, f64)
Represents a Pauli time evolution gate. WARNING: This gate is not yet supported in the compiler and cannot be used in circuits that need to be compiled. The compiler will panic if this gate is encountered during compilation.
§Fields
PauliString- The Pauli String operator.time- The time parameter for the evolution.
Implementations§
Source§impl Gate
impl Gate
Sourcepub fn new_measurement(
qubit_indices: Vec<usize>,
basis: MeasurementBasis,
) -> Self
pub fn new_measurement( qubit_indices: Vec<usize>, basis: MeasurementBasis, ) -> Self
Sourcepub fn new_operator(
operator: Box<dyn Operator>,
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Self
pub fn new_operator( operator: Box<dyn Operator>, target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Self
Creates a new operator gate for the specified qubit indices.
§Arguments
-
operator- A boxed dynamic operator trait object. -
target_indices- The indices of the qubits on which the operator acts. -
control_indices- Optional control qubit indices for controlled gates.
§Returns
Gate- A new instance of the Gate struct representing an operator gate.
Sourcepub fn get_target_qubits(&self) -> Vec<usize>
pub fn get_target_qubits(&self) -> Vec<usize>
Returns the indices of the qubits on which the gate acts.
§Returns
Vec<usize>- A vector of indices of the qubits on which the gate acts.
Sourcepub fn get_control_qubits(&self) -> Option<&Vec<usize>>
pub fn get_control_qubits(&self) -> Option<&Vec<usize>>
Returns the control indices of the gate if it has any.
§Returns
Option<&Vec<usize>>- An optional vector of control indices.
Sourcepub fn h_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn h_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn h_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn h_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Sourcepub fn x_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn x_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn x_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn x_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Creates new Pauli-X gates for the specified qubit indices with control qubits.
§Arguments
-
target_indices- The indices of the target qubits. -
control_indices- The indices of the control qubits.
§Returns
Gates- A vector of Gate structs representing controlled Pauli-X gates for each target qubit index.
Sourcepub fn y_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn y_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn y_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn y_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Sourcepub fn z_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn z_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn z_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn z_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Sourcepub fn i_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn i_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn i_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn i_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Sourcepub fn s_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn s_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn s_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn s_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Sourcepub fn s_dag_gate(qubit_index: usize) -> Self
pub fn s_dag_gate(qubit_index: usize) -> Self
Sourcepub fn s_dag_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn s_dag_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn s_dag_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn s_dag_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Creates new controlled Phase-S dagger gates for the specified qubit indices.
§Arguments
-
target_indices- The indices of the target qubits. -
control_indices- The indices of the control qubits.
§Returns
Gates- A vector of Gate structs representing controlled Phase-S dagger gates for each target qubit index.
Sourcepub fn t_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn t_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn t_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn t_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Sourcepub fn t_dag_gate(qubit_index: usize) -> Self
pub fn t_dag_gate(qubit_index: usize) -> Self
Sourcepub fn t_dag_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
pub fn t_dag_multi_gate(qubit_indices: Vec<usize>) -> Vec<Self>
Sourcepub fn t_dag_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Vec<Self>
pub fn t_dag_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Vec<Self>
Creates new controlled Phase-T dagger gates for the specified qubit indices.
§Arguments
-
target_indices- The indices of the target qubits. -
control_indices- The indices of the control qubits.
§Returns
Gates- A vector of Gate structs representing controlled Phase-T dagger gates for each target qubit index.
Sourcepub fn p_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
pub fn p_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
Creates new Phase Shift (P) gates for the specified qubit indices and angle.
§Arguments
qubit_indices- The indices of the qubits on which the Phase Shift gates act.angle- The phase shift angle in radians for all gates.
§Returns
Vec<Gate>- A vector of Gate structs representing Phase Shift gates for each qubit index.
Sourcepub fn p_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
angle: f64,
) -> Vec<Self>
pub fn p_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, angle: f64, ) -> Vec<Self>
Creates new controlled Phase Shift (P) gates for the specified qubit indices and angle.
§Arguments
target_indices- The indices of the target qubits.control_indices- The indices of the control qubits.angle- The phase shift angle in radians for all gates.
§Returns
Gates- A vector of Gate structs representing controlled Phase Shift gates for each target qubit index.
Sourcepub fn rx_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
pub fn rx_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
Creates new RotateX (RX) gates for the specified qubit indices and angle.
§Arguments
qubit_indices- The indices of the qubits on which the RotateX gates act.angle- The rotation angle in radians for all gates.
§Returns
Vec<Gate>- A vector of Gate structs representing RotateX gates for each qubit index.
Sourcepub fn rx_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
angle: f64,
) -> Vec<Self>
pub fn rx_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, angle: f64, ) -> Vec<Self>
Creates new controlled RotateX (RX) gates for the specified qubit indices and angle.
§Arguments
target_indices- The indices of the target qubits.control_indices- The indices of the control qubits.angle- The rotation angle in radians for all gates.
§Returns
Gates- A vector of Gate structs representing controlled RotateX gates for each target qubit index.
Sourcepub fn ry_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
pub fn ry_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
Creates new RotateY (RY) gates for the specified qubit indices and angle.
§Arguments
qubit_indices- The indices of the qubits on which the RotateY gates act.angle- The rotation angle in radians for all gates.
§Returns
Vec<Gate>- A vector of Gate structs representing RotateY gates for each qubit index.
Sourcepub fn ry_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
angle: f64,
) -> Vec<Self>
pub fn ry_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, angle: f64, ) -> Vec<Self>
Creates new controlled RotateY (RY) gates for the specified qubit indices and angle.
§Arguments
target_indices- The indices of the target qubits.control_indices- The indices of the control qubits.angle- The rotation angle in radians for all gates.
§Returns
Gates- A vector of Gate structs representing controlled RotateY gates for each target qubit index.
Sourcepub fn rz_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
pub fn rz_multi_gate(qubit_indices: Vec<usize>, angle: f64) -> Vec<Self>
Creates new RotateZ (RZ) gates for the specified qubit indices and angle.
§Arguments
qubit_indices- The indices of the qubits on which the RotateZ gates act.angle- The rotation angle in radians for all gates.
§Returns
Vec<Gate>- A vector of Gate structs representing RotateZ gates for each qubit index.
Sourcepub fn rz_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
angle: f64,
) -> Vec<Self>
pub fn rz_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, angle: f64, ) -> Vec<Self>
Creates new controlled RotateZ (RZ) gates for the specified qubit indices and angle.
§Arguments
target_indices- The indices of the target qubits.control_indices- The indices of the control qubits.angle- The rotation angle in radians for all gates.
§Returns
Gates- A vector of Gate structs representing controlled RotateZ gates for each target qubit index.
Sourcepub fn unitary2_gate(
qubit_index: usize,
unitary: [[Complex<f64>; 2]; 2],
) -> Result<Self, Error>
pub fn unitary2_gate( qubit_index: usize, unitary: [[Complex<f64>; 2]; 2], ) -> Result<Self, Error>
Creates a new Unitary2 gate for the specified qubit index and unitary matrix.
§Arguments
qubit_index- The index of the qubit on which the Unitary2 gate acts.unitary- The unitary matrix to be applied.
§Returns
Result<Gate, Error>- A Gate struct representing a Unitary2 gate if the unitary is valid, else an error.
Sourcepub fn unitary2_multi_gate(
qubit_indices: Vec<usize>,
unitary: [[Complex<f64>; 2]; 2],
) -> Result<Vec<Self>, Error>
pub fn unitary2_multi_gate( qubit_indices: Vec<usize>, unitary: [[Complex<f64>; 2]; 2], ) -> Result<Vec<Self>, Error>
Creates new Unitary2 gates for the specified qubit indices and unitary matrix.
§Arguments
-
qubit_indices- The indices of the qubits on which the Unitary2 gates act. -
unitary- The unitary matrix to be applied.
§Returns
Result<Vec<Gate>, Error>- A vector of Gate structs representing Unitary2 gates for each qubit index if the unitary is valid,, else an error.
Sourcepub fn unitary2_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
unitary: [[Complex<f64>; 2]; 2],
) -> Result<Vec<Self>, Error>
pub fn unitary2_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, unitary: [[Complex<f64>; 2]; 2], ) -> Result<Vec<Self>, Error>
Creates new controlled Unitary2 gates for the specified qubit indices and unitary matrix.
§Arguments
-
target_indices- The indices of the target qubits. -
control_indices- The indices of the control qubits. -
unitary- The unitary matrix to be applied.
§Returns
Result<Vec<Gate>, Error>- A vector of Gate structs representing controlled Unitary2 gates for each target qubit index if the unitary is valid, else an error.
Sourcepub fn ry_phase_gate(qubit_index: usize, theta: f64, phi: f64) -> Self
pub fn ry_phase_gate(qubit_index: usize, theta: f64, phi: f64) -> Self
Creates a new Unitary2 gate for the specified qubit index and unitary matrix using a rotation angle and phase shift. Unlike custom Unitary2 gates, the generated unitary matrix is guaranteed to be valid. Therefore, this method does not return an error.
§Arguments
-
qubit_index - The index of the qubit on which the Unitary2 gate acts.
-
theta - The rotation angle in radians.
-
phi - The phase shift in radians.
§Returns
- Gate - A new instance of the Gate struct representing a Unitary2 gate.
Sourcepub fn ry_phase_multi_gate(
qubit_indices: Vec<usize>,
theta: f64,
phi: f64,
) -> Vec<Self>
pub fn ry_phase_multi_gate( qubit_indices: Vec<usize>, theta: f64, phi: f64, ) -> Vec<Self>
Creates new Unitary2 gates for the specified qubit indices and unitary matrix using a rotation angle and phase shift. Unlike custom Unitary2 gates, the generated unitary matrix is guaranteed to be valid. Therefore, this method does not return an error.
§Arguments
-
qubit_indices - The indices of the qubits on which the Unitary2 gates act.
-
theta - The rotation angle in radians for all gates.
-
phi - The phase shift in radians for all gates.
§Returns
Vec<Gate>- A vector of Gate structs representing Unitary2 gates for each qubit index.
Sourcepub fn ry_phase_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
theta: f64,
phi: f64,
) -> Vec<Self>
pub fn ry_phase_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, theta: f64, phi: f64, ) -> Vec<Self>
Creates new controlled Unitary2 gates for the specified qubit indices and unitary matrix using a rotation angle and phase shift.
§Arguments
-
target_indices - The indices of the target qubits.
-
control_indices - The indices of the control qubits.
-
theta - The rotation angle in radians for all gates.
-
phi - The phase shift in radians for all gates.
§Returns
Vec<Gate>- A vector of Gate structs representing controlled Unitary2 gates for each target qubit index.
Sourcepub fn ry_phase_dag_gate(qubit_index: usize, theta: f64, phi: f64) -> Self
pub fn ry_phase_dag_gate(qubit_index: usize, theta: f64, phi: f64) -> Self
Creates a new Unitary2 gate from a rotation angle theta and phase shift angle phi.
§Arguments
qubit_index- The index of the qubit on which the Unitary2 gate acts.theta- The rotation angle in radians.phi- The phase shift angle in radians.
§Returns
- Gate - A new instance of the Gate struct representing a Unitary2 gate.
Sourcepub fn ry_phase_dag_multi_gate(
qubit_indices: Vec<usize>,
theta: f64,
phi: f64,
) -> Vec<Self>
pub fn ry_phase_dag_multi_gate( qubit_indices: Vec<usize>, theta: f64, phi: f64, ) -> Vec<Self>
Creates new Unitary2 gates from a rotation angle theta and phase shift angle phi.
§Arguments
-
qubit_indices- The indices of the qubits on which the Unitary2 gates act. -
theta- The rotation angle in radians. -
phi- The phase shift angle in radians. -
Vec<Gate>- A vector of Gate structs representing Unitary2 gates for each qubit index.
Sourcepub fn ry_phase_dag_controlled_gates(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
theta: f64,
phi: f64,
) -> Vec<Self>
pub fn ry_phase_dag_controlled_gates( target_indices: Vec<usize>, control_indices: Vec<usize>, theta: f64, phi: f64, ) -> Vec<Self>
Creates new controlled Unitary2 gates from a rotation angle theta and phase shift angle phi.
§Arguments
target_indices- The indices of the target qubits.control_indices- The indices of the control qubits.theta- The rotation angle in radians.phi- The phase shift angle in radians.
§Returns
Vec<Gate>- A vector of Gate structs representing controlled Unitary2 gates for each target qubit index.
Sourcepub fn swap_controlled_gate(
target_indices: Vec<usize>,
control_indices: Vec<usize>,
) -> Self
pub fn swap_controlled_gate( target_indices: Vec<usize>, control_indices: Vec<usize>, ) -> Self
Sourcepub fn toffoli_gate(target_index: usize, control_indices: Vec<usize>) -> Self
pub fn toffoli_gate(target_index: usize, control_indices: Vec<usize>) -> Self
Sourcepub fn pauli_string_gate(pauli_string: PauliString) -> Self
pub fn pauli_string_gate(pauli_string: PauliString) -> Self
Sourcepub fn pauli_time_evolution_gate(pauli_string: PauliString, time: f64) -> Self
pub fn pauli_time_evolution_gate(pauli_string: PauliString, time: f64) -> Self
Sourcepub fn matchgate(target_index: usize, theta: f64, phi1: f64, phi2: f64) -> Self
pub fn matchgate(target_index: usize, theta: f64, phi1: f64, phi2: f64) -> Self
Creates a new Matchgate with the specified qubit index and its adjacent as targets.
§Arguments
target_index- The index of the first target qubit. The second target qubit is assumed to be the next qubit.theta- The angle of rotation in radians.phi1- The first phase shift in radians.phi2- The second phase shift in radians.
§Returns
Gate- A new instance of the Gate struct representing a Matchgate.
§Warning
This gate is not yet compilable to OpenQASM, since it requires advanced decomposition techniques.
Sourcepub fn controlled_matchgate(
target_index: usize,
control_indices: Vec<usize>,
theta: f64,
phi1: f64,
phi2: f64,
) -> Self
pub fn controlled_matchgate( target_index: usize, control_indices: Vec<usize>, theta: f64, phi1: f64, phi2: f64, ) -> Self
Creates a new controlled Matchgate with the specified qubit index and its adjacent as target qubits.
§Arguments
target_index- The index of the first target qubit. The second target qubit is assumed to be the next qubit.control_indices- The indices of the control qubits.theta- The angle of rotation in radians.phi1- The first phase shift in radians.phi2- The second phase shift in radians.
§Returns
Gate- A new instance of the Gate struct representing a controlled Matchgate.
§Warning
This gate is not yet compilable to OpenQASM, since it requires advanced decomposition techniques.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Gate
impl !RefUnwindSafe for Gate
impl Send for Gate
impl Sync for Gate
impl Unpin for Gate
impl !UnwindSafe for Gate
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 more