Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define the SimpleReplace API. #85

Merged
merged 9 commits into from
Jun 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion specification/hugr.md
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,41 @@ in {a}\* (i.e. there is no hierarchy relation between them).

There are the following primitive operations.

##### Replacement method
##### Replacement methods

###### `SimpleReplace`

This method is used for simple replacement of dataflow subgraphs consisting of
leaf nodes.

Given a set $S$ of nodes in a hugr $H$, let:

- $\textrm{inp}_H(S)$ be the set of input ports of nodes in $S$ whose source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, neat - love the subscripting

is in $H \setminus S$;
- $\textrm{out}_H(S)$ be the set of input ports of nodes in $H \setminus S$
whose source is in $S$.

The method takes as input:

- the ID of a DFG node $P$ in $\Gamma$;
- a DFG-convex set $S$ of IDs of leaf nodes that are children of $P$ (not
including the Input and Output nodes), and that have no incoming or outgoing
Ext edges;
- a hugr $H$ whose root is a DFG node $R$ with only leaf nodes as children --
let $T$ be the set of children of $R$;
- a map $\nu\_\textrm{inp}: \textrm{inp}\_H(T \setminus \\{\texttt{Input}\\}) \to \textrm{inp}\_{\Gamma}(S)$;
- a map $\nu_\textrm{out}: \textrm{out}_{\Gamma}(S) \to \textrm{out}_H(T \setminus \\{\texttt{Output}\\})$.

The new hugr is then derived by:

- adding copies of all children of $R$, except for Input and Output nodes, to
$\Gamma$, and make them all children of $P$;
- adding edges between all newly added nodes matching those in $R$;
- for each $p \in \textrm{inp}\_H(T)$, adding an edge from the predecessor of
$\nu\_\textrm{inp}(p)$ to the new copy of $p$;
- for each $p \in \textrm{out}\_{\Gamma}(S)$, adding an edge from the new copy
of the predecessor of $\nu\_\textrm{out}(p)$ to $p$.
- removing all nodes in $S$ and edges between them.

###### `Replace`

Expand Down