@@ -35,15 +35,15 @@ use super::root_checked::RootCheckable;
35
35
///
36
36
/// A HUGR region in which all nodes share the same parent. Unlike
37
37
/// [`super::SiblingGraph`], not all nodes of the sibling graph must be
38
- /// included. A convex subgraph is always an induced subgraph, i.e. it is
39
- /// defined by a set of nodes and all edges between them.
38
+ /// included. A convex subgraph is always an induced subgraph, i.e. it is defined
39
+ /// by a set of nodes and all edges between them.
40
40
///
41
41
/// The incoming boundary (resp. outgoing boundary) is given by the input (resp.
42
- /// output) ports of the subgraph that are linked to nodes outside of the
43
- /// subgraph. The signature of the subgraph is then given by the types of the
44
- /// incoming and outgoing boundary ports. Given a replacement with the same
45
- /// signature, a [`SimpleReplacement`] can be constructed to rewrite the
46
- /// subgraph with the replacement.
42
+ /// output) ports of the subgraph that are linked to nodes outside of the subgraph.
43
+ /// The signature of the subgraph is then given by the types of the incoming
44
+ /// and outgoing boundary ports. Given a replacement with the same signature,
45
+ /// a [`SimpleReplacement`] can be constructed to rewrite the subgraph with the
46
+ /// replacement.
47
47
///
48
48
/// The ordering of the nodes in the subgraph is irrelevant to define the convex
49
49
/// subgraph, but it determines the ordering of the boundary signature.
@@ -150,10 +150,10 @@ impl<N: HugrNode> SiblingSubgraph<N> {
150
150
///
151
151
/// ## Arguments
152
152
///
153
- /// The `incoming` and `outgoing` arguments give $B_I$ and $B_O$
154
- /// respectively. Incoming edges must be given by incoming ports and
155
- /// outgoing edges by outgoing ports. The ordering of the incoming and
156
- /// outgoing ports defines the signature of the subgraph.
153
+ /// The `incoming` and `outgoing` arguments give $B_I$ and $B_O$ respectively.
154
+ /// Incoming edges must be given by incoming ports and outgoing edges by
155
+ /// outgoing ports. The ordering of the incoming and outgoing ports defines
156
+ /// the signature of the subgraph.
157
157
///
158
158
/// Incoming boundary ports must be unique and partitioned by input
159
159
/// parameter: two ports within the same set of the partition must be
@@ -190,8 +190,7 @@ impl<N: HugrNode> SiblingSubgraph<N> {
190
190
) -> Result < Self , InvalidSubgraph < N > > {
191
191
let pg = hugr. portgraph ( ) ;
192
192
193
- // Ordering of the edges here is preserved and becomes ordering of the
194
- // signature.
193
+ // Ordering of the edges here is preserved and becomes ordering of the signature.
195
194
let subpg = Subgraph :: new_subgraph ( pg. clone ( ) , make_boundary ( hugr, & inputs, & outputs) ) ;
196
195
let nodes = subpg
197
196
. nodes_iter ( )
@@ -394,12 +393,12 @@ impl<N: HugrNode> SiblingSubgraph<N> {
394
393
/// match the signature of the subgraph.
395
394
///
396
395
/// May return one of the following five errors
397
- /// - [`InvalidReplacement::InvalidDataflowGraph`]: the replacement graph
398
- /// is not a [`crate::ops::OpTag::DataflowParent`]-rooted graph,
396
+ /// - [`InvalidReplacement::InvalidDataflowGraph`]: the replacement
397
+ /// graph is not a [`crate::ops::OpTag::DataflowParent`]-rooted graph,
399
398
/// - [`InvalidReplacement::InvalidSignature`]: the signature of the
400
399
/// replacement DFG does not match the subgraph signature, or
401
- /// - [`InvalidReplacement::NonConvexSubgraph`]: the sibling subgraph is
402
- /// not convex.
400
+ /// - [`InvalidReplacement::NonConvexSubgraph`]: the sibling subgraph is not
401
+ /// convex.
403
402
///
404
403
/// At the moment we do not support state order edges. If any are found in
405
404
/// the replacement graph, this will panic.
@@ -623,10 +622,10 @@ fn get_edge_type<H: HugrView, P: Into<Port> + Copy>(
623
622
624
623
/// Whether a subgraph is valid.
625
624
///
626
- /// Verifies that input and output ports are valid subgraph boundaries, i.e.
627
- /// they belong to nodes within the subgraph and are linked to at least one node
628
- /// outside of the subgraph. This does NOT check convexity proper, i.e. whether
629
- /// the set of nodes form a convex induced graph.
625
+ /// Verifies that input and output ports are valid subgraph boundaries, i.e. they belong
626
+ /// to nodes within the subgraph and are linked to at least one node outside of the subgraph.
627
+ /// This does NOT check convexity proper, i.e. whether the set of nodes form a convex
628
+ /// induced graph.
630
629
fn validate_subgraph < H : HugrView > (
631
630
hugr : & H ,
632
631
nodes : & [ H :: Node ] ,
@@ -676,8 +675,8 @@ fn validate_subgraph<H: HugrView>(
676
675
Err ( InvalidSubgraphBoundary :: DisconnectedBoundaryPort ( n, p) ) ?;
677
676
} ;
678
677
679
- // Check that every incoming port of a node in the subgraph whose source is not
680
- // in the subgraph belongs to inputs.
678
+ // Check that every incoming port of a node in the subgraph whose source is not in the subgraph
679
+ // belongs to inputs.
681
680
if nodes. iter ( ) . any ( |& n| {
682
681
hugr. node_inputs ( n) . any ( |p| {
683
682
hugr. linked_ports ( n, p) . any ( |( n1, _) | {
@@ -687,8 +686,8 @@ fn validate_subgraph<H: HugrView>(
687
686
} ) {
688
687
return Err ( InvalidSubgraph :: NotConvex ) ;
689
688
}
690
- // Check that every outgoing port of a node in the subgraph whose target is not
691
- // in the subgraph belongs to outputs.
689
+ // Check that every outgoing port of a node in the subgraph whose target is not in the subgraph
690
+ // belongs to outputs.
692
691
if nodes. iter ( ) . any ( |& n| {
693
692
hugr. node_outputs ( n) . any ( |p| {
694
693
hugr. linked_ports ( n, p)
@@ -708,8 +707,7 @@ fn validate_subgraph<H: HugrView>(
708
707
return Err ( InvalidSubgraphBoundary :: EmptyPartition . into ( ) ) ;
709
708
}
710
709
711
- // Check edge types are equal within partition and copyable if partition size >
712
- // 1
710
+ // Check edge types are equal within partition and copyable if partition size > 1
713
711
if let Some ( ( i, _) ) = inputs. iter ( ) . enumerate ( ) . find ( |( _, ports) | {
714
712
let Some ( edge_t) = get_edge_type ( hugr, ports) else {
715
713
return true ;
@@ -888,9 +886,9 @@ mod tests {
888
886
impl < N : HugrNode > SiblingSubgraph < N > {
889
887
/// A sibling subgraph from a HUGR.
890
888
///
891
- /// The subgraph is given by the sibling graph of the root. If you wish
892
- /// to create a subgraph from another root, wrap the argument
893
- /// `region` in a [`super::SiblingGraph`].
889
+ /// The subgraph is given by the sibling graph of the root. If you wish to
890
+ /// create a subgraph from another root, wrap the argument `region` in a
891
+ /// [`super::SiblingGraph`].
894
892
///
895
893
/// This will return an [`InvalidSubgraph::EmptySubgraph`] error if the
896
894
/// subgraph is empty.
@@ -912,8 +910,7 @@ mod tests {
912
910
}
913
911
914
912
/// A Module with a single function from three qubits to three qubits.
915
- /// The function applies a CX gate to the first two qubits and a Rz gate
916
- /// (with a constant angle) to the last qubit.
913
+ /// The function applies a CX gate to the first two qubits and a Rz gate (with a constant angle) to the last qubit.
917
914
fn build_hugr ( ) -> Result < ( Hugr , Node ) , BuildError > {
918
915
let mut mod_builder = ModuleBuilder :: new ( ) ;
919
916
let func = mod_builder. declare (
@@ -1278,8 +1275,7 @@ mod tests {
1278
1275
rep. apply ( & mut h) . unwrap ( ) ;
1279
1276
}
1280
1277
1281
- /// Test the behaviour of the sibling subgraph when built from a single
1282
- /// node.
1278
+ /// Test the behaviour of the sibling subgraph when built from a single node.
1283
1279
#[ test]
1284
1280
fn single_node_subgraph ( ) {
1285
1281
// A hugr with a single NOT operation, with disconnected output.
@@ -1293,18 +1289,17 @@ mod tests {
1293
1289
// Unconnected output, discarded
1294
1290
let h = b. finish_hugr_with_outputs ( [ ] ) . unwrap ( ) ;
1295
1291
1296
- // When built with `from_node`, the subgraph's signature is the same as the
1297
- // node's. (bool input, bool output)
1292
+ // When built with `from_node`, the subgraph's signature is the same as the node's.
1293
+ // (bool input, bool output)
1298
1294
let subg = SiblingSubgraph :: from_node ( not_n. node ( ) , & h) ;
1299
1295
assert_eq ! ( subg. nodes( ) . len( ) , 1 ) ;
1300
1296
assert_eq ! (
1301
1297
subg. signature( & h) . io( ) ,
1302
1298
Signature :: new( vec![ bool_t( ) ] , vec![ bool_t( ) ] ) . io( )
1303
1299
) ;
1304
1300
1305
- // `from_nodes` is different, is it only uses incoming and outgoing edges to
1306
- // compute the signature. In this case, the output is disconnected, so
1307
- // it is not part of the subgraph signature.
1301
+ // `from_nodes` is different, is it only uses incoming and outgoing edges to compute the signature.
1302
+ // In this case, the output is disconnected, so it is not part of the subgraph signature.
1308
1303
let subg = SiblingSubgraph :: try_from_nodes ( [ not_n. node ( ) ] , & h) . unwrap ( ) ;
1309
1304
assert_eq ! ( subg. nodes( ) . len( ) , 1 ) ;
1310
1305
assert_eq ! (
0 commit comments