Skip to content

Commit

Permalink
Reorganized Project Layout & Updated lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Haadi-Khan committed Oct 31, 2024
1 parent 9c62646 commit a8c7119
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/braiding.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod braiding;
pub mod braiding;
6 changes: 3 additions & 3 deletions src/braiding/braiding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions src/fusion/fusion.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
22 changes: 8 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod anyon;
mod braiding;
mod fusion;
mod gates;
mod state;
mod util;
use pyo3::prelude::*;

Expand All @@ -11,20 +9,16 @@ use pyo3::prelude::*;
/// here following the same format
#[pymodule]
fn tqc_emu(m: &Bound<'_, PyModule>) -> PyResult<()> {
// m.add_class::<model::anyon::Anyon>()?;
// m.add_class::<model::anyon::IsingTopoCharge>()?;
// m.add_class::<model::anyon::FibonacciTopoCharge>()?;
// m.add_class::<model::anyon::TopoCharge>()?;
m.add_class::<util::anyon::Anyon>()?;
m.add_class::<util::anyon::TopoCharge>()?;
m.add_class::<util::basis::Basis>()?;
m.add_class::<util::state::StateVec>()?;
m.add_class::<util::state::State>()?;

// m.add_class::<model::model::Model>()?;
// m.add_class::<model::model::AnyonModel>()?;
m.add_class::<fusion::fusion::Fusion>()?;
m.add_class::<fusion::fusion::FusionPair>()?;

// m.add_class::<fusion::fusion::Fusion>()?;
// m.add_class::<fusion::fusion::FusionPair>()?;
m.add_class::<braiding::braiding::Braid>()?;

// m.add_class::<fusion::state::State>()?;

// m.add_class::<util::basis::Basis>()?;
// m.add_class::<util::statevec::StateVec>()?;
Ok(())
}
56 changes: 0 additions & 56 deletions src/state.rs

This file was deleted.

3 changes: 2 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod anyon;
pub mod math;
pub mod basis;
pub mod statevec;
pub mod state;
File renamed without changes.
3 changes: 2 additions & 1 deletion src/util/basis.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use pyo3::prelude::*;
use std::collections::HashSet;
use crate::state::FusionNode;

use super::state::FusionNode;

#[pyclass]
#[derive(Clone, Debug, PartialEq)]
Expand Down
61 changes: 57 additions & 4 deletions src/util/statevec.rs → src/util/state.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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<Anyon>,
#[pyo3(get)]
fusion_ops: Vec<FusionNode>,
// TODO: Add braiding
// #[pyo3(get)]
// braiding_ops: Vec<FusionNode>,
#[pyo3(get)]
state_vec: StateVec,
}

impl StateVec {
/// Returns a clone of the state vector
pub fn get_vec(&self) -> DVector<c64> {
Expand All @@ -32,7 +54,38 @@ impl StateVec {
}
}

/// Python Methods
impl State {
pub fn anyons(&self) -> Vec<Anyon> {
self.anyons.clone()
}

pub fn fusion_ops(&self) -> Vec<FusionNode> {
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<bool> {
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]
Expand Down

0 comments on commit a8c7119

Please sign in to comment.