pub struct State {
pub state_vector: Vec<Complex<f64>>,
pub num_qubits: usize,
}Fields§
§state_vector: Vec<Complex<f64>>The state vector of the system, represented as a complex vector. Each element of the vector represents a probability amplitude for a particular state.
num_qubits: usizeThe number of qubits in the system.
Implementations§
Source§impl State
impl State
Sourcepub fn new(state_vector: Vec<Complex<f64>>) -> Result<Self, Error>
pub fn new(state_vector: Vec<Complex<f64>>) -> Result<Self, Error>
Creates a new state object with the given state vector.
§Arguments
state_vector- The state vector of the system, represented as a complex vector.
§Returns
state- A result containing the state object if successful, or an error if the state vector is invalid.
§Errors
- Returns an error if the state vector is empty.
- Returns an error if the state vector is not normalised (i.e., the square norm is not 1).
- Returns an error if the number of qubits is invalid (i.e., the length of the state vector is not a power of 2).
Sourcepub fn new_zero(num_qubits: usize) -> Result<Self, Error>
pub fn new_zero(num_qubits: usize) -> Result<Self, Error>
Creates a new state object with the given number of qubits initialised to the |0…0> state.
§Arguments
num_qubits- The number of qubits in the system.
§Returns
state- A result containing the state object if successful, or an error if the number of qubits is invalid.
§Errors
- Returns an error if the number of qubits is 0.
Sourcepub fn new_basis_n(num_qubits: usize, n: usize) -> Result<Self, Error>
pub fn new_basis_n(num_qubits: usize, n: usize) -> Result<Self, Error>
Creates a new state object with the given number of qubits initialised to the n-th basis state.
§Arguments
num_qubits- The number of qubits in the system.n- The index of the basis state to initialise to.
§Returns
state- A result containing a new state object with the specified number of qubits, initialised to then-th basis state or an error ifnis out of bounds or if the number of qubits is invalid.
§Errors
- Returns an error if the number of qubits is 0 or if
nis out of bounds for the given number of qubits.
Sourcepub fn new_plus(num_qubits: usize) -> Result<Self, Error>
pub fn new_plus(num_qubits: usize) -> Result<Self, Error>
Creates a new plus state object with the given number of qubits initialised to the |+…+> state.
§Arguments
num_qubits- The number of qubits in the system.
§Returns
state- A result containing a new state object with the specified number of qubits, initialised to the |+…+> state or an error if the number of qubits is invalid.
§Errors
- Returns an error if the number of qubits is 0.
Sourcepub fn new_minus(num_qubits: usize) -> Result<Self, Error>
pub fn new_minus(num_qubits: usize) -> Result<Self, Error>
Creates a new minus state object with the given number of qubits initialised to the |-…-> state.
§Arguments
num_qubits- The number of qubits in the system.
§Returns
state- A result containing a new state object with the specified number of qubits, initialised to the |-…-> state or an error if the number of qubits is invalid.
§Errors
- Returns an error if the number of qubits is 0.
Sourcepub fn num_qubits(&self) -> usize
pub fn num_qubits(&self) -> usize
Returns the number of qubits in the state vector.
§Returns
num_qubits- The number of qubits in the state vector.
Sourcepub fn measure(
&self,
basis: MeasurementBasis,
measured_qubits: &[usize],
) -> Result<MeasurementResult, Error>
pub fn measure( &self, basis: MeasurementBasis, measured_qubits: &[usize], ) -> Result<MeasurementResult, Error>
Measures the state vector in the specified basis and returns the measurement result.
§Arguments
basis- The basis to measure in.indices- The indices of the qubits to measure. Ifindicesis empty, all qubits are measured.
§Returns
result- A result containing the measurement result if successful, or an error if the measurement fails.
§Errors
- Returns an error if the measurement fails.
- Returns an error if the number of qubits is invalid.
- Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn measure_n(
&self,
basis: MeasurementBasis,
measured_qubits: &[usize],
n: usize,
) -> Result<Vec<MeasurementResult>, Error>
pub fn measure_n( &self, basis: MeasurementBasis, measured_qubits: &[usize], n: usize, ) -> Result<Vec<MeasurementResult>, Error>
Measures the state vector n times in the specified basis and returns the measurement results.
§Arguments
basis- The basis to measure in.indices- The indices of the qubits to measure. Ifindicesis empty, all qubits are measured.n- The number of measurements to perform.
§Returns
results- A result containing a vector of measurement results if successful, or an error if the measurement fails.
§Errors
- Returns an error if the measurement fails.
- Returns an error if the number of qubits is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if
nis 0.
Sourcepub fn tensor_product(&self, other: &Self) -> Result<Self, Error>
pub fn tensor_product(&self, other: &Self) -> Result<Self, Error>
Performs a tensor product of two state vectors and returns the resulting state. Uses parallel computation if the resulting dimension is large enough.
§Arguments
other- The other state vector to perform the tensor product with.
§Returns
result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if either state vector is empty.
- Returns an error if either state vector has an invalid number of qubits.
Sourcepub fn inner_product(&self, other: &Self) -> Result<Complex<f64>, Error>
pub fn inner_product(&self, other: &Self) -> Result<Complex<f64>, Error>
Performs an inner product of two state vectors and returns the resulting complex number.
§Arguments
other- The other state vector to perform the inner product with.
§Returns
result- A result containing the inner product as a complex number if successful, or an error if the operation fails.
§Errors
- Returns an error if either state vector is empty.
- Returns an error if the state vectors have different dimensions.
Sourcepub fn operate(
&self,
unitary: impl Operator,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn operate( &self, unitary: impl Operator, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies a unitary operation to the state vector.
§Arguments
-
unitary- The unitary operation to apply, represented as anOperatortrait object. -
target_qubits - The indices of the qubits to apply the unitary operation to.
-
control_qubits - The indices of the control qubits for the unitary operation, if any.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the unitary operation is invalid.
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn h(&self, index: usize) -> Result<Self, Error>
pub fn h(&self, index: usize) -> Result<Self, Error>
Applies the Hadamard gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Hadamard gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn h_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn h_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Hadamard gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Hadamard gate to.
§Returns
-
Result- A result containing the new state object if successful, or an error if the operation fails. §Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn ch_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn ch_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Hadamard gate to the specified qubits in the state vector in the given order.
§Arguments
-
target_qubits- The indices of the target qubits to apply the controlled Hadamard gate to. -
control_qubits- The indices of the control qubits for the controlled Hadamard gate.
§Returns
-
Result- A result containing the new state object if successful, or an error if the operation fails. §Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
-
Returns an error if the control qubits and target qubits overlap.
Sourcepub fn x(&self, index: usize) -> Result<Self, Error>
pub fn x(&self, index: usize) -> Result<Self, Error>
Applies the Pauli-X (NOT) gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Pauli-X gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn x_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn x_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Pauli-X (NOT) gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Pauli-X gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn cx_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn cx_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Pauli-X (NOT) gate to the specified qubits in the state vector in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Pauli-X gate to.control_qubits- The indices of the control qubits for the controlled Pauli-X gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn y(&self, index: usize) -> Result<Self, Error>
pub fn y(&self, index: usize) -> Result<Self, Error>
Applies the Pauli-Y gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Pauli-Y gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn y_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn y_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Pauli-Y gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Pauli-Y gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn cy_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn cy_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Pauli-Y gate to the specified qubits in the state vector in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Pauli-Y gate to.control_qubits- The indices of the control qubits for the controlled Pauli-Y gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn z(&self, index: usize) -> Result<Self, Error>
pub fn z(&self, index: usize) -> Result<Self, Error>
Applies the Pauli-Z gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Pauli-Z gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn z_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn z_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Pauli-Z gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Pauli-Z gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn cz_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn cz_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Pauli-Z gate to the specified qubits in the state vector in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Pauli-Z gate to.control_qubits- The indices of the control qubits for the controlled Pauli-Z gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn i(&self, qubit: usize) -> Result<Self, Error>
pub fn i(&self, qubit: usize) -> Result<Self, Error>
Applies the Identity gate to the state vector.
§Arguments
qubit- The index of the qubit to apply the Identity gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn i_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn i_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Identity gate to the state vector for multiple qubits in the given order.
§Arguments
qubits- The indices of the qubits to apply the Identity gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn ci_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn ci_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Identity gate to the state vector for multiple qubits in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Identity gate to.control_qubits- The indices of the control qubits for the controlled Identity gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn s(&self, index: usize) -> Result<Self, Error>
pub fn s(&self, index: usize) -> Result<Self, Error>
Applies the Phase S gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Phase S gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn s_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn s_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Phase S gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Phase S gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn cs_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn cs_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Phase S gate to the specified qubits in the state vector in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Phase S gate to.control_qubits- The indices of the control qubits for the controlled Phase S gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn t(&self, index: usize) -> Result<Self, Error>
pub fn t(&self, index: usize) -> Result<Self, Error>
Applies the Phase T gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Phase T gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn t_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn t_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Phase T gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Phase T gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn ct_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn ct_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Phase T gate to the specified qubits in the state vector in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Phase T gate to.control_qubits- The indices of the control qubits for the controlled Phase T gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn s_dag(&self, index: usize) -> Result<Self, Error>
pub fn s_dag(&self, index: usize) -> Result<Self, Error>
Applies the Phase S dagger gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Phase S dagger gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn s_dag_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn s_dag_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Phase S dagger gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Phase S dagger gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn cs_dag_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn cs_dag_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Phase S dagger gate to the specified qubits in the state vector in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Phase S dagger gate to.control_qubits- The indices of the control qubits for the controlled Phase S dagger gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn t_dag(&self, index: usize) -> Result<Self, Error>
pub fn t_dag(&self, index: usize) -> Result<Self, Error>
Applies the Phase T dagger gate to the specified qubit in the state vector.
§Arguments
index- The index of the qubit to apply the Phase T dagger gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn t_dag_multi(&self, qubits: &[usize]) -> Result<Self, Error>
pub fn t_dag_multi(&self, qubits: &[usize]) -> Result<Self, Error>
Applies the Phase T dagger gate to the specified qubits in the state vector in the given order.
§Arguments
qubits- The indices of the qubits to apply the Phase T dagger gate to.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn ct_dag_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<Self, Error>
pub fn ct_dag_multi( &self, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<Self, Error>
Applies the controlled Phase T dagger gate to the specified qubits in the state vector in the given order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Phase T dagger gate to.control_qubits- The indices of the control qubits for the controlled Phase T dagger gate.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn p(&self, index: usize, angle: f64) -> Result<Self, Error>
pub fn p(&self, index: usize, angle: f64) -> Result<Self, Error>
Applies the Phase Shift gate with the specified angle to the given qubit.
§Arguments
index- The index of the qubit to apply the Phase Shift gate to.angle- The phase shift angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn p_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
pub fn p_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
Applies the Phase Shift gate with the specified angle to the given qubits in order.
§Arguments
-
qubits- The indices of the qubits to apply the Phase Shift gate to. -
angle- The phase shift angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn cp_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
angle: f64,
) -> Result<Self, Error>
pub fn cp_multi( &self, target_qubits: &[usize], control_qubits: &[usize], angle: f64, ) -> Result<Self, Error>
Applies the controlled Phase Shift gate with the specified angle to the given qubits in order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled Phase Shift gate to.control_qubits- The indices of the control qubits for the controlled Phase Shift gate.angle- The phase shift angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn rx(&self, index: usize, angle: f64) -> Result<Self, Error>
pub fn rx(&self, index: usize, angle: f64) -> Result<Self, Error>
Applies the RotateX gate with the specified angle to the given qubit.
§Arguments
index- The index of the qubit to apply the RotateX gate to.angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn rx_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
pub fn rx_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
Applies the RotateX gate with the specified angle to the given qubits in order.
§Arguments
-
qubits- The indices of the qubits to apply the RotateX gate to. -
angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn crx_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
angle: f64,
) -> Result<Self, Error>
pub fn crx_multi( &self, target_qubits: &[usize], control_qubits: &[usize], angle: f64, ) -> Result<Self, Error>
Applies the controlled RotateX gate with the specified angle to the given qubits in order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled RotateX gate to.control_qubits- The indices of the control qubits for the controlled RotateX gate.angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn ry(&self, index: usize, angle: f64) -> Result<Self, Error>
pub fn ry(&self, index: usize, angle: f64) -> Result<Self, Error>
Applies the RotateY gate with the specified angle to the given qubit.
§Arguments
index- The index of the qubit to apply the RotateY gate to.angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn ry_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
pub fn ry_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
Applies the RotateY gate with the specified angle to the given qubits in order.
§Arguments
-
qubits- The indices of the qubits to apply the RotateY gate to. -
angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn cry_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
angle: f64,
) -> Result<Self, Error>
pub fn cry_multi( &self, target_qubits: &[usize], control_qubits: &[usize], angle: f64, ) -> Result<Self, Error>
Applies the controlled RotateY gate with the specified angle to the given qubits in order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled RotateY gate to.control_qubits- The indices of the control qubits for the controlled RotateY gate.angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn rz(&self, index: usize, angle: f64) -> Result<Self, Error>
pub fn rz(&self, index: usize, angle: f64) -> Result<Self, Error>
Applies the RotateZ gate with the specified angle to the given qubit.
§Arguments
index- The index of the qubit to apply the RotateZ gate to.angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the index is out of bounds for the state vector.
Sourcepub fn rz_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
pub fn rz_multi(&self, qubits: &[usize], angle: f64) -> Result<Self, Error>
Applies the RotateZ gate with the specified angle to the given qubits in order.
§Arguments
-
qubits- The indices of the qubits to apply the RotateZ gate to. -
angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
Sourcepub fn crz_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
angle: f64,
) -> Result<Self, Error>
pub fn crz_multi( &self, target_qubits: &[usize], control_qubits: &[usize], angle: f64, ) -> Result<Self, Error>
Applies the controlled RotateZ gate with the specified angle to the given qubits in order.
§Arguments
target_qubits- The indices of the target qubits to apply the controlled RotateZ gate to.control_qubits- The indices of the control qubits for the controlled RotateZ gate.angle- The rotation angle in radians.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if the number of qubits provided is invalid.
- Returns an error if the indices are out of bounds for the state vector.
- Returns an error if the control qubits and target qubits overlap.
Sourcepub fn unitary(
&self,
index: usize,
unitary: [[Complex<f64>; 2]; 2],
) -> Result<Self, Error>
pub fn unitary( &self, index: usize, unitary: [[Complex<f64>; 2]; 2], ) -> Result<Self, Error>
Applies the unitary gate to the specified qubit in the state vector.
§Arguments
-
index- The index of the qubit to apply the unitary gate to. -
unitary- The unitary matrix to apply.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the index is out of bounds for the state vector.
-
Returns an error if the unitary matrix is not unitary.
Sourcepub fn unitary_multi(
&self,
qubits: &[usize],
unitary: [[Complex<f64>; 2]; 2],
) -> Result<Self, Error>
pub fn unitary_multi( &self, qubits: &[usize], unitary: [[Complex<f64>; 2]; 2], ) -> Result<Self, Error>
Applies the unitary gate to the specified qubits in the state vector in the given order.
§Arguments
-
qubits- The indices of the qubits to apply the unitary gate to. -
unitary- The unitary matrix to apply.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
-
Returns an error if the unitary matrix is not unitary.
Sourcepub fn cunitary_multi(
&self,
target_qubits: &[usize],
control_qubits: &[usize],
unitary: [[Complex<f64>; 2]; 2],
) -> Result<Self, Error>
pub fn cunitary_multi( &self, target_qubits: &[usize], control_qubits: &[usize], unitary: [[Complex<f64>; 2]; 2], ) -> Result<Self, Error>
Applies the controlled unitary gate to the specified qubits in the state vector in the given order.
§Arguments
-
target_qubits- The indices of the target qubits to apply the controlled unitary gate to. -
control_qubits- The indices of the control qubits for the controlled unitary gate. -
unitary- The unitary matrix to apply.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
-
Returns an error if the number of qubits provided is invalid.
-
Returns an error if the indices are out of bounds for the state vector.
-
Returns an error if the control qubits and target qubits overlap.
-
Returns an error if the unitary matrix is not unitary.
Sourcepub fn cnot(&self, control: usize, target: usize) -> Result<Self, Error>
pub fn cnot(&self, control: usize, target: usize) -> Result<Self, Error>
Applies the CNOT (Controlled-NOT) gate to the state vector.
§Arguments
control- The index of the control qubit.target- The index of the target qubit.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if any index is out of bounds for the state vector.
Sourcepub fn swap(&self, qubit1: usize, qubit2: usize) -> Result<Self, Error>
pub fn swap(&self, qubit1: usize, qubit2: usize) -> Result<Self, Error>
Applies the SWAP gate to the state vector.
§Arguments
qubit1- The index of the first qubit to swap.qubit2- The index of the second qubit to swap.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if any index is out of bounds for the state vector.
Sourcepub fn cswap(
&self,
target1: usize,
target2: usize,
controls: &[usize],
) -> Result<Self, Error>
pub fn cswap( &self, target1: usize, target2: usize, controls: &[usize], ) -> Result<Self, Error>
Applies the controlled SWAP gate to the state vector.
§Arguments
target1- The index of the first target qubit to swap.target2- The index of the second target qubit to swap.controls- The indices of the control qubits.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if any index is out of bounds for the state vector.
- Returns an error if target or control qubits overlap.
Sourcepub fn toffoli(
&self,
control1: usize,
control2: usize,
target: usize,
) -> Result<Self, Error>
pub fn toffoli( &self, control1: usize, control2: usize, target: usize, ) -> Result<Self, Error>
Applies the Toffoli (Controlled-Controlled-NOT) gate to the state vector.
§Arguments
control1- The index of the first control qubit.control2- The index of the second control qubit.target- The index of the target qubit.
§Returns
Result- A result containing the new state object if successful, or an error if the operation fails.
§Errors
- Returns an error if any index is out of bounds for the state vector.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnwindSafe for State
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