Preliminaries and simplifying assumptions

4.2. Preliminaries and simplifying assumptions

For simplicity, we will throughout consider minIR graphs that admit a type system Σ\Sigma, though most of the results can also be adapted to other graph domains. We will write TT for the types of Σ\Sigma (i.e. its values) and Γ\Gamma for the operation types (i.e. its edges).

Linear paths and operation splitting #

An operation type νΓ\nu \in \Gamma in the type system Σ\Sigma is a hyperedge. Its endpoints

src(ν)=src1(ν)srcs(ν) and tgt(ν)=tgt1(ν)tgtt(ν) \textit{src}(\nu) = \textit{src}_1(\nu) \cdots \textit{src}_s(\nu) \textrm{ and } \textit{tgt}(\nu) = \textit{tgt}_1(\nu) \cdots \textit{tgt}_t(\nu)

are strings of data types that define the input and output signature of the operation ν\nu. We can refer to the set of all hyperedge endpoints of ν\nu using the string indices Idx()\mathrm{Idx}(\cdot) (\sqcup denotes the disjoint set union):

Pν=Idx(src(ν))Idx(tgt(ν))={1,,s}{1,,t}.P_\nu = \mathrm{Idx}(\textit{src}(\nu)) \sqcup \mathrm{Idx}(\textit{tgt}(\nu)) = \{1, \dots, s\} \sqcup \{1, \dots, t\}.

Fix a partition of PνP_\nu into disjoint pairs

Pν={p1,p1}{p2,p2},P_\nu = \{p_1, p_1'\} \,\sqcup\, \{p_2, p_2'\} \,\sqcup\, \cdots,

where the last set of the partition may be a singleton if Pν|P_\nu| is odd. For every νΓ\nu \in \Gamma, we then define f=Po/2f = \lceil |P_o| / 2 \rceil new split operation types ν1,,νf\nu_1, \dots, \nu_f, each with two endpoints: the ii-th operation type νi\nu_i has endpoints pip_i and pip_i' in PνP_\nu. For every operation oEo \in E of type ν\nu, we can then split oo into ff operations o1,,of,o_1, \dots, o_f, each of arity 1 or 2 and of types ν1,,νf\nu_1, \dots, \nu_f respectively. We will refer to the graph transformation that replaces an operation oo in a minIR graph with the operations oio_i for 1if1 \leqslant i \leqslant f as operation splitting.

It is important to note that the splitting of an operation oo is unique and given by the type of oo, and thus invariant under (typed) morphisms: there is a morphism PGP \to G of a pattern into a graph if and only if there is a morphism PGP' \to G' from the split pattern PP' into the split graph GG'.

Operation splitting

A transformation rule splitting an operation with 3 sources and 2 targets. The choice of endpoint partition made here, obtained by pairing the ii-th use with the ii-th define, is arbitrary but convenient for quantum gates as they correspond to the input and output values of a same qubit.

The endpoint partitions PνP_\nu also define linear paths. Two values v,vv, v' in a minIR graph are on the same linear path if there are values u1,,uku_1, \dots, u_k with v=u1v = u_1 and v=ukv' = u_k such that uiu_i is connected to ui+1u_{i+1} through an operation oo and they correspond to the same pair of endpoints in the endpoints partition (i.e. the indices of Ptype(o)P_{type(o)} correspond to values uiu_i and ui+1u_{i+1} in src(o)tgt(o)\textit{src}(o) \sqcup \textit{tgt}(o)).

Linearity assumption and rigidity #

Recall that in Definition ., VsrcV_\textit{src} and VtgtV_\textit{tgt} refer to the subset of values that are within the domain of definition of src\textit{src} and tgt\textit{tgt} respectively. For this chapter, we will assume Vsrc=Vtgt=VV_\textit{src} = V_\textit{tgt} = V; in other words, minIR graphs are IO-free (this is w.l.o.g., see discussion after Proposition .) and all values are linear1 (this is definitely not w.l.o.g.!).

As a result of this assumption, the subcategory of minIR graphs that we consider forms a rigid category, as introduced by Danos et al. Danos, 2014Vincent Danos, Reiko Heckel and Pawel Sobocinski. 2014. Transformation and Refinement of Rigid Structures. The definition, which we reproduce here, is given in terms of morphisms that intersect all components of the codomain. We refer to Danos, 2014Vincent Danos, Reiko Heckel and Pawel Sobocinski. 2014. Transformation and Refinement of Rigid Structures for the precise definition of that notion: in the context of linear-valued minIR graphs, this is equivalent to requiring that the image of the graph homomorphism intersects every connected component of the codomain.

Definition 4.1Rigid Category

A category C\mathbb C is rigid if for all morphisms AhBA \xrightarrow{h} B in C\mathbb C that intersects all components of BB and for all AgCA \xrightarrow{g} C that factorises as g=fhg = f \circ h, then BfCB \xrightarrow{f} C is unique.

In other words, there is a unique way to extend a morphism AgCA \xrightarrow{g} C to a morphism BfCB \xrightarrow{f} C, if it exists. If we interpret AA and BB as graph patterns that we are interested in matching with ABA \subseteq B, then rigidity guarantees that there is (at most) a unique way to extend a match morphism AGA \to G into a match morphism on the larger pattern BGB \to G.

The linearity assumption also has other useful consequences. Every linear value has exactly one use and one definition. As a result, all linear paths are disjoint and form a partition of the values of the graph. They correspond to the paths that form the connected components of the fully split graph, i.e. the graph obtained by splitting every operation. We call the number of linear paths (and hence the number of connected components in the fully split graph) the circuit width, written width(G)width(G). We also use the linear path decomposition to define circuit depth, written depth(G)depth(G), as the longest linear path in GG.

As discussed in section 3.4, minIR rewrites are instantiated from transformation rules by minIR match morphisms m:PGm: P \to G. Restricting our considerations to linear-valued minIR graphs has the further implication that all such match morphsisms mm will be injective. We call mm an embedding and write it using greek letters and a hooked arrow

m=φ:PG.m = \varphi: P \hookrightarrow G.

Finding such embeddings PGP \hookrightarrow G is the pattern matching problem that we are solving. This problem is equivalent to finding minIR subgraphs HGH \subseteq G of GG such that HH is isomorphic to the pattern PHP \simeq H.

Convexity #

According to Proposition ., a necessary condition for a subgraph HH to define a valid minIR rewrite is convexity. In this chapter we weaken this requirement and propose a condition based on circuit width:

Proposition 4.1Necessary condition for convexity

Let φ:PG\varphi: P \hookrightarrow G be an embedding of a pattern PP into a linear-valued minIR graph GG such that φ(P)\varphi(P) is a convex subgraph of GG. Then for every subgraph HGH \subseteq G such that φ(P)H\varphi(P) \subseteq H, it holds that width(P)width(H).width(P) \leq width(H).

Proof

Up to isomorphism, we can assume PGP \subseteq G. Suppose there is HGH \subseteq G such that PHP \subseteq H and width(P)>width(H)width(P) > width(H). Let LP,LHP(V)\mathcal{L}_P, \mathcal{L}_H \subseteq \mathcal{P}(V) be partitions of VPV_P and VHV_H into sets of values that are on the same linear path of PP and HH respectively. It must hold that for all LP\ell \in \mathcal{L}_P there is LH\ell' \in \mathcal{L}_H such that \ell \subseteq \ell', because PHP \subseteq H and operation splitting is preserved under embeddings. As the map from LP\mathcal{L}_P to LH\mathcal{L}_H cannot be injective, there must be 1,2LP\ell_1, \ell_2 \in \mathcal{L}_P and LH\ell' \in \mathcal{L}_H, such that 12\ell_1 \neq \ell_2 and 1,2\ell_1, \ell_2 \subseteq \ell'. We conclude that there must be a path in the fully split graph of HH between a value of 1\ell_1 and a value of 2\ell_2 that is not in the fully split graph of PP. Given that PP is convex, this path must be in PP, which contradicts the preservation of operation splitting under embeddings.

In this chapter, whenever we define a subgraph HGH \subseteq G of a graph GG, we will assume that HH satisfies the above weakened convexity condition.

The converse of Proposition ., however, is not true. The pattern-matching technique presented below will find a strict superset of convex embeddings. To restrict considerations to convex embeddings, it suffices to filter out the non-convex ones in a post-processing step.

Ignoring minIR Hierarchy #

So far, we have omitted discussing one part of the minIR structure: the nested hierarchy of operations. Syntactically, the hierarchy formed by parentparent relations between minIR operations can be viewed as just another value type that operations are incident to: parent operations define an additional output that children operations consume as additional input. Because of the bijectivity requirement of minIR morphisms on parent-child relations of Definition ., these parent-child relations behave, in fact, like linear values – and hence do not violate the linearity assumption we have imposed.

However, by treating them as such, we have further weakened the constraints on pattern embeddings. We do not enforce that boundary values must be in the same regions or that parent-child relations cannot be boundary values. Similarly to convexity, we defer checking these properties to a post-processing step.

Further assumptions (harmless) #

We will further simplify the problem by making presentation choices that do not imply any loss of generality. First of all, we assume that all patterns have the same width ww and depth dd, are connected graphs and have at least 2 operations. These conditions can always be fulfilled by adding “dummy” operations if necessary. Embeddings of disconnected patterns can be computed one connected component at a time.

We will further assume that all operations are on at most two linear paths (and thus in particular, have at most 4 endpoints). Operations on Δ>2\Delta > 2 linear paths can always be broken up into a composition of Δ1\Delta-1 operations, each on two linear paths as follows:

Gate decomposition

Expressing an operation on Δ=3\Delta = 3 linear paths as a composition of two operations on 2 linear paths.

This transformation leaves circuit width unchanged but may multiply the graph depth by up to a factor Δ\Delta.

We furthermore define the set of all port labels

Pall=νΓPνP_{all} = \bigcup_{\nu \in \Gamma} P_\nu

so that we can associate every operation endpoint in a minIR graph GG with a port label from the set PallP_{all}. We further endow the labels PallP_{all} with a total order (for instance, based on the string index values). The total order on PallP_{all} then induces a total order on the paths v1vkVv_1\cdots v_k \in V^\ast in GG that start in the same value v1v_1: the paths are equivalently described by the sequence of port labels of the operations traversed. These form strings in PallP_{all}^\ast, which we order lexicographically. Given a root value rr, for every value vv in GG there is thus a unique smallest path from rr to vv in GG2. This path is invariant under isomorphism of the underlying graph (i.e. relabelling of the values and operations but preserving the port labels). With this we conclude the discussions of the specificities of minIR graphs related to typing, linearity and hierarchy, and the related assumptions that we are making.

To summarise, minIR graphs as they are considered in this chapter are hypergraphs (Definition .) that satisfy the following properties

  • every vertex (value) is incident to exactly two hyperedges (operations). It is the target of one hyperedge (its definition) and the source of another one (its use),
  • every hyperedge is incident to at most four vertices,
  • every hyperedge can be split in a unique way (and invariant under isomorphism) into at most two split operations, with each at most two endpoints.

When modelling subgraphs of IO-free minIR graphs (typically patterns for pattern matching), some hyperedge connections at the boundary of the subgraph will be missing. We say a value is open if a use or define operation is missing (i.e. it is a boundary value in a minIR subgraph).

We will simplify refer to hypergraphs that satisfy the above assumptions as graphs. In the unique instance of this chapter where a graph that does not satisfy this construction is referred to, we will specifically call it a simple graph.

We conclude with the following notable bound on circuit width.

Proposition 4.2Bound on circuit width

Let GG be a graph with noddn_\textrm{odd} operations of odd arity (i.e. def(o)+use(o)|def(o) + use(o)| is odd) and nωn_\omega open values. Then, the circuit width of GG is

width(G)=(nodd+nω)/2.width(G) = \lfloor(n_\textrm{odd} + n_\omega) / 2\rfloor.

Proof

For any linear path PVP \subseteq V^\ast in GG consider its two ends v1v_1 and v2v_2, i.e. the two values in PP with only one neighbouring value in PP (by definition linear paths cannot be empty). In the fully split graph of GG, these values are either open or must be connected to two operations. In the latter case, at least one of the operations must have a single endpoint (otherwise by acyclicity, the operation would have two neighbours).

In a fully split graph, operations with a single endpoint result from a split operation with an odd number of endpoints. We conclude that for every linear path, there are either two operations with an odd number of endpoints in GG, or one such operation and one open value, or two open values. The result follows.


  1. This restriction is necessary for our results: copyable values may admit an arbitrary number of adjacent hyperedges. As a result, minIR graph pattern matching with copyable values is a generalisation of the subgraph isomorphism problem, a well-known NP-complete problem Cook, 1971Stephen A. Cook. 1971. The complexity of theorem-proving procedures. In Proceedings of the third annual ACM symposium on Theory of computing - STOC ’71. ACM Press, 151--158. doi: 10.1145/800157.805047. The approach generalises to non-linear types, but the complexity analysis no longer holds (we pay a computational price for every non-linear value matched). ↩︎

  2. Remark that the ordering of the operations thus defined is a particular case of a depth-first search (DFS) ordering of the graph: given an operation oo that has been visited, all its descendants will be visited before proceeding to any other operation. ↩︎