You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've done a simple BFS to construct a subgraph from an input circuit and a starting node.
the input circuit HUGR looks like this. Load in this json file -> goto.json
After extracting the subgraph the HUGR we see that it has multiple output nodes which seems strange. See the extra ouput node hanging by itself on the right of the diagram below.
Sorry I don't know of a short way to reproduce this issue so I'll just share the code I hacked together.
use tket2::{self,
hugr::{hugr::views::SiblingSubgraph, ops::NamedOp,HugrView,Node},};fnsubgraph_from_source_node(circuit:&tket2::Circuit,source_node:Node) -> SiblingSubgraph{// Traverse the Circuit with BFS to find the subcircuit// in the causal cone of the source nodeletmut visited_nodes:Vec<Node> = Vec::new();letmut nodes_to_visit = vec![source_node];
visited_nodes.push(source_node);while nodes_to_visit.len() > 0{let current_node = nodes_to_visit.pop().unwrap();for neighbour in circuit.hugr().output_neighbours(current_node){if !visited_nodes.contains(&neighbour){
visited_nodes.push(neighbour);
nodes_to_visit.push(neighbour);}}}SiblingSubgraph::try_from_nodes(visited_nodes, circuit.hugr()).unwrap()}fnmain(){let circ: tket2::Circuit = tket2::serialize::load_tk1_json_file("goto.json").unwrap();let pauli_z_cmds:Vec<_> = circ
.commands().filter(|cmd| cmd.optype().name() == "tket2.quantum.Z").collect();let first_pauli = &pauli_z_cmds[0];let sibgraph = subgraph_from_source_node(&circ, first_pauli.node());let extracted = sibgraph.extract_subgraph(circ.hugr(),"");let subcircuit = tket2::Circuit::try_new(&extracted, extracted.root()).unwrap();println!("{}", subcircuit.mermaid_string());}
The text was updated successfully, but these errors were encountered:
CalMacCQ
changed the title
SiblingSubgraph generates a HUGR with multiple output nodesSiblingSubgraph generates a HUGR with two output nodes
Feb 21, 2025
I've done a simple BFS to construct a subgraph from an input circuit and a starting node.
the input circuit HUGR looks like this. Load in this json file -> goto.json
After extracting the subgraph the HUGR we see that it has multiple output nodes which seems strange. See the extra ouput node hanging by itself on the right of the diagram below.
Sorry I don't know of a short way to reproduce this issue so I'll just share the code I hacked together.
The text was updated successfully, but these errors were encountered: