@@ -1063,7 +1063,41 @@ in {a}\* (i.e. there is no hierarchy relation between them).
1063
1063
1064
1064
There are the following primitive operations.
1065
1065
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.
1067
1101
1068
1102
###### `Replace`
1069
1103
0 commit comments