Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lmondada committed Sep 21, 2023
1 parent 6b05912 commit 7d000c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
20 changes: 13 additions & 7 deletions src/portmatching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ impl PEdge {
circ: &impl Circuit,
) -> Result<Self, InvalidEdgeProperty> {
let src = port;
let (dst_node, dst) = circ.linked_ports(node, src).exactly_one().map_err(|e| {
if e.size_hint().0 > 0 {
InvalidEdgeProperty::AmbiguousEdge(src)
} else {
InvalidEdgeProperty::NoLinkedEdge(src)
}
})?;
let (dst_node, dst) = circ
.linked_ports(node, src)
.exactly_one()
.map_err(|mut e| {
if e.next().is_some() {
InvalidEdgeProperty::AmbiguousEdge(src)
} else {
InvalidEdgeProperty::NoLinkedEdge(src)
}
})?;
if circ.get_optype(dst_node).tag() == OpTag::Input {
return Ok(Self::InputEdge { src });
}
Expand Down Expand Up @@ -120,6 +123,9 @@ impl portmatching::EdgeProperty for PEdge {
///
/// A node is either a real node in the HUGR graph or a hidden copy node
/// that is identified by its node and outgoing port.
///
/// A NodeID::CopyNode can only be found as a target of a PEdge::InputEdge
/// property. Furthermore, a NodeID::CopyNode never has a node property.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
)]
Expand Down
7 changes: 2 additions & 5 deletions src/portmatching/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use hugr::{hugr::views::SiblingSubgraph, ops::OpType, Hugr, Node, Port};
use itertools::Itertools;
use portmatching::{
automaton::{LineBuilder, ScopeAutomaton},
PatternID,
EdgeProperty, PatternID,
};
use thiserror::Error;

Expand Down Expand Up @@ -385,10 +385,7 @@ fn compatible_offsets(e1: &PEdge, e2: &PEdge) -> bool {
let PEdge::InternalEdge { dst: dst1, .. } = e1 else {
return false;
};
let src2 = match *e2 {
PEdge::InternalEdge { src, .. } => src,
PEdge::InputEdge { src, .. } => src,
};
let src2 = e2.offset_id();
dst1.direction() != src2.direction() && dst1.index() == src2.index()
}

Expand Down
14 changes: 6 additions & 8 deletions src/portmatching/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,12 @@ impl CircuitPattern {
)
.map(|m| {
m.into_iter()
.filter_map(|(node_p, node_c)| {
let NodeID::HugrNode(node_p) = node_p else {
return None;
};
let NodeID::HugrNode(node_c) = node_c else {
return None;
};
Some((node_p, node_c))
.filter_map(|(node_p, node_c)| match (node_p, node_c) {
(NodeID::HugrNode(node_p), NodeID::HugrNode(node_c)) => {
Some((node_p, node_c))
}
(NodeID::CopyNode(..), NodeID::CopyNode(..)) => None,
_ => panic!("Invalid match map"),
})
.collect()
})
Expand Down

0 comments on commit 7d000c5

Please sign in to comment.