Skip to content

Commit

Permalink
Using alias c64 instead of Complex64 for style
Browse files Browse the repository at this point in the history
  • Loading branch information
Haadi-Khan committed Aug 6, 2024
1 parent dddaa67 commit 9c12a12
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
66 changes: 33 additions & 33 deletions src/gates/singleton.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ndarray::Array2;
use numpy::Complex64;
use numpy::Complex64 as c64;

use crate::operations::{Gate, TimeUnit};

Expand All @@ -14,10 +14,10 @@ pub fn hadamard() -> Gate {
let matrix = Array2::from_shape_vec(
(2, 2),
vec![
Complex64::new(factor, 0.0),
Complex64::new(factor, 0.0),
Complex64::new(factor, 0.0),
Complex64::new(-factor, 0.0),
c64::new(factor, 0.0),
c64::new(factor, 0.0),
c64::new(factor, 0.0),
c64::new(-factor, 0.0),
],
)
.unwrap();
Expand All @@ -28,10 +28,10 @@ pub fn x() -> Gate {
let matrix = Array2::from_shape_vec(
(2, 2),
vec![
Complex64::new(0.0, 0.0),
Complex64::new(1.0, 0.0),
Complex64::new(1.0, 0.0),
Complex64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(1.0, 0.0),
c64::new(1.0, 0.0),
c64::new(0.0, 0.0),
],
)
.unwrap();
Expand All @@ -42,10 +42,10 @@ pub fn y() -> Gate {
let matrix = Array2::from_shape_vec(
(2, 2),
vec![
Complex64::new(0.0, 0.0),
Complex64::new(0.0, -1.0),
Complex64::new(0.0, 1.0),
Complex64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, -1.0),
c64::new(0.0, 1.0),
c64::new(0.0, 0.0),
],
)
.unwrap();
Expand All @@ -56,10 +56,10 @@ pub fn z() -> Gate {
let matrix = Array2::from_shape_vec(
(2, 2),
vec![
Complex64::new(1.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(-1.0, 0.0),
c64::new(1.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(-1.0, 0.0),
],
)
.unwrap();
Expand All @@ -70,22 +70,22 @@ pub fn cx() -> Gate {
let matrix = Array2::from_shape_vec(
(4, 4),
vec![
Complex64::new(1.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(1.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(1.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(0.0, 0.0),
Complex64::new(1.0, 0.0),
Complex64::new(0.0, 0.0),
c64::new(1.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(1.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(1.0, 0.0),
c64::new(0.0, 0.0),
c64::new(0.0, 0.0),
c64::new(1.0, 0.0),
c64::new(0.0, 0.0),
],
)
.unwrap();
Expand Down
28 changes: 14 additions & 14 deletions src/operations.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use ndarray::Array2;

use numpy::Complex64;
use numpy::Complex64 as c64;
use std::fmt::Debug;

pub type TimeDependentFn = fn(f64) -> Complex64;
pub type TimeDependentFn = fn(f64) -> f64;

/// Parts of a total Hamiltonian for a gate. This breaks up terms to easily
/// determine commutativity and other properties.
#[derive(Debug, PartialEq, Clone)]
pub struct HamiltonianComponent {
time_fn: Option<TimeDependentFn>,
constant: Option<Complex64>,
operator: Array2<Complex64>,
constant: Option<c64>,
operator: Array2<c64>,
}

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct Gate {
params: Vec<f64>,
duration: Option<f64>,
unit: TimeUnit,
matrix: Array2<Complex64>,
matrix: Array2<c64>,
hamiltonian: Option<Hamiltonian>,
}

Expand All @@ -52,7 +52,7 @@ pub struct GateBuilder {
params: Option<Vec<f64>>,
duration: Option<f64>,
unit: Option<TimeUnit>,
matrix: Option<Array2<Complex64>>,
matrix: Option<Array2<c64>>,
hamiltonian: Option<Hamiltonian>,
}

Expand All @@ -77,7 +77,7 @@ impl Gate {
params: Vec<f64>,
duration: Option<f64>,
unit: TimeUnit,
matrix: Array2<Complex64>,
matrix: Array2<c64>,
hamiltonian: Option<Hamiltonian>,
) -> Self {
Gate {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl Gate {
&self.unit
}

pub fn to_matrix(&self) -> Array2<Complex64> {
pub fn to_matrix(&self) -> Array2<c64> {
self.matrix.clone()
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ impl GateBuilder {
self
}

fn matrix(mut self, matrix: Array2<Complex64>) -> Self {
fn matrix(mut self, matrix: Array2<c64>) -> Self {
self.matrix = Some(matrix);
self
}
Expand All @@ -201,8 +201,8 @@ impl GateBuilder {
impl HamiltonianComponent {
pub fn new(
time_fn: TimeDependentFn,
constant: Complex64,
operator: Array2<Complex64>,
constant: c64,
operator: Array2<c64>,
) -> Self {
HamiltonianComponent {
time_fn: Some(time_fn),
Expand All @@ -215,15 +215,15 @@ impl HamiltonianComponent {
self.time_fn.as_ref().expect("Time function not set")
}

pub fn constant(&self) -> &Complex64 {
pub fn constant(&self) -> &c64 {
self.constant.as_ref().expect("Constant not set")
}

pub fn operator(&self) -> &Array2<Complex64> {
pub fn operator(&self) -> &Array2<c64> {
&self.operator
}

pub fn calculate(&self, t: f64) -> Array2<Complex64> {
pub fn calculate(&self, t: f64) -> Array2<c64> {
let time_fn = self.time_fn.expect("Time function not set");
let constant = self.constant.expect("Constant not set");

Expand Down
4 changes: 2 additions & 2 deletions src/quantum_circuit/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use ndarray::Array2;
use numpy::Complex64;
use numpy::Complex64 as c64;

/// TODO: Migrate to a standard parser library instead of a custom one (didn't realized these existed before lol)
Expand Down Expand Up @@ -29,7 +29,7 @@ macro_rules! insert_gates {
pub struct Parser {
tokens: Vec<Token>,
pos: usize,
mtx_map: HashMap<String, Array2<Complex64>>,
mtx_map: HashMap<String, Array2<c64>>,
}

impl Parser {
Expand Down

0 comments on commit 9c12a12

Please sign in to comment.