pub struct SWAP;Expand description
Defines a SWAP operator.
A two-qubit operator that swaps the states of the two qubits.
Trait Implementations§
Source§impl Operator for SWAP
impl Operator for SWAP
Source§fn apply(
&self,
state: &State,
target_qubits: &[usize],
control_qubits: &[usize],
) -> Result<State, Error>
fn apply( &self, state: &State, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<State, Error>
Applies the SWAP operator to the given state’s target qubits.
§Arguments:
-
state- The state to apply the operator to. -
target_qubits- The target qubits to apply the operator to. This should be two qubits. -
control_qubits- The control qubits. If empty, the swap is unconditional. Otherwise, the swap occurs only if all control qubits are |1> for the relevant basis states.
§Returns:
- The new state after applying the SWAP operator.
§Errors:
-
Error::InvalidNumberOfQubits- If the target qubits are not 2 different qubits. -
Error::InvalidQubitIndex- If the target qubit indices are invalid for the number of qubits in the state. -
Error::InvalidQubitIndex- If the target qubit indices are not different. -
Error::OverlappingControlAndTargetQubits- If the control qubit and target qubit indices overlap.
Source§fn base_qubits(&self) -> usize
fn base_qubits(&self) -> usize
impl Copy for SWAP
Auto Trait Implementations§
impl Freeze for SWAP
impl RefUnwindSafe for SWAP
impl Send for SWAP
impl Sync for SWAP
impl Unpin for SWAP
impl UnwindSafe for SWAP
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