Skip to content

Commit ad8a00b

Browse files
authored
[spec] Define the SimpleReplace API. (#85)
1 parent f290f4d commit ad8a00b

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

specification/hugr.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,41 @@ in {a}\* (i.e. there is no hierarchy relation between them).
10631063
10641064
There are the following primitive operations.
10651065
1066-
##### Replacement method
1066+
##### Replacement methods
1067+
1068+
###### `SimpleReplace`
1069+
1070+
This method is used for simple replacement of dataflow subgraphs consisting of
1071+
leaf nodes.
1072+
1073+
Given a set $S$ of nodes in a hugr $H$, let:
1074+
1075+
- $\textrm{inp}_H(S)$ be the set of input ports of nodes in $S$ whose source
1076+
is in $H \setminus S$;
1077+
- $\textrm{out}_H(S)$ be the set of input ports of nodes in $H \setminus S$
1078+
whose source is in $S$.
1079+
1080+
The method takes as input:
1081+
1082+
- the ID of a DFG node $P$ in $\Gamma$;
1083+
- a DFG-convex set $S$ of IDs of leaf nodes that are children of $P$ (not
1084+
including the Input and Output nodes), and that have no incoming or outgoing
1085+
Ext edges;
1086+
- a hugr $H$ whose root is a DFG node $R$ with only leaf nodes as children --
1087+
let $T$ be the set of children of $R$;
1088+
- a map $\nu\_\textrm{inp}: \textrm{inp}\_H(T \setminus \\{\texttt{Input}\\}) \to \textrm{inp}\_{\Gamma}(S)$;
1089+
- a map $\nu_\textrm{out}: \textrm{out}_{\Gamma}(S) \to \textrm{out}_H(T \setminus \\{\texttt{Output}\\})$.
1090+
1091+
The new hugr is then derived by:
1092+
1093+
- adding copies of all children of $R$, except for Input and Output nodes, to
1094+
$\Gamma$, and make them all children of $P$;
1095+
- adding edges between all newly added nodes matching those in $R$;
1096+
- for each $p \in \textrm{inp}\_H(T)$, adding an edge from the predecessor of
1097+
$\nu\_\textrm{inp}(p)$ to the new copy of $p$;
1098+
- for each $p \in \textrm{out}\_{\Gamma}(S)$, adding an edge from the new copy
1099+
of the predecessor of $\nu\_\textrm{out}(p)$ to $p$.
1100+
- removing all nodes in $S$ and edges between them.
10671101
10681102
###### `Replace`
10691103

0 commit comments

Comments
 (0)