From 370e6dcc336db354e69d566f93d9d33c63f9ea20 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Thu, 14 Dec 2023 15:07:55 +0000 Subject: [PATCH 01/10] Add a bit of intuition about Replace. --- specification/hugr.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/specification/hugr.md b/specification/hugr.md index 93e9ceb53..bfc4dae3e 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1202,7 +1202,18 @@ The new hugr is then derived as follows: ###### `Replace` -This is the general subgraph-replacement method. +This is the general subgraph-replacement method. Intuitively, it takes a set of +sibling nodes to remove and replace with a new set of nodes. The new set of +nodes is itself a HUGR with some "holes" (edges and nodes that get "filled in" +by the `Replace` operation). To fully specify the operation, some further data +are needed: + + - The replacement may containg container nodes with no children, which replace + removed container nodes, adopting all their (non-removed) children. + - All new incoming edges from the retained nodes to the new nodes, all + outgoing edges from the new nodes to the retained nodes, and any new edges + that bypass the replacement (going between retained nodes) must be + specified. Given a set $S$ of nodes in a hugr, let $S^\*$ be the set of all nodes descended from nodes in $S$ (i.e. reachable from $S$ by following hierarchy edges), From 37a5f723b354d60acb2f797e31e37c20198ed192 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Thu, 14 Dec 2023 15:52:01 +0000 Subject: [PATCH 02/10] Define an identity node for CFGs. --- specification/hugr.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index bfc4dae3e..78422d89f 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -417,6 +417,8 @@ Some normalizations are possible: - If the entry node has only one successor and that successor is the exit node, the CFG node itself can be removed. +An special `passthrough` `DFB` is defined having no effect on the data. + The CFG in the example below has three inputs: one (call it `v`) of type "P" (not specified, but with a conversion to boolean represented by the nodes labelled "P?1" and "P?2"), one of type "qubit" and one (call it `t`) of type "angle". @@ -1333,13 +1335,14 @@ the children of that CFG node. ###### `InsertIdentity` -Given an edge between sibling nodes in a DSG, insert an `identity` -node having its source as predecessor and its target as successor. +Given an edge between sibling nodes in a DSG or CFG, insert an `identity` or +`passthrough` node having its source as predecessor and its target as +successor. ###### `RemoveIdentity` -Remove an `identity` node from a DSG, wiring its predecessor to its -successor. +Remove an `identity` node from a DSG, or a `passthrough` node from a CFG, +wiring its predecessor to its successor. ##### Order insertion and removal methods From d0d094083455fb95254e71f5fcade13b5f723051 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Thu, 14 Dec 2023 16:10:44 +0000 Subject: [PATCH 03/10] State that acyclicity is preserved by InsertOrder. --- specification/hugr.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index 78422d89f..97a9c0621 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1350,8 +1350,8 @@ wiring its predecessor to its successor. Insert an Order edge from `n0` to `n1` where `n0` and `n1` are distinct siblings in a DSG such that there is no path in the DSG from `n1` to -`n0`. If there is already an order edge from `n0` to `n1` this does -nothing (but is not an error). +`n0`. (Thus acyclicity is preserved.) If there is already an order edge from +`n0` to `n1` this does nothing (but is not an error). ###### `RemoveOrder` From 1c9853e086bf2e4c0c18bfac45011fc771e7a519 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Thu, 14 Dec 2023 16:11:52 +0000 Subject: [PATCH 04/10] Use correct terminology. --- specification/hugr.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index 97a9c0621..5dd455bbe 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1356,8 +1356,8 @@ siblings in a DSG such that there is no path in the DSG from `n1` to ###### `RemoveOrder` Given nodes `n0` and `n1`, if there is an Order edge from `n0` to `n1`, -remove it. (If there is an intergraph edge from `n0` to a descendent of -`n1`, this invalidates the hugr. TODO should this be an error?) +remove it. (If there is a non-local edge from `n0` to a descendent of `n1`, this +invalidates the hugr. TODO should this be an error?) ##### Insertion and removal of const loads From 2733432c88ffadc083b359007f88d4f51cfddd6e Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Thu, 14 Dec 2023 16:13:37 +0000 Subject: [PATCH 05/10] Correct typo. --- specification/hugr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specification/hugr.md b/specification/hugr.md index 5dd455bbe..8df56c8b2 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1363,7 +1363,7 @@ invalidates the hugr. TODO should this be an error?) ###### `InsertConstIgnore` -Given a `Const` node `c`, and optionally a DSG `P`, add a new +Given a `Const` node `c`, and optionally `P`, a parent of a DSG, add a new `LoadConstant` node `n` as a child of `P` with a `Static` edge from `c` to `n` and no outgoing edges from `n`. Also add an Order edge from the Input node under `P` to `n`. Return the ID of `n`. If `P` is From 207079b5ee758316d30fe871ea36198800aa0283 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Thu, 14 Dec 2023 16:30:20 +0000 Subject: [PATCH 06/10] Fix outdated text. --- specification/hugr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specification/hugr.md b/specification/hugr.md index 8df56c8b2..5f786dc5f 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1396,7 +1396,7 @@ nodes. The most basic case – replacing a convex set of Op nodes in a DSG with another graph of Op nodes having the same signature – is implemented by -having T map everything to the parent node, and bot(G) is empty. +`SimpleReplace`. If one of the nodes in the region is a complex container node that we wish to preserve in the replacement without doing a deep copy, we can From 44d2ea321c77d2763b5ecff5af8414e7af9618be Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Thu, 14 Dec 2023 17:14:33 +0000 Subject: [PATCH 07/10] Make description of "passthrough" DFBs clearer. --- specification/hugr.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index 5f786dc5f..1e40275fb 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -417,7 +417,8 @@ Some normalizations are possible: - If the entry node has only one successor and that successor is the exit node, the CFG node itself can be removed. -An special `passthrough` `DFB` is defined having no effect on the data. +A `DFB` that simply wires its inputs to its outputs, having no effect on the +data, is called a _passthrough_ DFB. The CFG in the example below has three inputs: one (call it `v`) of type "P" (not specified, but with a conversion to boolean represented by the nodes labelled "P?1" and "P?2"), one of @@ -1335,13 +1336,13 @@ the children of that CFG node. ###### `InsertIdentity` -Given an edge between sibling nodes in a DSG or CFG, insert an `identity` or -`passthrough` node having its source as predecessor and its target as -successor. +Given an edge between sibling nodes in a DSG or CFG, insert an `identity` +node or passthrough DFB respectively, having its source as predecessor and its +target as successor. ###### `RemoveIdentity` -Remove an `identity` node from a DSG, or a `passthrough` node from a CFG, +Remove an `identity` node from a DSG, or a passthrough DFB node from a CFG, wiring its predecessor to its successor. ##### Order insertion and removal methods From cf1d9acda73ee86edee9a0d3469c30fc69c3787e Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Tue, 2 Jan 2024 11:50:43 +0000 Subject: [PATCH 08/10] Improve explanation of adoption. --- specification/hugr.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index b0f8dc0a9..6e6bca5a9 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1200,8 +1200,9 @@ nodes is itself a HUGR with some "holes" (edges and nodes that get "filled in" by the `Replace` operation). To fully specify the operation, some further data are needed: - - The replacement may containg container nodes with no children, which replace - removed container nodes, adopting all their (non-removed) children. + - The replacement may include container nodes with no children, which adopt + the children of removed container nodes and prevent those children being + removed. - All new incoming edges from the retained nodes to the new nodes, all outgoing edges from the new nodes to the retained nodes, and any new edges that bypass the replacement (going between retained nodes) must be From 4f61b7fd2d027560b8c7f878cc9b1c20203e3d52 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Tue, 2 Jan 2024 12:51:36 +0000 Subject: [PATCH 09/10] Revert "Make description of "passthrough" DFBs clearer." This reverts commit 44d2ea321c77d2763b5ecff5af8414e7af9618be. --- specification/hugr.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index 6e6bca5a9..ba91458ec 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -408,8 +408,7 @@ Some normalizations are possible: - If the entry node has only one successor and that successor is the exit node, the CFG node itself can be removed. -A `DFB` that simply wires its inputs to its outputs, having no effect on the -data, is called a _passthrough_ DFB. +An special `passthrough` `DFB` is defined having no effect on the data. The CFG in the example below has three inputs: one (call it `v`) of type "P" (not specified, but with a conversion to boolean represented by the nodes labelled "P?1" and "P?2"), one of @@ -1326,13 +1325,13 @@ the children of that CFG node. ###### `InsertIdentity` -Given an edge between sibling nodes in a DSG or CFG, insert an `identity` -node or passthrough DFB respectively, having its source as predecessor and its -target as successor. +Given an edge between sibling nodes in a DSG or CFG, insert an `identity` or +`passthrough` node having its source as predecessor and its target as +successor. ###### `RemoveIdentity` -Remove an `identity` node from a DSG, or a passthrough DFB node from a CFG, +Remove an `identity` node from a DSG, or a `passthrough` node from a CFG, wiring its predecessor to its successor. ##### Order insertion and removal methods From 90a98fd27f781aadd57ff94b92b6b78859b46cb6 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Tue, 2 Jan 2024 12:51:56 +0000 Subject: [PATCH 10/10] Revert "Define an identity node for CFGs." This reverts commit 37a5f723b354d60acb2f797e31e37c20198ed192. --- specification/hugr.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index ba91458ec..c9fb82b15 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -408,8 +408,6 @@ Some normalizations are possible: - If the entry node has only one successor and that successor is the exit node, the CFG node itself can be removed. -An special `passthrough` `DFB` is defined having no effect on the data. - The CFG in the example below has three inputs: one (call it `v`) of type "P" (not specified, but with a conversion to boolean represented by the nodes labelled "P?1" and "P?2"), one of type "qubit" and one (call it `t`) of type "angle". @@ -1325,14 +1323,13 @@ the children of that CFG node. ###### `InsertIdentity` -Given an edge between sibling nodes in a DSG or CFG, insert an `identity` or -`passthrough` node having its source as predecessor and its target as -successor. +Given an edge between sibling nodes in a DSG, insert an `identity` +node having its source as predecessor and its target as successor. ###### `RemoveIdentity` -Remove an `identity` node from a DSG, or a `passthrough` node from a CFG, -wiring its predecessor to its successor. +Remove an `identity` node from a DSG, wiring its predecessor to its +successor. ##### Order insertion and removal methods