Skip to content

Commit 6a06853

Browse files
committed
🚧 Add special_edges
1 parent 1254cd7 commit 6a06853

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

python/swiflow/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _special_edges(
7979
pplanes: Mapping[_V, PPlane] | None,
8080
) -> set[tuple[_V, _V]]:
8181
"""Compute special edges that can bypass partial order constraints in Pauli flow."""
82+
# MEMO: Unify with Rust implementation
8283
ret: set[tuple[_V, _V]] = set()
8384
if pplanes is None:
8485
return ret

src/pflow.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Maximally-delayed Pauli flow algorithm.
22
33
use core::iter;
4-
use std::collections::HashMap;
4+
use std::collections::{HashMap, HashSet};
55

66
use fixedbitset::FixedBitSet;
77
use pyo3::prelude::*;
@@ -434,6 +434,31 @@ pub fn find(g: Graph, iset: Nodes, oset: Nodes, pplanes: PPlanes) -> Option<(PFl
434434
}
435435
}
436436

437+
/// Compute special edges that can bypass partial order constraints in Pauli flow.
438+
fn special_edges(g: &[Nodes], pflow: &PFlow, pplanes: &PPlanes) -> HashSet<(Node, Node)> {
439+
let mut ret = HashSet::new();
440+
for (&i, fi) in pflow {
441+
for &j in fi.iter().filter(|&&j| i != j) {
442+
if let Some(PPlane::X) = pplanes.get(&i) {
443+
ret.insert((i, j));
444+
}
445+
}
446+
let mut odd_fi = utils::odd_neighbors(g, fi);
447+
odd_fi.remove(&i);
448+
for &j in &odd_fi {
449+
if let Some(PPlane::Z) = pplanes.get(&i) {
450+
ret.insert((i, j));
451+
}
452+
}
453+
for &j in fi.intersection(&odd_fi) {
454+
if let Some(PPlane::Y) = pplanes.get(&i) {
455+
ret.insert((i, j));
456+
}
457+
}
458+
}
459+
ret
460+
}
461+
437462
/// Validates Pauli flow.
438463
///
439464
/// # Errors
@@ -453,9 +478,11 @@ pub fn verify(
453478
let (f, layers) = pflow;
454479
let n = g.len();
455480
let vset = (0..n).collect::<Nodes>();
481+
let special = special_edges(&g, &f, &pplanes);
456482
let f_flatiter = f
457483
.iter()
458-
.flat_map(|(i, fi)| Iterator::zip(iter::repeat(i), fi.iter()));
484+
.flat_map(|(i, fi)| Iterator::zip(iter::repeat(i), fi.iter()))
485+
.filter(|&(&i, &j)| !special.contains(&(i, j)));
459486
common::check_domain(f_flatiter, &vset, &iset, &oset)?;
460487
check_def_geom(&f, &g, &pplanes)?;
461488
check_def_layer(&f, &layers, &g, &pplanes)?;

0 commit comments

Comments
 (0)