pub struct Unitary2 { /* private fields */ }Expand description
An arbitrary 2×2 unitary operator.
This operator can be applied to a single qubit in a quantum state. It is represented by a 2×2 unitary matrix. The matrix must be unitary. The operator can be constructed fallibly from a 2 x 2 unitary matrix, or infallibly from a rotation angle and phase shift angle.
Implementations§
Source§impl Unitary2
impl Unitary2
Sourcepub fn new(matrix: [[Complex<f64>; 2]; 2]) -> Result<Self, Error>
pub fn new(matrix: [[Complex<f64>; 2]; 2]) -> Result<Self, Error>
Creates a new Unitary2 operator with the given 2×2 unitary matrix.
§Arguments:
matrix- A 2×2 unitary matrix represented as a 2D array of complex numbers.
§Returns:
Result<Self, Error>- A result containing the new Unitary2 operator or an error if the matrix is not unitary.
§Errors:
Error::NonUnitaryMatrix- If the provided matrix is not unitary.
Sourcepub fn from_ry_phase(theta: f64, phi: f64) -> Self
pub fn from_ry_phase(theta: f64, phi: f64) -> Self
Creates a new Unitary2 operator from a rotation angle theta and phase shift angle phi. This operator can be decomposed into a rotation around the Y axis followed by a phase shift. The enclosed unitary matrix is guaranteed to be unitary.
Special cases include:
- U(theta, 0) = RY(theta)
- U(0, phi) = PhaseShift(phi)
- U(Pi/2, Pi) = Hadamard
- U(Pi, Pi) = Pauli-X
§Arguments:
-
theta- The rotation angle in radians. -
phi- The phase shift angle in radians
§Returns:
Self- A new Unitary2 operator representing the rotation and phase shift.
Sourcepub fn from_ry_phase_dagger(theta: f64, phi: f64) -> Self
pub fn from_ry_phase_dagger(theta: f64, phi: f64) -> Self
Creates a new Unitary2 operator from a rotation angle theta and phase shift angle phi. This operator can be decomposed into a phase shift followed by a rotation around the Y axis. The enclosed unitary matrix is guaranteed to be unitary.
This is the adjoint of the ry_phase operator.
§Arguments:
-
theta- The rotation angle in radians. -
phi- The phase shift angle in radians.
§Returns:
Self- A new Unitary2 operator representing the phase shift and rotation.
Trait Implementations§
Source§impl Operator for Unitary2
impl Operator for Unitary2
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 Unitary2 operator to the given state’s target qubit.
§Arguments:
-
state- The state to apply the operator to. -
target_qubits- The target qubits to apply the operator to. This should be a single qubit. -
control_qubits- The control qubits for the operator. If not empty, the operator will be applied conditionally based on the control qubits. Otherwise, it will be applied unconditionally.
§Returns:
- The new state after applying the Unitary2 operator.
Source§fn base_qubits(&self) -> usize
fn base_qubits(&self) -> usize
Source§fn to_compilable(&self) -> Option<&dyn Compilable>
fn to_compilable(&self) -> Option<&dyn Compilable>
impl Copy for Unitary2
Auto Trait Implementations§
impl Freeze for Unitary2
impl RefUnwindSafe for Unitary2
impl Send for Unitary2
impl Sync for Unitary2
impl Unpin for Unitary2
impl UnwindSafe for Unitary2
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