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 generateComplex<T>
§Fields
name: String identifier for the gatematrix: 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>
impl<T> Gate<T>
Sourcepub fn new(name: String, matrix: Array2<Complex<T>>) -> Result<Self, String>
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 gatematrix- 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);Sourcepub fn i() -> Self
pub fn i() -> Self
Creates an Identity gate (I).
§Examples
use quantum_sim::gates::Gate;
let i_gate = Gate::<f64>::i();Sourcepub fn x() -> Self
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");Sourcepub fn y() -> Self
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");Sourcepub fn z() -> Self
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");Sourcepub fn h() -> Self
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");Sourcepub fn s() -> Self
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");Sourcepub fn t() -> Self
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");Sourcepub fn cnot() -> Self
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§
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> 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
Mutably borrows from an owned value. Read more