pymatching 0.1.0

Safe Rust bindings for the PyMatching quantum error-correction decoder
Documentation
#![cfg(feature = "rustworkx")]

use pymatching::{EdgeData, Matching};
use rustworkx_core::petgraph::graph::UnGraph;

#[test]
fn boundary_edges_round_trip_through_rustworkx() {
    let mut matching = Matching::default();
    matching
        .add_boundary_edge(0, EdgeData::new(vec![7]).with_weight(1.25))
        .unwrap();
    matching
        .add_edge(0, 1, EdgeData::new(vec![8]).with_weight(2.5))
        .unwrap();
    matching.set_boundary_nodes([2]);

    let exported = matching.to_rustworkx().unwrap();
    let round_tripped = Matching::try_from(&exported).unwrap();

    assert_eq!(round_tripped.num_nodes(), 3);
    assert_eq!(round_tripped.num_edges(), 2);
    assert!(round_tripped.has_boundary_edge(0));
    assert_eq!(
        round_tripped.boundary_edge_data(0).unwrap(),
        &EdgeData::new(vec![7]).with_weight(1.25)
    );
    assert!(round_tripped.has_edge(0, 1));
    assert_eq!(round_tripped.boundary().collect::<Vec<_>>(), vec![2]);
}

#[test]
fn isolated_nodes_survive_import_and_export() {
    let mut graph = UnGraph::<bool, pymatching::EdgeData>::default();
    let a = graph.add_node(false);
    let b = graph.add_node(false);
    graph.add_node(false);
    graph.add_edge(a, b, pymatching::EdgeData::new(vec![0]).with_weight(1.25));

    let matching = Matching::try_from(&graph).unwrap();
    assert_eq!(matching.num_nodes(), 3);

    let exported = matching.to_rustworkx().unwrap();
    assert_eq!(exported.node_count(), 3);
    assert_eq!(exported.edge_count(), 1);
}