Skip to content

Commit aa7d5cb

Browse files
committed
remove unwanted changes
1 parent a5eb655 commit aa7d5cb

File tree

2 files changed

+34
-162
lines changed

2 files changed

+34
-162
lines changed

hugr-core/src/hugr/persistent/trait_impls.rs

Lines changed: 0 additions & 123 deletions
This file was deleted.

hugr-core/src/hugr/views/sibling_subgraph.rs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ use super::root_checked::RootCheckable;
3535
///
3636
/// A HUGR region in which all nodes share the same parent. Unlike
3737
/// [`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.
4040
///
4141
/// 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.
4747
///
4848
/// The ordering of the nodes in the subgraph is irrelevant to define the convex
4949
/// subgraph, but it determines the ordering of the boundary signature.
@@ -150,10 +150,10 @@ impl<N: HugrNode> SiblingSubgraph<N> {
150150
///
151151
/// ## Arguments
152152
///
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.
157157
///
158158
/// Incoming boundary ports must be unique and partitioned by input
159159
/// parameter: two ports within the same set of the partition must be
@@ -190,8 +190,7 @@ impl<N: HugrNode> SiblingSubgraph<N> {
190190
) -> Result<Self, InvalidSubgraph<N>> {
191191
let pg = hugr.portgraph();
192192

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.
195194
let subpg = Subgraph::new_subgraph(pg.clone(), make_boundary(hugr, &inputs, &outputs));
196195
let nodes = subpg
197196
.nodes_iter()
@@ -394,12 +393,12 @@ impl<N: HugrNode> SiblingSubgraph<N> {
394393
/// match the signature of the subgraph.
395394
///
396395
/// 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,
399398
/// - [`InvalidReplacement::InvalidSignature`]: the signature of the
400399
/// 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.
403402
///
404403
/// At the moment we do not support state order edges. If any are found in
405404
/// the replacement graph, this will panic.
@@ -623,10 +622,10 @@ fn get_edge_type<H: HugrView, P: Into<Port> + Copy>(
623622

624623
/// Whether a subgraph is valid.
625624
///
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.
630629
fn validate_subgraph<H: HugrView>(
631630
hugr: &H,
632631
nodes: &[H::Node],
@@ -676,8 +675,8 @@ fn validate_subgraph<H: HugrView>(
676675
Err(InvalidSubgraphBoundary::DisconnectedBoundaryPort(n, p))?;
677676
};
678677

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.
681680
if nodes.iter().any(|&n| {
682681
hugr.node_inputs(n).any(|p| {
683682
hugr.linked_ports(n, p).any(|(n1, _)| {
@@ -687,8 +686,8 @@ fn validate_subgraph<H: HugrView>(
687686
}) {
688687
return Err(InvalidSubgraph::NotConvex);
689688
}
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.
692691
if nodes.iter().any(|&n| {
693692
hugr.node_outputs(n).any(|p| {
694693
hugr.linked_ports(n, p)
@@ -708,8 +707,7 @@ fn validate_subgraph<H: HugrView>(
708707
return Err(InvalidSubgraphBoundary::EmptyPartition.into());
709708
}
710709

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
713711
if let Some((i, _)) = inputs.iter().enumerate().find(|(_, ports)| {
714712
let Some(edge_t) = get_edge_type(hugr, ports) else {
715713
return true;
@@ -888,9 +886,9 @@ mod tests {
888886
impl<N: HugrNode> SiblingSubgraph<N> {
889887
/// A sibling subgraph from a HUGR.
890888
///
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`].
894892
///
895893
/// This will return an [`InvalidSubgraph::EmptySubgraph`] error if the
896894
/// subgraph is empty.
@@ -912,8 +910,7 @@ mod tests {
912910
}
913911

914912
/// 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.
917914
fn build_hugr() -> Result<(Hugr, Node), BuildError> {
918915
let mut mod_builder = ModuleBuilder::new();
919916
let func = mod_builder.declare(
@@ -1278,8 +1275,7 @@ mod tests {
12781275
rep.apply(&mut h).unwrap();
12791276
}
12801277

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.
12831279
#[test]
12841280
fn single_node_subgraph() {
12851281
// A hugr with a single NOT operation, with disconnected output.
@@ -1293,18 +1289,17 @@ mod tests {
12931289
// Unconnected output, discarded
12941290
let h = b.finish_hugr_with_outputs([]).unwrap();
12951291

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)
12981294
let subg = SiblingSubgraph::from_node(not_n.node(), &h);
12991295
assert_eq!(subg.nodes().len(), 1);
13001296
assert_eq!(
13011297
subg.signature(&h).io(),
13021298
Signature::new(vec![bool_t()], vec![bool_t()]).io()
13031299
);
13041300

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.
13081303
let subg = SiblingSubgraph::try_from_nodes([not_n.node()], &h).unwrap();
13091304
assert_eq!(subg.nodes().len(), 1);
13101305
assert_eq!(

0 commit comments

Comments
 (0)