4.2. Preliminaries and simplifying assumptions
For simplicity, we will throughout consider minIR graphs that admit a type system , though most of the results can also be adapted to other graph domains. We will write for the types of (i.e. its values) and for the operation types (i.e. its edges).
Linear paths and operation splitting #
An operation type in the type system is a hyperedge. Its endpoints
are strings of data types that define the input and output signature of the operation . We can refer to the set of all hyperedge endpoints of using the string indices ( denotes the disjoint set union):
Fix a partition of into disjoint pairs
where the last set of the partition may be a singleton if is odd. For every , we then define new split operation types , each with two endpoints: the -th operation type has endpoints and in . For every operation of type , we can then split into operations each of arity 1 or 2 and of types respectively. We will refer to the graph transformation that replaces an operation in a minIR graph with the operations for as operation splitting.
It is important to note that the splitting of an operation is unique and given by the type of , and thus invariant under (typed) morphisms: there is a morphism of a pattern into a graph if and only if there is a morphism from the split pattern into the split graph .
A transformation rule splitting an operation with 3 sources and 2 targets. The choice of endpoint partition made here, obtained by pairing the -th use with the -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 also define linear paths. Two values in a minIR graph are on the same linear path if there are values with and such that is connected to through an operation and they correspond to the same pair of endpoints in the endpoints partition (i.e. the indices of correspond to values and in ).
Linearity assumption and rigidity #
Recall that in Definition ., and refer to the subset of values that are within the domain of definition of and respectively. For this chapter, we will assume ; 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, 2014. 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, 2014. 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.
A category is rigid if for all morphisms in that intersects all components of and for all that factorises as , then is unique.
In other words, there is a unique way to extend a morphism to a morphism , if it exists. If we interpret and as graph patterns that we are interested in matching with , then rigidity guarantees that there is (at most) a unique way to extend a match morphism into a match morphism on the larger pattern .
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 . We also use the linear path decomposition to define circuit depth, written , as the longest linear path in .
As discussed in section 3.4, minIR rewrites are instantiated from transformation rules by minIR match morphisms . Restricting our considerations to linear-valued minIR graphs has the further implication that all such match morphsisms will be injective. We call an embedding and write it using greek letters and a hooked arrow
Finding such embeddings is the pattern matching problem that we are solving. This problem is equivalent to finding minIR subgraphs of such that is isomorphic to the pattern .
Convexity #
According to Proposition ., a necessary condition for a subgraph to define a valid minIR rewrite is convexity. In this chapter we weaken this requirement and propose a condition based on circuit width:
Let be an embedding of a pattern into a linear-valued minIR graph such that is a convex subgraph of . Then for every subgraph such that , it holds that
Proof
Up to isomorphism, we can assume . Suppose there is such that and . Let be partitions of and into sets of values that are on the same linear path of and respectively. It must hold that for all there is such that , because and operation splitting is preserved under embeddings. As the map from to cannot be injective, there must be and , such that and . We conclude that there must be a path in the fully split graph of between a value of and a value of that is not in the fully split graph of . Given that is convex, this path must be in , which contradicts the preservation of operation splitting under embeddings.
In this chapter, whenever we define a subgraph of a graph , we will assume that 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 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 and depth , 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 linear paths can always be broken up into a composition of operations, each on two linear paths as follows:
Expressing an operation on 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 .
We furthermore define the set of all port labels
so that we can associate every operation endpoint in a minIR graph with a port label from the set . We further endow the labels with a total order (for instance, based on the string index values). The total order on then induces a total order on the paths in that start in the same value : the paths are equivalently described by the sequence of port labels of the operations traversed. These form strings in , which we order lexicographically. Given a root value , for every value in there is thus a unique smallest path from to in 2. 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.
Let be a graph with operations of odd arity (i.e. is odd) and open values. Then, the circuit width of is
Proof
For any linear path in consider its two ends and , i.e. the two values in with only one neighbouring value in (by definition linear paths cannot be empty). In the fully split graph of , 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 , or one such operation and one open value, or two open values. The result follows.
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, 1971. 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). ↩︎
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 that has been visited, all its descendants will be visited before proceeding to any other operation. ↩︎