From 9c12a12b48dad1c609b4380f862b44934942b47b Mon Sep 17 00:00:00 2001 From: Haadi Khan Date: Tue, 6 Aug 2024 19:44:54 -0400 Subject: [PATCH] Using alias c64 instead of Complex64 for style --- src/gates/singleton.rs | 66 +++++++++++++++++------------------ src/operations.rs | 28 +++++++-------- src/quantum_circuit/parser.rs | 4 +-- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/gates/singleton.rs b/src/gates/singleton.rs index f417805..3efc2ce 100644 --- a/src/gates/singleton.rs +++ b/src/gates/singleton.rs @@ -1,5 +1,5 @@ use ndarray::Array2; -use numpy::Complex64; +use numpy::Complex64 as c64; use crate::operations::{Gate, TimeUnit}; @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/src/operations.rs b/src/operations.rs index 83fa4e9..dff24bc 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -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, - constant: Option, - operator: Array2, + constant: Option, + operator: Array2, } #[derive(Debug, PartialEq, Clone)] @@ -41,7 +41,7 @@ pub struct Gate { params: Vec, duration: Option, unit: TimeUnit, - matrix: Array2, + matrix: Array2, hamiltonian: Option, } @@ -52,7 +52,7 @@ pub struct GateBuilder { params: Option>, duration: Option, unit: Option, - matrix: Option>, + matrix: Option>, hamiltonian: Option, } @@ -77,7 +77,7 @@ impl Gate { params: Vec, duration: Option, unit: TimeUnit, - matrix: Array2, + matrix: Array2, hamiltonian: Option, ) -> Self { Gate { @@ -118,7 +118,7 @@ impl Gate { &self.unit } - pub fn to_matrix(&self) -> Array2 { + pub fn to_matrix(&self) -> Array2 { self.matrix.clone() } } @@ -176,7 +176,7 @@ impl GateBuilder { self } - fn matrix(mut self, matrix: Array2) -> Self { + fn matrix(mut self, matrix: Array2) -> Self { self.matrix = Some(matrix); self } @@ -201,8 +201,8 @@ impl GateBuilder { impl HamiltonianComponent { pub fn new( time_fn: TimeDependentFn, - constant: Complex64, - operator: Array2, + constant: c64, + operator: Array2, ) -> Self { HamiltonianComponent { time_fn: Some(time_fn), @@ -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 { + pub fn operator(&self) -> &Array2 { &self.operator } - pub fn calculate(&self, t: f64) -> Array2 { + pub fn calculate(&self, t: f64) -> Array2 { let time_fn = self.time_fn.expect("Time function not set"); let constant = self.constant.expect("Constant not set"); diff --git a/src/quantum_circuit/parser.rs b/src/quantum_circuit/parser.rs index 878089a..05c1be4 100644 --- a/src/quantum_circuit/parser.rs +++ b/src/quantum_circuit/parser.rs @@ -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) @@ -29,7 +29,7 @@ macro_rules! insert_gates { pub struct Parser { tokens: Vec, pos: usize, - mtx_map: HashMap>, + mtx_map: HashMap>, } impl Parser {