Skip to content

SiblingSubgraph::try_from_nodes fails if there's a Const+LoadConst #2654

@aborgna-q

Description

@aborgna-q

Given the following hugr (fn build_hugr from sibling_subgraph::test)

graph LR
    subgraph 0 ["(0) [**Module**]"]
        direction LR
        style 0 stroke:#832561,stroke-width:3px
        subgraph 1 ["(1) FuncDefn: #quot;test#quot;"]
            direction LR
            2["(2) Input"]
            3["(3) Output"]
            4["(4) test.quantum.CX"]
            5["(5) const:custom:f64(0.5)"]
            6["(6) LoadConstant"]
            7["(7) test.quantum.RzF64"]
            2--"0:0<br>qubit"-->4
            2--"1:1<br>qubit"-->4
            2--"2:0<br>qubit"-->7
            4--"0:0<br>qubit"-->3
            4--"1:1<br>qubit"-->3
            5--"0:0<br>float64"-->6
            6--"0:1<br>float64"-->7
            7--"0:2<br>qubit"-->3
        end
    end
Loading

Trying to create a subgraph containing the const definition and LoadConstant nodes fails with at NotConvex error.
Failing test:

    #[test]
    fn construct_load_const_subgraph() {
        let (hugr, func_root) = build_hugr().unwrap(); // From sibling_subgraph.rs

        let const_node = hugr
            .children(func_root)
            .find(|&n| hugr.get_optype(n).is_const())
            .unwrap();
        let load_const_node = hugr
            .children(func_root)
            .find(|&n| hugr.get_optype(n).is_load_constant())
            .unwrap();
        let nodes: BTreeSet<_> = BTreeSet::from_iter([const_node, load_const_node]);

        let sub = SiblingSubgraph::try_from_nodes(vec![const_node, load_const_node], &hugr).unwrap();

        let subgraph_nodes: BTreeSet<_> = sub.nodes().iter().copied().collect();
        assert_eq!(subgraph_nodes, nodes);
    }
Error: NotConvex
test hugr::views::sibling_subgraph::tests::construct_load_const_subgraph ... FAILED

Metadata

Metadata

Assignees

Labels

A-rustArea: Rust codeC-bugfixCategory: PR with bug fix

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions