Skip to content

test: Failing testcase for #1974 #1975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions hugr-core/src/hugr/views/sibling_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,24 @@ impl<N: HugrNode> SiblingSubgraph<N> {
///
/// The subgraph signature will be given by signature of the node.
pub fn from_node(node: N, hugr: &impl HugrView<Node = N>) -> Self {
let is_value_port = |p: Port| -> bool {
hugr.get_optype(node)
.port_kind(p)
.is_some_and(|k| k.is_value())
};

let nodes = vec![node];
let inputs = hugr
.node_inputs(node)
.filter(|&p| hugr.is_linked(node, p))
.map(|p| vec![(node, p)])
// accept linked value inputs
.filter_map(|p| {
(hugr.is_linked(node, p) && is_value_port(p.into())).then_some(vec![(node, p)])
})
.collect_vec();
let outputs = hugr
.node_outputs(node)
.filter_map(|p| {
// accept linked outputs or unlinked value outputs
{
hugr.is_linked(node, p)
|| hugr
.get_optype(node)
.port_kind(p)
.is_some_and(|k| k.is_value())
}
.then_some((node, p))
})
// accept linked or unlinked value outputs
.filter_map(|p| is_value_port(p.into()).then_some((node, p)))
.collect_vec();

Self {
Expand Down Expand Up @@ -831,6 +830,7 @@ mod tests {
use cool_asserts::assert_matches;

use crate::builder::inout_sig;
use crate::extension::prelude::Noop;
use crate::hugr::Rewrite;
use crate::ops::Const;
use crate::std_extensions::arithmetic::float_types::{self, ConstF64};
Expand Down Expand Up @@ -1239,4 +1239,29 @@ mod tests {
let rep = subg.create_simple_replacement(&h, replacement).unwrap();
rep.apply(&mut h).unwrap();
}

#[test]
// #[should_panic]
fn order_edge() {
let (hugr, nop) = {
let mut b = DFGBuilder::new(Signature::new_endo(Type::UNIT).with_prelude()).unwrap();
let input = b.input();
let nop = b
.add_dataflow_op(Noop(Type::UNIT), [input.out_wire(0)])
.unwrap();
let output = b.output();
b.add_other_wire(input.node(), nop.node());
b.add_other_wire(nop.node(), output.node());
(
b.finish_hugr_with_outputs([nop.out_wire(0)]).unwrap(),
nop.node(),
)
};
println!("{}", hugr.mermaid_string());
let view = SiblingSubgraph::from_node(nop, &hugr);
assert_eq!(
view.signature(&hugr),
Signature::new_endo(Type::UNIT).with_prelude()
);
}
}
Loading