From a8c7119ed85da642195f007738f478e63545c65c Mon Sep 17 00:00:00 2001 From: Haadi Khan Date: Thu, 31 Oct 2024 14:21:48 -0400 Subject: [PATCH] Reorganized Project Layout & Updated lib.rs --- src/braiding.rs | 2 +- src/braiding/braiding.rs | 6 +-- src/fusion/fusion.rs | 6 +-- src/lib.rs | 22 ++++------- src/state.rs | 56 --------------------------- src/util.rs | 3 +- src/{ => util}/anyon.rs | 0 src/util/basis.rs | 3 +- src/util/{statevec.rs => state.rs} | 61 ++++++++++++++++++++++++++++-- 9 files changed, 75 insertions(+), 84 deletions(-) delete mode 100644 src/state.rs rename src/{ => util}/anyon.rs (100%) rename src/util/{statevec.rs => state.rs} (67%) diff --git a/src/braiding.rs b/src/braiding.rs index ebee08a..71fb4b0 100644 --- a/src/braiding.rs +++ b/src/braiding.rs @@ -1 +1 @@ -mod braiding; +pub mod braiding; diff --git a/src/braiding/braiding.rs b/src/braiding/braiding.rs index 5321b8c..2971caa 100644 --- a/src/braiding/braiding.rs +++ b/src/braiding/braiding.rs @@ -2,12 +2,12 @@ use crate::util::math::c64; use nalgebra::DMatrix; use pyo3::prelude::*; -use crate::state::State; +use crate::util::state::State; /// A braid is a sequence of swaps that can be applied to a state. A sequence of /// braids is analogous to a gate in a quantum circuit for TQC. #[pyclass] -struct Braid { +pub struct Braid { #[pyo3(get)] state: State, #[pyo3(get)] @@ -18,7 +18,7 @@ struct Braid { impl Braid { // TODO: Write swap - // TODO: Write swap_to_qubit + // TODO: Write swap_to_qubit // TODO: Write swap_mtx diff --git a/src/fusion/fusion.rs b/src/fusion/fusion.rs index 9f3a61d..0763ea6 100644 --- a/src/fusion/fusion.rs +++ b/src/fusion/fusion.rs @@ -1,9 +1,7 @@ use std::collections::HashMap; - use pyo3::prelude::*; - -use crate::anyon::TopoCharge; -use crate::state::State; +use crate::util::anyon::TopoCharge; +use crate::util::state::State; /// We represent an anyon's topological charge as a triple of usizes. The values /// serve as the combinatoric labels for the various states. diff --git a/src/lib.rs b/src/lib.rs index 76f1eff..c86c37c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,6 @@ -mod anyon; mod braiding; mod fusion; mod gates; -mod state; mod util; use pyo3::prelude::*; @@ -11,20 +9,16 @@ use pyo3::prelude::*; /// here following the same format #[pymodule] fn tqc_emu(m: &Bound<'_, PyModule>) -> PyResult<()> { - // m.add_class::()?; - // m.add_class::()?; - // m.add_class::()?; - // m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; - // m.add_class::()?; - // m.add_class::()?; + m.add_class::()?; + m.add_class::()?; - // m.add_class::()?; - // m.add_class::()?; + m.add_class::()?; - // m.add_class::()?; - - // m.add_class::()?; - // m.add_class::()?; Ok(()) } diff --git a/src/state.rs b/src/state.rs deleted file mode 100644 index 397b0e4..0000000 --- a/src/state.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::{anyon::Anyon, fusion::fusion::FusionPair, util::statevec::StateVec}; -use pyo3::prelude::*; - -/// In the fusion tree, each node is a tuple with an associated time and fusion -/// event. We use this type to represent the elements in the fusion tree. -pub type FusionNode = (u32, FusionPair); - -#[pyclass] -#[derive(Clone, Debug, PartialEq)] -/// State is the overall state of our system. It stores everything to fully -/// describe an anyon system and its associated operations. -pub struct State { - #[pyo3(get)] - anyons: Vec, - #[pyo3(get)] - fusion_ops: Vec, - // TODO: Add braiding - // #[pyo3(get)] - // braiding_ops: Vec, - #[pyo3(get)] - state_vec: StateVec, -} - -impl State { - pub fn anyons(&self) -> Vec { - self.anyons.clone() - } - - pub fn fusion_ops(&self) -> Vec { - self.fusion_ops.clone() - } -} - - -/// Python Methods -#[pymethods] -impl State { - #[new] - fn new() -> Self { - State { - anyons: Vec::new(), - fusion_ops: Vec::new(), - state_vec: StateVec::new(1, None), - } - } - - /// Add an anyon to the state - fn add_anyon(&mut self, anyon: Anyon) -> PyResult { - self.anyons.push(anyon); - Ok(true) - } - - // TODO: Add braiding - - // TODO: Create a method for adding an operation (and verifying it with an internal method) -} diff --git a/src/util.rs b/src/util.rs index 2c87425..11d43ec 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,3 +1,4 @@ +pub mod anyon; pub mod math; pub mod basis; -pub mod statevec; +pub mod state; diff --git a/src/anyon.rs b/src/util/anyon.rs similarity index 100% rename from src/anyon.rs rename to src/util/anyon.rs diff --git a/src/util/basis.rs b/src/util/basis.rs index 06bc403..64ef28e 100644 --- a/src/util/basis.rs +++ b/src/util/basis.rs @@ -1,6 +1,7 @@ use pyo3::prelude::*; use std::collections::HashSet; -use crate::state::FusionNode; + +use super::state::FusionNode; #[pyclass] #[derive(Clone, Debug, PartialEq)] diff --git a/src/util/statevec.rs b/src/util/state.rs similarity index 67% rename from src/util/statevec.rs rename to src/util/state.rs index 40063cb..a0225f9 100644 --- a/src/util/statevec.rs +++ b/src/util/state.rs @@ -1,7 +1,14 @@ +use super::anyon::Anyon; +use crate::fusion::fusion::FusionPair; +use pyo3::prelude::*; + +use crate::util::math::c64; use nalgebra::{base::DVector, DMatrix}; use numpy::{PyArray1, PyReadonlyArray1, ToPyArray}; -use crate::util::math::c64; -use pyo3::prelude::*; + +/// In the fusion tree, each node is a tuple with an associated time and fusion +/// event. We use this type to represent the elements in the fusion tree. +pub type FusionNode = (u32, FusionPair); #[pyclass] #[derive(Clone, Debug, PartialEq)] @@ -12,7 +19,22 @@ pub struct StateVec { init_size: usize, } -/// Internal Methods +#[pyclass] +#[derive(Clone, Debug, PartialEq)] +/// State is the overall state of our system. It stores everything to fully +/// describe an anyon system and its associated operations. +pub struct State { + #[pyo3(get)] + anyons: Vec, + #[pyo3(get)] + fusion_ops: Vec, + // TODO: Add braiding + // #[pyo3(get)] + // braiding_ops: Vec, + #[pyo3(get)] + state_vec: StateVec, +} + impl StateVec { /// Returns a clone of the state vector pub fn get_vec(&self) -> DVector { @@ -32,7 +54,38 @@ impl StateVec { } } -/// Python Methods +impl State { + pub fn anyons(&self) -> Vec { + self.anyons.clone() + } + + pub fn fusion_ops(&self) -> Vec { + self.fusion_ops.clone() + } +} + +#[pymethods] +impl State { + #[new] + fn new() -> Self { + State { + anyons: Vec::new(), + fusion_ops: Vec::new(), + state_vec: StateVec::new(1, None), + } + } + + /// Add an anyon to the state + fn add_anyon(&mut self, anyon: Anyon) -> PyResult { + self.anyons.push(anyon); + Ok(true) + } + + // TODO: Add braiding + + // TODO: Create a method for adding an operation (and verifying it with an internal method) +} + #[pymethods] impl StateVec { #[new]