Gate

Struct Gate 

Source
pub struct Gate<T> {
    pub name: String,
    pub matrix: Array2<Complex<T>>,
}
Expand description

Represents a quantum gate with a name and unitary matrix representation.

§Type Parameters

  • T: Floating-point type for the matrix elements to generate Complex<T>

§Fields

  • name: String identifier for the gate
  • matrix: Unitary matrix representing the gate operation (2D array of complex numbers)

§Examples

use quantum_sim::gates::Gate;
use num_complex::Complex;
use num_traits::{One, Zero};
use ndarray::arr2;

let gate = Gate::<f64>::new("Custom".to_string(), arr2(&[[Complex::one(), Complex::zero()],
                                                 [Complex::zero(), Complex::one()]]));

Fields§

§name: String§matrix: Array2<Complex<T>>

Implementations§

Source§

impl<T> Gate<T>
where T: Float + FromPrimitive + Copy + PartialOrd + LowerExp + 'static,

Source

pub fn new(name: String, matrix: Array2<Complex<T>>) -> Result<Self, String>

Creates a new quantum gate with the given name and matrix.

§Arguments
  • name - String identifier for the gate
  • matrix - Unitary matrix representing the gate operation
§Panics

The caller must ensure the matrix is unitary. This is checked internally.

§Examples
use quantum_sim::gates::Gate;
use ndarray::arr2;
use num_complex::Complex;
use num_traits::{One, Zero};

let matrix = arr2(&[[Complex::one(), Complex::zero()],
                    [Complex::zero(), Complex::one()]]);
let identity = Gate::<f64>::new("Identity".to_string(), matrix);
Source

pub fn i() -> Self

Creates an Identity gate (I).

§Examples
use quantum_sim::gates::Gate;

let i_gate = Gate::<f64>::i();
Source

pub fn x() -> Self

Creates a Pauli-X gate (NOT gate).

§Examples
use quantum_sim::gates::Gate;

let x_gate = Gate::<f64>::x();
assert_eq!(x_gate.name, "X");
Source

pub fn y() -> Self

Creates a Pauli-Y gate.

§Examples
use quantum_sim::gates::Gate;

let y_gate = Gate::<f64>::y();
assert_eq!(y_gate.name, "Y");
Source

pub fn z() -> Self

Creates a Pauli-Z gate.

§Examples
use quantum_sim::gates::Gate;

let z_gate = Gate::<f64>::z();
assert_eq!(z_gate.name, "Z");
Source

pub fn h() -> Self

Creates a Hadamard gate (H).

The Hadamard gate creates superposition states. Matrix representation:

[1/sqrt(2)  1/sqrt(2)]
[1/sqrt(2) -1/sqrt(2)]
§Examples
use quantum_sim::gates::Gate;

let h_gate = Gate::<f64>::h();
assert_eq!(h_gate.name, "H");
Source

pub fn s() -> Self

Creates a Phase gate (S gate).

The Phase gate introduces a π/2 phase shift. Matrix representation:

[1 0]
[0 i]
§Examples
use quantum_sim::gates::Gate;

let s_gate = Gate::<f64>::s();
assert_eq!(s_gate.name, "S");
Source

pub fn t() -> Self

Creates a T gate (π/8 gate).

The T gate introduces a π/4 phase shift. Matrix representation:

[1 0]
[0 e^(iπ/4)]
§Examples
use quantum_sim::gates::Gate;

let t_gate = Gate::<f64>::t();
assert_eq!(t_gate.name, "T");
Source

pub fn cnot() -> Self

Creates a Controlled-NOT gate (CNOT).

The CNOT gate flips the target qubit if the control qubit is |1⟩. Matrix representation:

[1 0 0 0]
[0 1 0 0]
[0 0 0 1]
[0 0 1 0]
§Examples
use quantum_sim::gates::Gate;

let cnot_gate = Gate::<f64>::cnot();
assert_eq!(cnot_gate.name, "CNOT");

Trait Implementations§

Source§

impl<T: Clone> Clone for Gate<T>

Source§

fn clone(&self) -> Gate<T>

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<T: Debug> Debug for Gate<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Gate<T>

§

impl<T> RefUnwindSafe for Gate<T>
where T: RefUnwindSafe,

§

impl<T> Send for Gate<T>
where T: Send,

§

impl<T> Sync for Gate<T>
where T: Sync,

§

impl<T> Unpin for Gate<T>

§

impl<T> UnwindSafe for Gate<T>
where T: RefUnwindSafe,

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

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