Skip to content

Commit

Permalink
mwpm_2d stub
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranra committed Jan 9, 2025
1 parent 19f085b commit b21bd3e
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 26 deletions.
24 changes: 18 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pyo3 = "0.23"
rand = "0.8"
rand_chacha = "0.3"
rand_xoshiro = "0.6"
petgraph = "0.7"

pecos-core = { version = "0.1.1", path = "crates/pecos-core" }
pecos-qsim = { version = "0.1.1", path = "crates/pecos-qsim" }
Expand Down
3 changes: 3 additions & 0 deletions crates/pecos-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
// or implied. See the License for the specific language governing permissions and limitations under
// the License.

pub mod qubit_id;
mod sets;
mod sims_rngs;
mod stabilizer_code;

pub use qubit_id::QubitId;
pub use sets::element::{Element, IndexableElement};
pub use sets::set::Set;
pub use sets::vec_set::VecSet;
Expand Down
14 changes: 14 additions & 0 deletions crates/pecos-core/src/qubit_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2025 The PECOS Developers
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under
// the License.

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct QubitId(pub usize);
13 changes: 13 additions & 0 deletions crates/pecos-core/src/stabilizer_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::qubit_id::QubitId;

pub trait StabilizerCode {
fn num_data_qubits(&self) -> usize;

// Get a vector of the stabilizer generators used for the code.
// Todo: Utilize PauliSet when available
fn get_stabilizer_gens(&self) -> Vec<Vec<(usize, QubitId)>>;

// Get the boundaries of the code
// TODO: Consider adding identifiers to identify the boundary types
fn get_boundaries(&self) -> Vec<Vec<QubitId>>;
}
17 changes: 0 additions & 17 deletions crates/pecos-decoders/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion crates/pecos-decoders/src/lib.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/pecos-qec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ categories.workspace = true
description = "QEC for Rust PECOS."

[dependencies]
pecos-qsim = { workspace = true }
pecos-decoders = { workspace = true}
petgraph = { workspace = true }
pecos-core = { workspace = true }

[lints]
workspace = true
1 change: 1 addition & 0 deletions crates/pecos-qec/src/decoders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod mwpm_2d;
62 changes: 62 additions & 0 deletions crates/pecos-qec/src/decoders/mwpm_2d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use pecos_core::QubitId;
use petgraph::graph::NodeIndex;
use petgraph::Graph;
use std::collections::HashMap;

// Recreate pecos/decoders/mwpm2d/{mwpm2d/py, precomputing.py}

#[derive(Debug)]
pub struct PrecomputedData {
x_graph: Graph<(), f64>,
z_graph: Graph<(), f64>,
virtual_edges: HashMap<NodeIndex, VirtualEdgeData>,
edge_to_data: HashMap<(NodeIndex, NodeIndex), QubitId>,
}

#[derive(Debug)]
pub struct VirtualEdgeData {
pub virtual_node: NodeIndex,
pub weight: f64,
pub syndrome_path: Vec<NodeIndex>,
pub data_path: Vec<QubitId>,
}

struct Syndrome {}
struct Recovery {}
struct SurfaceCode {}

// #[derive(Debug)]
pub struct MWPM2DDecoder {
precomputed: PrecomputedData,
cached_recoveries: HashMap<Vec<Syndrome>, Recovery>,
}

impl MWPM2DDecoder {
pub fn new(code: &SurfaceCode) -> Self {
let precomputed = Self::precompute(code);
Self {
precomputed,
cached_recoveries: HashMap::new(),
}
}

fn precompute(code: &SurfaceCode) -> PrecomputedData {
// Build distance graphs and lookup tables
// Similar to precomputing.py
PrecomputedData {
x_graph: Graph::new(),
z_graph: Graph::new(),
virtual_edges: HashMap::new(),
edge_to_data: HashMap::new(),
}
}

pub fn decode(&mut self, syndromes: &[Syndrome]) -> Recovery {
// 1. Check cache
// 2. Build matching graph
// 3. Add virtual nodes
// 4. Find maximum weight perfect matching
// 5. Convert matching to recovery operations
Recovery {}
}
}
2 changes: 2 additions & 0 deletions crates/pecos-qec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
// the License.

// pecos-qec stub. Left intentionally blank for now.

mod decoders;

0 comments on commit b21bd3e

Please sign in to comment.