Graph transformation in minIR

3.4. Graph transformation in minIR

As discussed in section 3.2, computation graphs with linear values, such as minIR, must adopt strict graph transformation semantics to ensure that linear constraints are satisfied at all times. In this section, we use the minIR graph category presented in the previous section to define transformation semantics that lean on the double pushout (DPO) Ehrig, 1976Hartmut Ehrig and Hans-Jörg Kreowski. 1976. Parallelism of manipulations in multidimensional information structures and sesqui-pushout (SqPO) Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 semantics in adhesive categories Lack, 2005Stephen Lack and Pawel Sobocinski. 2005. Adhesive and quasiadhesive categories. RAIRO - Theoretical Informatics and Applications 39, 3 (July 2005, 511--545). doi: 10.1051/ITA:2005028.

Adhesivity of hypergraph categories #

The natural place to start this section is by studying which of the categories defined in section 3.3 are adhesive. From adhesivity follows that transforming graphs using DPO and SqPO constructions is well-defined and unique, at least in the regimes of interest to us.

A category is said to be adhesive if it has all pullbacks and pushouts along monos, as well as some compatibility conditions between them, the so-called “Van Kampen squares”. We refer to the literature (e.g. Lack, 2005Stephen Lack and Pawel Sobocinski. 2005. Adhesive and quasiadhesive categories. RAIRO - Theoretical Informatics and Applications 39, 3 (July 2005, 511--545). doi: 10.1051/ITA:2005028) for a complete definition. For our purposes, the following two results are sufficient:

  • Every presheaf topos [C,Set][\mathbb C, \mathrm{Set}] is adhesive (Corollary 3.6 in Lack, 2005Stephen Lack and Pawel Sobocinski. 2005. Adhesive and quasiadhesive categories. RAIRO - Theoretical Informatics and Applications 39, 3 (July 2005, 511--545). doi: 10.1051/ITA:2005028);
  • Every full subcategory DC\mathbb D \subseteq \mathbb C of an adhesive category is adhesive if the pullbacks and pushouts in C\mathbb C of objects in D\mathbb D are again in D\mathbb D (a simple result; if the Van Kampen squares commute in C\mathbb C, they must commute in D\mathbb D).

A first result immediately follows from the first result:

Proposition 3.1Adhesivity of directed hypergraphs
The category H\mathbb H of directed hypergraphs is adhesive.
Proof

It is a presheaf.

This does not immediately generalise to lin-H\textrm{lin-}\mathbb H, as unlike H\mathbb H, Definition 3.2 imposes that EE be a coproduct. However, the result still holds:

Proposition 3.2Adhesivity of hypergraphs with linearity constraints
The categories lin-H\textrm{lin-}\mathbb H and lin-Htype\textrm{lin-}\mathbb H_\textrm{type} are adhesive.
Proof

lin-H\textrm{lin-}\mathbb H is a full subcategory of the adhesive category [lin-C,Set][\textrm{lin-}\mathbb C, \mathrm{Set}]. We must show the existence of pullbacks and pushouts along monos in lin-H\textrm{lin-}\mathbb H.

Pullbacks. Consider a pullback ApaPpbA \xleftarrow{p_a} P \xrightarrow{p_b} of AaCbBA \xrightarrow{a} C \xleftarrow{b} B in [lin-C,Set][\textrm{lin-}\mathbb C, \mathrm{Set}], with A,B,Clin-HA, B, C \in \textrm{lin-}\mathbb H. We must show that PP is in lin-H\textrm{lin-}\mathbb H. Colimits are computed pointwise in presheaves, so we know that P(E)P(E) is the pullback of A(E)C(E)B(E)A(E) \to C(E) \leftarrow B(E) in Set\textrm{Set}. If we can show that P(E)P(E) is the coproduct of P(Est)P(E_{st}) for s,tNs, t \in \mathbb{N}, then we are done.

Let vP(E)v \in P(E). Because A(E)A(E) and B(E)B(E) are coproducts in Set, i.e. a disjoint union, there must be s,t,s,tNs, t, s', t' \in \mathbb{N} such that pa(v)A(Est)p_a(v) \in A(E_{st}) and pb(v)B(Est)p_b(v) \in B(E_{st'}). By naturality of aa and bb, it follows that a(pa(v))C(Est)a(p_a(v)) \in C(E_{st}) and b(pb(v))B(Est)b(p_b(v)) \in B(E_{s't'}). But by commutativity of the pullback diagram, a(pa(v))=b(pb(v))a(p_a(v)) = b(p_b(v)), and thus s=ss = s' and t=tt = t'. We conclude by unicity of the pullback that vP(Est)v \in P(E_{st}) and thus P(E)=stP(Est)P(E) = \bigsqcup_{st} P(E_{st}).

Pushouts. The same argument as for pullbacks also applies to pushouts: given a pushout PP of AaCbBA \xrightarrow{a} C \xleftarrow{b} B in [lin-C,Set][\textrm{lin-}\mathbb C, \mathrm{Set}] with A,B,Clin-HA, B, C \in \textrm{lin-}\mathbb H, an element vP(E)v \in P(E) that makes the pushout square commute must have preimages in A(Est),B(Est)A(E_{st}), B(E_{st}) and C(Est)C(E_{st}) for some s,tNs, t \in \mathbb{N}. Thus the pushout distributes over the coproduct, and we can conclude that P(E)P(E) is the coproduct of pushouts.

The same argument also applies to lin-Htype\textrm{lin-}\mathbb H_\textrm{type}1.

Now to the spicy stuff:

Proposition 3.3Non-adhesivity of hierarchical hypergraphs
Whilst hier-lin-Htype\textrm{hier-lin-}\mathbb H_\textrm{type} is adhesive, the category hier-lin-H\textrm{hier-lin-}\mathbb H is NOT adhesive.
Proof

hier-lin-Htype\textrm{hier-lin-}\mathbb H_\textrm{type} is a presheaf – hence adhesive.

The following pushout square shows that hier-lin-H\textrm{hier-lin-}\mathbb H cannot be adhesive: the pushout square is valid in [hier-lin-C,Set][\textrm{hier-lin-}\mathbb C, \mathrm{Set}], but the pushout at the bottom right is not in hier-lin-H\textrm{hier-lin-}\mathbb H, because the child regions cannot each be assigned a unique parent.

Double pushout semantics #

From Proposition 3.3, it follows that minIR graph transformations can be performed through the double pushout (DPO) construction Ehrig, 1976Hartmut Ehrig and Hans-Jörg Kreowski. 1976. Parallelism of manipulations in multidimensional information structures in the [hier-lin-C,Set][\textrm{hier-lin-}\mathbb C, \mathrm{Set}] category.

Definition 3.6Double pushout (DPO) transformation

A transformation rule pp in an adhesive category A\mathbb A is a span LIRL \leftarrow I \rightarrow R. For objects G,HAG, H \in \mathbb A, we then write G(p,m)HG \xRightarrow{(p,m)} H or GpHG \xRightarrow{p} H if there is a matching morphism m:LGm: L \to G and a context object CC along with morphisms GCHG \leftarrow C \to H and ICI \to C such that the following diagram commutes and both squares are pushouts:

If the DPO transformation G(p,m)HG \xRightarrow{(p,m)} H exists for some rule pp and match mm, then we say GHG \Rightarrow H is a valid DPO rewrite.

To ensure that a DPO rewrite is valid in minIR, we must impose certain conditions. Let GG be an IO-free minIR graph, i.e. Ghier-lin-HG \in \textrm{hier-lin-}\mathbb H, there is a morphism GΣG \to \Sigma in hier-lin-Htype\textrm{hier-lin-}\mathbb H_\textrm{type} for some type system Σ\Sigma and I=O=I = O = \varnothing.

A DPO rewrite GHG \Rightarrow H is a valid minIR DPO rewrite if there is a transformation GpHG \xRightarrow{p} H in [hier-lin-C,Set][\textrm{hier-lin-}\mathbb C, \mathrm{Set}] and

  1. pp is left-mono, i.e. the morphism ILI \to L is mono,2
  2. the pushout complement CC and pushout HH also exist in the slice category hier-lin-HtypeΣ\textrm{hier-lin-}\mathbb H_\textrm{type} \searrow \Sigma,
  3. HH satisfies the hierarchy condition of Definition 3.3,
  4. HH is IO-free.
Proposition 3.4
If GG is a minIR graph and GHG \Rightarrow H is a valid minIR DPO rewrite, then HH is a valid minIR graph.
Proof

We know by construction that H[hier-lin-C,Set]H \in [\textrm{hier-lin-}\mathbb C, \mathrm{Set}]. We must show that HH further satisfies the constraints to be an object in the full subcategory of minIR graphs.

The first condition is standard in DPO and guarantees that CC and DD are unique if they exist.

The third condition we impose on HH corresponds directly to the constraint that defines hierarchical graphs in hier-lin-H\textrm{hier-lin-}\mathbb H. The fourth condition ensures that valid minIR DPO rewrites map IO-free graphs to IO-free graphs.

Finally, the second condition is imposed to ensure well-typedness of HH. The functor hier-lin-Hhier-lin-Htype\textrm{hier-lin-}\mathbb H \to \textrm{hier-lin-}\mathbb H_\textrm{type} that forgets the def\textit{def} and use\textit{use} morphisms is a left adjoint (it possesses a right Kan extension defined pointwise), and thus preserves colimits. The images of CC and HH thus form pushout squares in hier-lin-Htype\textrm{hier-lin-}\mathbb H_\textrm{type}, and by unicity, must match the pushout squares in hier-lin-HtypeΣ\textrm{hier-lin-}\mathbb H_\textrm{type} \searrow \Sigma. Hence HH is well-typed.

The restriction to rewrites of IO-free graphs is not a restriction of generality: if we are interested in rewriting computations with inputs and outputs, we can always express them as IO-free graphs by adding input and output ops with the values in II as outputs, respectively OO as inputs. We assign them dedicated types distinct from all other operations; these operations will never be matched by transformation rules and can be removed at the end of rewriting.

Generalising to sesqui-pushouts #

We restricted minIR rewrites to DPO transformations obtained form left-mono rules, to ensure that the construction is unique. This excludes rules that may identify two values in GG but split them into two different values in HH. Such rules allow for cloning values, which is a useful transformation in minIR for non-linear values. An example of a transformation rule that we would like to allow in minIR:

For this example we added a 2x operation that multiplies an angle value passed as input by two. The transformation rule replaces a rotation of angle 2α2\alpha by two rotations of angle α\alpha by cloning the input angle.

Such semantics are possible using the sesqui-pushout construction (SqPO) by Corradini et al. Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4. We can reuse the same (p,m)\xRightarrow{(p,m)} notation: when DPO is restricted to left-mono rules as we have done, SqPO is a generalisation of DPO (i.e. the construction coincides whenever the DPO exists).

Definition 3.7Sesqui-pushout (SqPO) transformation

A transformation rule pp in an adhesive category A\mathbb A is a span LIRL \leftarrow I \rightarrow R. For objects G,HAG, H \in \mathbb A, we then write G(p,m)HG \xRightarrow{(p,m)} H or GpHG \xRightarrow{p} H if there is a matching morphism m:LGm: L \to G and a context object CC along with morphisms GCHG \leftarrow C \to H and ICI \to C such that CC is the final pullback complement of ILmGI \to L \xrightarrow{m} G and the right square is a pushout:

If the SqPO transformation G(p,m)HG \xRightarrow{(p,m)} H exists for some rule pp and match mm, then we say GHG \Rightarrow H is a valid (SqPO) rewrite.

The left square is redundant in the diagram above, as it follows from the requirement that CC be the final pullback complement (FPC). It is kept to highlight the similarities to DPO. As the commuting diagram indicates, the final pullback complement (FPC) construction forms a pullback square. Furthermore, unlike pushout complements, the FPC is defined by a universality property that ensures uniqueness if it exists. We refer to Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 for the exact FPC construction.

With SqPO, we can define the set of valid minIR rewrites as given by the SqPO transformations GpHG \xRightarrow{p} H in [hier-lin-C,Set][\textrm{hier-lin-}\mathbb C, \mathrm{Set}] satisfying the relaxed set of conditions

  1. the pushout complement CC and pushout HH also exist in the slice category hier-lin-HtypeΣ\textrm{hier-lin-}\mathbb H_\textrm{type} \searrow \Sigma,
  2. HH satisfies the hierarchy condition of Definition 3.3,
  3. HH is IO-free.

We conclude this section with a discussion of some of the properties of minIR transformations using SqPO (referring again to Corradini Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 or König, 2018Barbara König, Dennis Nolte, Julia Padberg and Arend Rensink. 2018. A Tutorial on Graph Transformation. In Graph Transformation, Specifications, and Nets - In Memory of Hartmut Ehrig. Springer, 83--104. doi: 10.1007/978-3-319-75396-6_5 for a more detailed explanation of the concepts discussed):

Deletion in unknown context.  A key difference between DPO and SqPO transformations is that SqPO transformations on graphs will delete edges attached to a vertex vdv_d that is deleted by the transformation rule (i.e. vdLv_d \in L but vd∉Rv_d \not\in R of the rule). The DPO transformation on the other hand is only well-defined when all edges incident to vdv_d are in the image of mm and thus explicitly deleted (this is known as the dangling condition).

As minIR rewrites follow SqPO semantics, transformation rules such as the following are allowed:

Here ×\times denotes the multiplication of angles and const(0)\textsf{const(0)} the zero angle. Any operation that would be connected to the starred value on the left would be deleted by this rule. However such an implicit operation deletion only yields valid minIR graphs if all incident values are non-linear and none of the target values of the deleted operation are used.

Non-left-mono rules.  As discussed in the introduction to SqPO, the cloning of values is allowed in minIR rewrites. However, linear values may never be cloned (the FPC or pushout will not exist in these cases). Thus any minIR transformation rule will be left-mono on linear values. It must further be left-linear on all (linear and non-linear) values in II that are mapped to outputs in RR: if a value ww is produced by op applied to vv, then cloning vv and 'op will result in two definitions of ww.

Non-right-mono rules.  Non-right-mono rules are allowed in both DPO and SqPO. They result in vertex merges. In minIR, the situation for right-mono is symmetric to left-mono: the map must be mono on linear values (otherwise the same value will have multiple uses or definitions) and it must be mono on all values in II that are mapped to inputs in LL (otherwise a value in the rewritten minIR graph will have more than one value definition).


  1. In fact, a much simpler argument applies: the category lin-Htype\textrm{lin-}\mathbb H_\textrm{type} is isomorphic to the presheaf category [lin-C~type,Set][\textrm{lin-}\tilde{\mathbb C}_\textrm{type}, \mathrm{Set}], where lin-C~type\textrm{lin-}\tilde{\mathbb C}_\textrm{type} is obtained from lin-Ctype\textrm{lin-}\mathbb C_\textrm{type} by removing the object EE. Adhesivity follows. ↩︎

  2. This is often called left-linear in the literature. We avoid this term in this thesis to avoid confusion with the linearity property of values in minIR. ↩︎