State

Struct State 

Source
pub struct State {
    pub state_vector: Vec<Complex<f64>>,
    pub num_qubits: usize,
}
Expand description

Represents the state of a quantum register.

The state is represented as a complex vector, where each element corresponds to a probability amplitude for a particular basis state. The number of qubits in the system is also stored, which determines the length of the state vector (2^num_qubits).

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: usize

The number of qubits in the system.

Implementations§

Source§

impl State

Source

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).
Source

pub fn new_hartree_fock( num_electrons: usize, num_orbitals: usize, ) -> Result<Self, Error>

Creates a new Hartree-Fock state object with the given number of electrons and orbitals.

§Arguments
  • num_electrons - The number of electrons in the system.

  • num_orbitals - The number of orbitals in the system.

§Returns
  • state - A result containing the state object if successful, or an error if the input is invalid.
Source

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.
Source

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 the n-th basis state or an error if n is out of bounds or if the number of qubits is invalid.
§Errors
  • Returns an error if the number of qubits is 0 or if n is out of bounds for the given number of qubits.
Source

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.
Source

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.
Source

pub fn new_ghz(num_qubits: usize) -> Result<Self, Error>

Creates a new Greenberger–Horne–Zeilinger state object with the given number of qubits initialised to the |GHZ> state. The GHZ state is the maximally entangled state 1/sqrt(2) * (|0…0> + |1…1>).

§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 |GHZ> state or an error if the number of qubits is invalid.
§Errors
  • Returns an error if the number of qubits is 0.
Source

pub fn new_phi_plus() -> Self

Creates a new two-qubit Phi plus Bell state |Φ+⟩.

§Returns
  • Self - A new instance of the two-qubit Bell state |Φ+⟩.
Source

pub fn new_phi_minus() -> Self

Creates a new two-qubit Phi minus Bell state |Φ-⟩.

§Returns
  • Self - A new instance of the two-qubit Bell state |Φ-⟩.
Source

pub fn new_psi_plus() -> Self

Creates a new two-qubit Psi plus Bell state |Ψ+⟩.

§Returns
  • Self - A new instance of the two-qubit Bell state |Ψ+⟩.
Source

pub fn new_psi_minus() -> Self

Creates a new two-qubit Psi minus Bell state |Ψ-⟩.

§Returns
  • Self - A new instance of the two-qubit Bell state |Ψ-⟩.
Source

pub fn equals_without_phase(&self, other: &Self) -> bool

Checks the phase-independent equality of two states

§Arguments
  • other - The other state to compare with.
§Returns
  • true if the states are equal (ignoring phase), false otherwise.
Source

pub fn conj(&self) -> Self

Returns the Hermitian conjugate (<self|) of the state.

§Returns
  • Self - The Hermitian conjugate of the state.
Source

pub fn probability(&self, n: usize) -> Result<f64, Error>

Returns the probability of a basis state at index n in the state vector.

§Arguments
  • n - The index of the basis state to get the probability for.
§Returns
  • probability - The probability of the basis state at index n.
§Errors
  • Returns an error if n is out of bounds for the state vector.
Source

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.
Source

pub fn amplitude(&self, n: usize) -> Result<Complex<f64>, Error>

Returns the amplitude of the basis state at index n in the state vector.

§Arguments
  • n - The index of the basis state to get the amplitude for.
§Returns
  • amplitude - The amplitude of the basis state at index n.
§Errors
  • Returns an error if n is out of bounds for the state vector.
Source

pub fn fs_dist(&self, other: &Self) -> Result<f64, Error>

Returns the Fubini-Study metric distance between two normalised quantum states. Expressed as D = arccos(<Self|Other>) = arccos(F^0.5).

§Arguments
  • other - The other quantum state to compare against.
§Returns
  • distance - The Fubini-Study metric distance between the two states.
§Errors

Returns an error if the inner product calculation fails (ie. if one of the state vectors is empty, or if the dimensions do not match) Returns an error is the normalisation of either of the states fails (ie. if one of the states has zero norm).

Source

pub fn fs_fidelity(&self, other: &Self) -> Result<f64, Error>

Returns the Fubini-Study fidelity metric between two quantum states. Expressed as F = |<Self|Other>|^2 = cos^2(D).

§Arguments
  • other - The other quantum state to compare against.
§Errors

Returns an error if the inner product calculation fails (ie. if one of the state vectors is empty, or if the dimensions do not match) Returns an error if the normalisation of either of the states fails (ie. if one of the states has zero norm).

Source

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. If indices is 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.
Source

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. If indices is 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 n is 0.
Source

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.
Source

pub fn inner_product(&self, other: &Self) -> Result<Complex<f64>, Error>

Performs an inner product of two state vectors (<Self | Other>) 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.
Source

pub fn normalise(&self) -> Result<Self, Error>

Normalises the state vector and returns the state.

§Returns
  • Result<State, Error> - The resulting state after normalisation, or an error if the operation fails.
Source

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 an Operator trait 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.

Source

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.
Source

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.

Source

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.

Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.

Source

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.

Source

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.

Source

pub fn ry_phase( &self, index: usize, angle: f64, phase: f64, ) -> Result<Self, Error>

Applies the Unitary (constructed from rotation angle and phase shift) to the specified qubit in the state vector.

§Arguments
  • index - The index of the qubit to apply the Unitary gate to.

  • angle - The rotation angle in radians.

  • phase - 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.
Source

pub fn ry_phase_multi( &self, qubits: &[usize], angle: f64, phase: f64, ) -> Result<Self, Error>

Applies the Unitary (constructed from rotation angle and phase shift) 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.

  • angle - The rotation angle in radians.

  • phase - 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.

Source

pub fn cry_phase_gates( &self, target_qubits: &[usize], control_qubits: &[usize], angle: f64, phase: f64, ) -> Result<Self, Error>

Applies the controlled Unitary (constructed from rotation angle and phase shift) 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.

  • angle - The rotation angle in radians.

    • phase - 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.

Source

pub fn ry_phase_dag( &self, qubit: usize, angle: f64, phase: f64, ) -> Result<Self, Error>

Applies the Unitary (constructed from rotation angle and phase shift) to the specified qubit in the state vector. This is the adjoint of the ry_phase operation.

§Arguments
  • qubit - The index of the qubit to apply the adjoint operation to.

  • angle - The rotation angle in radians.

  • phase - 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 target qubit is out of bounds for the state vector
Source

pub fn ry_phase_dag_multi( &self, qubits: &[usize], angle: f64, phase: f64, ) -> Result<Self, Error>

Applies the Unitary (constructed from rotation angle and phase shift) to the specified qubits in the state vector in the given order. This is the adjoint of the ry_phase operation.

§Arguments
  • qubits - The indices of the qubits to apply the adjoint ry_phase operation to.

  • angle - The rotation angle in radians.

  • phase - 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.

Source

pub fn cry_phase_dag_gates( &self, target_qubits: &[usize], control_qubits: &[usize], angle: f64, phase: f64, ) -> Result<Self, Error>

Applies the controlled Unitary (constructed from rotation angle and phase shift) to the specified qubits in the state vector in the given order. This is the controlled adjoint of the ry_phase operation.

§Arguments
  • target_qubits - The index of the target qubit.

  • control_qubits - The indices of the control qubits.

  • angle - The rotation angle in radians.

  • phase - 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.

Source

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.
Source

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.
Source

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.
Source

pub fn matchgate( &self, target: usize, theta: f64, phi1: f64, phi2: f64, ) -> Result<State, Error>

Applies the Matchgate to the state vector

§Arguments
  • target - The index of the first target qubit. The second target qubit is automatically determined to be the next qubit.
  • theta - The rotation angle in radians
  • phi1 - The first phase angle in radians
  • phi2 - The second phase 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 any index is out of bounds for the state vector.
  • Returns an error if target or control qubits overlap.
Source

pub fn cmatchgate( &self, target: usize, theta: f64, phi1: f64, phi2: f64, controls: &[usize], ) -> Result<State, Error>

Applies the controlled Matchgate to the state vector

§Arguments
  • target - The index of the first target qubit. The second target qubit is automatically determined to be the next qubit.
  • theta - The rotation angle in radians
  • phi1 - The first phase angle in radians
  • phi2 - The second phase angle in radians
  • 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.
Source

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§

Source§

impl Add for State

Source§

fn add(self, rhs: State) -> Self::Output

Adds two state vectors element-wise. Panics if the states do not have the same number of qubits. Note: This operation typically results in an unnormalised state.

Source§

type Output = State

The resulting type after applying the + operator.
Source§

impl Clone for State

Source§

fn clone(&self) -> State

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Mul<Complex<f64>> for State

Source§

fn mul(self, rhs: Complex<f64>) -> Self::Output

Multiplies each amplitude in the state vector by a complex scalar. Note: This operation typically results in an unnormalised state.

Source§

type Output = State

The resulting type after applying the * operator.
Source§

impl Mul<State> for Complex<f64>

Source§

fn mul(self, rhs: State) -> Self::Output

Multiplies each amplitude in the state vector by a complex scalar from the left. Note: This operation typically results in an unnormalised state.

Source§

type Output = State

The resulting type after applying the * operator.
Source§

impl Mul<State> for f64

Source§

fn mul(self, rhs: State) -> Self::Output

Multiplies each amplitude in the state vector by a real scalar from the left. Note: This operation typically results in an unnormalised state.

Source§

type Output = State

The resulting type after applying the * operator.
Source§

impl Mul<f64> for State

Source§

fn mul(self, rhs: f64) -> Self::Output

Multiplies each amplitude in the state vector by a real scalar. Note: This operation typically results in an unnormalised state.

Source§

type Output = State

The resulting type after applying the * operator.
Source§

impl PartialEq for State

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for State

Source§

fn sub(self, rhs: State) -> Self::Output

Subtracts the right-hand state vector from the left-hand state vector element-wise. Panics if the states do not have the same number of qubits. Note: This operation typically results in an unnormalised state.

Source§

type Output = State

The resulting type after applying the - operator.
Source§

impl Sum for State

Source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = Self>,

Takes an iterator and generates Self from the elements by “summing up” the items.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V