Enum quantr::Gate

source ·
pub enum Gate<'a> {
Show 25 variants Id, H, X, Y, Z, S, Sdag, T, Tdag, Rx(f64), Ry(f64), Rz(f64), X90, Y90, MX90, MY90, Phase(f64), CR(f64, usize), CRk(i32, usize), CZ(usize), CY(usize), CNot(usize), Swap(usize), Toffoli(usize, usize), Custom(fn(_: ProductState) -> Option<SuperPosition>, &'a [usize], String),
}
Expand description

Gates that can be added to a crate::Circuit struct.

Matrix representations of these gates can be found at https://www.quantum-inspire.com/kbase/cqasm-qubit-gate-operations/.

Variants§

§

Id

Identity.

§

H

Hadamard.

§

X

Pauli-X.

§

Y

Pauli-Y.

§

Z

Pauli-Z.

§

S

Phase, rotation of +π/2 around the z-axis.

§

Sdag

Phase dagger, rotation of -π/2 around the z-axis.

§

T

T.

§

Tdag

T dagger.

§

Rx(f64)

Rotation around x-axis, with angle.

§

Ry(f64)

Rotation around y-axis, with angle.

§

Rz(f64)

Rotation around z-axis, with angle.

§

X90

Rotation of +π/2 around x-axis.

§

Y90

Rotation of +π/2 around y-axis.

§

MX90

Rotation of -π/2 around x-axis.

§

MY90

Rotation of -π/2 around y-axis.

§

Phase(f64)

Global phase, exp(i*theta/2) * Identity, with angle.

§

CR(f64, usize)

Controlled phase shift, with rotation and position of control node respectively.

§

CRk(i32, usize)

Controlled phase shift for Quantum Fourier Transforms, with rotation and position of control node respectively.

§

CZ(usize)

Controlled Pauli-Z, with position of control node.

§

CY(usize)

Controlled Pauli-Y, with position of control node.

§

CNot(usize)

Controlled Not, with position of control node.

§

Swap(usize)

Swap, with position of control node.

§

Toffoli(usize, usize)

Toffoli, with position of control nodes.

§

Custom(fn(_: ProductState) -> Option<SuperPosition>, &'a [usize], String)

Defines a custom gate.

Note, that the custom function isn’t checked for unitarity.

The arguments define the mapping of the gate; the position of the control node and a name that will be displayed in the printed diagram respectively. The name of the custom gate should be in ASCII for it to render properly when printing the circuit diagram.

§Example

use quantr::{Circuit, Gate};
use quantr::states::{SuperPosition, ProductState, Qubit};
use quantr::{Complex, complex_re_array};

// Defines a C-Not gate
fn example_cnot(prod: ProductState) -> Option<SuperPosition> {
   let input_register: [Qubit; 2] = [prod.get_qubits()[0], prod.get_qubits()[0]];
   Some(SuperPosition::new_with_amplitudes(match input_register {
       [Qubit::Zero, Qubit::Zero] => return None,
       [Qubit::Zero, Qubit::One]  => return None,
       [Qubit::One, Qubit::Zero]  => &complex_re_array!(0f64, 0f64, 0f64, 1f64),
       [Qubit::One, Qubit::One]   => &complex_re_array!(0f64, 0f64, 1f64, 0f64),
   }).unwrap())
}

let mut quantum_circuit = Circuit::new(3).unwrap();
quantum_circuit.add_gate(Gate::Custom(example_cnot, &[2], String::from("X")), 1).unwrap();

// This is equivalent to
quantum_circuit.add_gate(Gate::CNot(2), 1).unwrap();

Trait Implementations§

source§

impl<'a> Clone for Gate<'a>

source§

fn clone(&self) -> Gate<'a>

Returns a copy 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<'a> Debug for Gate<'a>

source§

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

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

impl<'a> PartialEq for Gate<'a>

source§

fn eq(&self, other: &Gate<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> StructuralPartialEq for Gate<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Gate<'a>

§

impl<'a> RefUnwindSafe for Gate<'a>

§

impl<'a> Send for Gate<'a>

§

impl<'a> Sync for Gate<'a>

§

impl<'a> Unpin for Gate<'a>

§

impl<'a> UnwindSafe for Gate<'a>

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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.