### Bounding the search space size

←Return to chapter

## 5.5. Bounding the search space size

We show in this section that under some assumptions on the GTSs that hold in the use cases of interest to quantum compilation, there is a provable gap between the size of the search space of all reachable graphs in the GTS and the size of the corresponding confluently persistent data structure D\mathcal{D}D.

Let us introduce first the notion of overwriting rewrites.

Definition 5.3Overwriting rewrite

For two rewrites r 1 r_1 r 1​ and r 2 r_2 r 2​, we say that r 2 r_2 r 2​ overwrites r 1 r_1 r 1​, written r 1↠r 2 r_1 \twoheadrightarrow r_2 r 1​↠r 2​, if the deletion set V 2−V^-_2 V 2−​ of δ 2\delta_2 δ 2​ includes a vertex of the vertex set V 1 V_1 V 1​ of the replacement graph of r 1 r_1 r 1​

V 2−∩V 1≠∅.V^-_2 \cap V_1 \neq \varnothing. V 2−​∩V 1​=∅.

The definition can identically be applied to events. In this case, the overwriting events are precisely given by the parent-child relation: the set of all overwriting events of δ∈D\delta \in \mathcal{D}δ∈D is by definition the set of parents P(δ)P(\delta)P(δ) of δ\delta δ.

Our argument relies on the comparison of asymptotic bounds for the sizes of two sets G Δ\mathcal{G}_\Delta G Δ​ and D Δ\mathcal{D}_\Delta D Δ​, which we now define. Consider a GTS and an input graph G GG. A graph G′G'G′ is reachable from G GG within depth Δ⩾0\Delta \geqslant 0Δ⩾0 if there is a sequence of rewrites r 1,…,r ℓ r_1, \dots, r_\ell r 1​,…,r ℓ​ in the GTS from G GG to G′G'G′ such that all subsequences r β 1,…,r β k r_{\beta_1}, \dots, r_{\beta_k}r β 1​​,…,r β k​​ formed of overwriting rewrites r β i↠r β i+1 r_{\beta_i} \twoheadrightarrow r_{\beta_{i + 1}}r β i​​↠r β i+1​​ have length at most k⩽Δ k \leqslant \Delta k⩽Δ.

The set G Δ\mathcal{G}_\Delta G Δ​ is the set of all graphs reachable within depth Δ\DeltaΔ. We derive:

1. a lower bound on the size of ∣G Δ∣|\mathcal{G}_\Delta|∣G Δ​∣, the space of all graphs reachable in at most Δ\DeltaΔ rewrites from some input G GG, and
2. an upper bound on the size of the equivalent confluently persistent data structure D Δ\mathcal{D}_\Delta D Δ​, i.e. such that
   G Δ={f l a t(D)∣D∈Γ(D Δ)}.\mathcal{G}_\Delta = \{ flat(D) \mid D \in \Gamma(\mathcal{D}_\Delta) \}.G Δ​={f l at(D)∣D∈Γ(D Δ​)}.

In order to obtain bounds, we will introduce hypotheses that the GTSs must satisfy. Throughout this section, we will illustrate and motivate the restrictions that they impose in the following two use cases.

#### Use case 1: ζ\zeta ζ-complete GTS #

The first GTS we consider can be defined on any graph domain that has a notion of graph size (e.g. based on number of nodes, number of edges, etc.1) and for any graph size ζ\zeta ζ. The GTS is such that for any subgraph H⊆G H \subseteq G H⊆G of size ∣H∣=ζ|H| = \zeta∣H∣=ζ, there is at least one transformation rule in the GTS that matches H H H. We will call this case CompleteGTS.

This is the use case of quantum superoptimisation discussed in section 3.1 and used for benchmarking in section 4.7. In those cases, the transformation rules are obtained by enumerating all small circuits up to a certain size ζ\zeta ζ, thus guaranteeing that any subcircuit of size ζ\zeta ζ will be matched by the GTS.

Note that there is also an (obvious) upper bound on the number of transformation rules that can match on any given subgraph: the total number of transformation rules in the GTS.

#### Use case 2: single-rule GTS in a uniform domain #

At the other extreme of the GTS spectrum, we can consider a GTS made of a single (arbitrary) transformation rule. In this case, we require that graphs are drawn from a domain uniformly at random, so that for any subgraph H⊆G H \subseteq G H⊆G, all patterns of size ∣H∣|H|∣H∣ are equally likely. We will call this case SingleRuleGTS.

In this case, we will not show that our hypotheses hold for all inputs, but rather that they hold with a high probability. We will phrase our statements as a function of ϵ>0\epsilon > 0ϵ>0 and will require that they hold with probability 1−ϵ 1 - \epsilon1−ϵ for randomly drawn G GG.

This regime is interesting as it is the simplest instance of problem domains for which few assumptions can be made about the GTS themselves, but all inputs are expected to be equally likely.

### Lower bound on the naive search tree #

The event history of the set of graphs G Δ\mathcal{G}_\Delta G Δ​ defines a tree T Δ T_\Delta T Δ​, where G Δ\mathcal{G}_\Delta G Δ​ are the nodes and G p∈G Δ G_p \in \mathcal{G}_\DeltaG p​∈G Δ​ is the parent of G c∈G Δ G_c \in \mathcal{G}_\DeltaG c​∈G Δ​ if there is a rewrite r r r rewriting G p G_pG p​ to G c G_cG c​ in the GTS. Paths in T Δ T_\Delta T Δ​ are sequences of rewrites. We call T Δ T_\Delta T Δ​ the naive search tree of the GTS. We wish to derive a lower bound for ∣T Δ∣|T_\Delta|∣T Δ​∣.

#### Graph partitioning #

For fixed search depth Δ\DeltaΔ, let n>0 n > 0n>0 be the largest integer such that for all graphs G′∈T Δ G' \in T_\DeltaG′∈T Δ​, there exists disjoint subgraphs Π 1,…,Π n\Pi_1, \ldots, \Pi_nΠ 1​,…,Π n​ of G′G'G′ that satisfies the following property, for all 1≤i≤n: 1 \leq i \leq n:1≤i≤n:

there exists a rewrite in the GTS that can be applied to Π i\Pi_iΠ i​.

Hypothesis 1Linear scaling of n nn

For a fixed GTS, a fixed depth Δ\DeltaΔ and a family of input graphs G GG, we have the scaling n=Θ(∣G∣)n = \Theta(|G|)n=Θ(∣G∣).

We conjecture that this scaling holds for many GTSs of interest:

Proposition 5.5
Hypothesis 1 holds for `CompleteGTS` and for `SingleRuleGTS` probabilistically.

In CompleteGTS, it suffices to partition any input G GG into n=⌊∣G∣ζ⌋=Θ(∣G∣)n = \lfloor \frac{|G|}\zeta \rfloor = \Theta(|G|)n=⌊ζ∣G∣​⌋=Θ(∣G∣) disjoint subgraphs of size at least ζ\zeta ζ. Each subgraph will match a rule of the GTS by definition.

For SingleRuleGTS, let ϵ>0\epsilon > 0ϵ>0. Let ∣L∣|L|∣L∣ be the size of the left hand side L LL of the GTS rule. By assumption, for any subgraph H H H of size ∣L∣|L|∣L∣ of an input G GG, there is a constant probability p pp that the rule matches H H H. For a subgraph H H H of size k∣L∣k |L|k∣L∣, the probability of the rule not matching in H H H is (1−p)k(1 - p)^k(1−p)k. Picking

k>1 1+δ ln⁡ϵ+ln⁡∣L∣∣G∣ln⁡(1−p)k > \frac1{1 + \delta}\frac{\ln \epsilon + \ln {\frac{|L|}{|G|}}}{\ln (1 - p)}k>1+δ 1​ln(1−p)ln ϵ+ln∣G∣∣L∣​​

for some δ>0\delta > 0 δ>0 ensures that whenever δ>−ln⁡k k ln⁡(1−p)\delta > - \frac{\ln k}{k \ln (1 - p)}δ>−k ln(1−p)ln k​ (i.e. for k k k large enough),

k−ln⁡k ln⁡(1−p)>(1+δ)k>ln⁡ϵ+ln⁡∣L∣∣G∣ln⁡(1−p)⇔k>ln⁡ϵ n ln⁡(1−p), \begin{aligned} &k - \frac {\ln k}{\ln (1 - p)} > (1 + \delta)k > \frac{\ln \epsilon + \ln {\frac{|L|}{|G|}}}{\ln (1 - p)}\\ \Leftrightarrow\quad &k > \frac{\ln{\frac \epsilon n}}{\ln (1 - p)}, \end{aligned} ⇔​k−ln(1−p)ln k​>(1+δ)k>ln(1−p)ln ϵ+ln∣G∣∣L∣​​k>ln(1−p)ln n ϵ​​,​

where n=∣G∣k∣L∣n = \frac{|G|}{k |L|}n=k∣L∣∣G∣​ was chosen. It follows that a partition of G GG into ⌊n⌋\lfloor n \rfloor⌊n⌋ disjoint subgraphs of size at least k∣L∣k |L|k∣L∣ satisfies the hypothesis with probability 1−ϵ 1 - \epsilon1−ϵ.

#### Lower bound on ∣T Δ∣|T_\Delta|∣T Δ​∣ #

Fix the tree depth Δ\DeltaΔ and the GTS. Any rewrite from the GTS removes at most a constant K K K number of vertices from the graph it applies on. Thus, Any graph in T Δ T_\Delta T Δ​ is at least of size (1−K Δ)∣G∣=Θ(∣G∣)(1 - K\Delta)|G| = \Theta(|G|)(1−K Δ)∣G∣=Θ(∣G∣). Let n′n'n′ be the smallest value of n nn for a graph G m i n∈G Δ G_{min} \in \mathcal G_\DeltaG min​∈G Δ​. Whenever hypothesis 1 applies, we have n′=Θ(∣G m i n∣)=Θ(∣G∣)n' = \Theta(|G_{min}|) = \Theta(|G|)n′=Θ(∣G min​∣)=Θ(∣G∣).

For each G′∈T Δ G' \in T_\DeltaG′∈T Δ​ and Π i\Pi_iΠ i​, pick a rewrite r i(G′)r_i(G')r i​(G′) that applies to Π i\Pi_iΠ i​ and let R R R be the set of all such rewrites

R Δ={r i(G′)∣1≤i≤n′,G′∈T Δ}.R_\Delta = \{ r_i(G') \mid 1 \leq i \leq n', G' \in T_\Delta \}.R Δ​={r i​(G′)∣1≤i≤n′,G′∈T Δ​}.

We can consider the subtree T Δ′⊆T Δ T'_\Delta \subseteq T_\Delta T Δ′​⊆T Δ​ that only contains graphs obtained by applying rewrites in R Δ R_\Delta R Δ​.

For Δ=1\Delta = 1Δ=1, the search tree T Δ′T'_\Delta T Δ′​ will contain 2 n′2^{n'}2 n′ graphs: for each subgraph Π i\Pi_iΠ i​ of the input graph G GG, we can choose to either apply r i(G)r_i(G)r i​(G) or not2.

By repeating Δ\DeltaΔ times the search tree of size 2 n′2^{n'}2 n′ for Δ=1\Delta = 1Δ=1, we obtain a lower bound

∣G Δ∣=∣T Δ∣⩾∣T Δ′∣=(2 n′)Δ.|\mathcal{G}_\Delta| = |T_\Delta| \geqslant |T'_\Delta| = (2^{n'})^\Delta.∣G Δ​∣=∣T Δ​∣⩾∣T Δ′​∣=(2 n′)Δ.

We frame this result as the following proposition.

Proposition 5.6Lower bound for ∣G Δ∣|\mathcal{G}_\Delta|∣G Δ​∣
The naive search tree size ∣G Δ∣|\mathcal{G}_\Delta|∣G Δ​∣ is in Ω(2 Δ⋅n′)\Omega(2^{\Delta \cdot n'})Ω(2 Δ⋅n′).

As a result, for any GTS satisfying Hypothesis 1 the size of G Δ\mathcal G_\Delta G Δ​ grows at least exponentially with input graph size G GG and search depth Δ\DeltaΔ.

### Upper bound on the factorised search space #

Consider two rewrites r 1 r_1 r 1​ and r 2 r_2 r 2​. If neither overwrites the other, i.e. r 1↠̸r 2 r_1 \not\twoheadrightarrow r_2 r 1​↠r 2​ and r 2↠̸r 1 r_2 \not\twoheadrightarrow r_1 r 2​↠r 1​, then the order in which they are applied is irrelevant (see also Proposition 5.2). The persistent data structure D\mathcal{D}D uses this symmetry explicitly when exploring the set of reachable graphs.

This drastically reduces the size of the event history of D Δ\mathcal{D}_\Delta D Δ​. The event history defines a directed acyclic graph F Δ F_\Delta F Δ​ that is the equivalent for D Δ\mathcal{D}_\Delta D Δ​ to the naive search tree T Δ T_\Delta T Δ​ of G Δ\mathcal{G}_\Delta G Δ​. The vertices of F Δ F_\Delta F Δ​ are the flattened histories of events in D Δ\mathcal{D}_\Delta D Δ​:

V(F Δ)={f l a t({ δ })∣δ∈D Δ},V(F_\Delta) = \{flat(\{\,\delta\,\}) \mid \delta \in \mathcal{D}_\Delta\},V(F Δ​)={f l at({δ})∣δ∈D Δ​},

with an edge from f l a t({ δ p })flat(\{\,\delta_p\,\})f l at({δ p​}) to f l a t({ δ c })flat(\{\,\delta_c\,\})f l at({δ c​}) if there is a parent-child relation δ p∈P(δ c)\delta_p \in P(\delta_c)δ p​∈P(δ c​). We call F Δ F_\Delta F Δ​ the factorised search space of D Δ\mathcal{D}_\Delta D Δ​.

By construction, any graph G′∈V(T)G' \in V(T)G′∈V(T) in the naive search tree maps injectively to a subgraph S⊆F Δ S \subseteq F_\Delta S⊆F Δ​ of the factorised search space, given by the subgraph of F F F induced by the rewrites on the path from G GG to G′G'G′ in T T T.

Whereas our earlier discussion was focused on proving a lower bound for the size of the search tree, we now show an upper bound on the number of graphs ∣F Δ∣|F_\Delta|∣F Δ​∣ in the factorised search space.

#### Graph covering #

Instead of considering partitions of graphs in T Δ T_\Delta T Δ​ as we did above, we now consider coverings of graphs G′G'G′ in F Δ F_\Delta F Δ​, i.e. a set of subgraphs Γ 1,…,Γ n\Gamma_1, \ldots, \Gamma_nΓ 1​,…,Γ n​ such that their union is G′G'G′ but that might not be disjoint.

Let m mm, s ss and γ\gamma γ be parameters and fix a covering Γ 1,…,Γ m\Gamma_1, \ldots, \Gamma_mΓ 1​,…,Γ m​ for each graph G′∈V(F Δ)G' \in V(F_\Delta)G′∈V(F Δ​) such that:

- for all G′G'G′ and all 1⩽i⩽m 1 \leqslant i \leqslant m1⩽i⩽m, there are at most s ss applicable rewrites to the i ii-th covering set Γ i\Gamma_iΓ i​ of G′G'G′. Furthermore, all rewrites within Γ i\Gamma_iΓ i​ are mutually exclusive, i.e. they modify a shared subgraph so that it is never possible to apply more than one rewrite among the (up to s ss) applicable ones3;
- for all G′G'G′ and for all rewrites r r r that apply to G′G'G′, there is 1⩽i⩽m 1 \leqslant i \leqslant m1⩽i⩽m such that r r r applies to Γ i\Gamma_iΓ i​ (i.e. the matching subgraph of r r r is fully contained within one of the coverings). Furthermore, the matching subgraph of r r r overlaps with at most γ\gamma γ distinct Γ i\Gamma_iΓ i​;
- for all rewrites r r r that apply to the covering set Γ i\Gamma_iΓ i​ of a graph G′G'G′, the image r(Γ i)⊆Γ i′r(\Gamma_i) \subseteq \Gamma_i'r(Γ i​)⊆Γ i′​ must be a subgraph of the i ii-th covering subgraph Γ i′\Gamma_i'Γ i′​ of r(G′)r(G')r(G′).

The first condition is satisfied whenever the size of the coverings can be bounded: in that case s ss can be chosen based on the number of distinct subgraphs that can be contained in a covering set and the number of rules that can apply to each. The second condition is related to the connectivity between the covering sets: γ\gamma γ can thus often be derived by considering how many neighbours a covering set has, and how many of those neighbours can a match of a GTS rule span.

The third condition above can be understood as “rewrites must preserve the coverings”. In other words, the coverings are chosen such that a graph mutation produced by the application of a rewrite r∈E(F Δ)r \in E(F_\Delta)r∈E(F Δ​) on G GG is always contained within a single covering subgraph of r(G′)r(G')r(G′).

Hypothesis 2Linear scaling of m mm and constant s, γ s, \gammas, γ

For a fixed GTS, a fixed depth Δ\DeltaΔ and a family of input graphs G GG, we have the scaling m=Θ(∣G∣)m = \Theta(|G|)m=Θ(∣G∣) and s=Θ(1)s = \Theta(1)s=Θ(1) and γ=Θ(1)\gamma = \Theta(1)γ=Θ(1).

These conditions along with Hypothesis 2 are somewhat restrictive and future work should explore how to relax them. For our use cases `CompleteGTS` and `SingleRuleGTS`, we restrict our considerations to the special case where the graph domain is quantum circuits. We make the further simplifying assumptions (similar results can be obtained with variations on these assumptions)

- transformation rules have two-qubit circuits as left and right hand sides, and
- the number of qubits on the inputs is fixed (i.e. the number of gates on each qubit scales with circuit size).

Define ℓ\ellℓ to be the largest number of gates on any one qubit in the left hand sides of the GTS transformation rules. Consider a partition of the gates on each qubit into sequences of ℓ\ellℓ gates. We can obtain a covering of a quantum circuit G GG by considering covering sets Γ 1,…,Γ m\Gamma_1, \ldots, \Gamma_mΓ 1​,…,Γ m​ defined for all 1≤i≤m 1 \leq i \leq m1≤i≤m such that for all matches H H H of a left hand side of a transformation rule of the GTS, H⊆Γ i H \subseteq \Gamma_i H⊆Γ i​ if and only if there is a gate v v v in H H H such that v v v is in the i ii-th sequence of ℓ\ellℓ gate on some qubit in G GG. Imposing the condition that rewrites must preserve coverings, the covering of the input fixes the covering of all reachable graphs G′G'G′ in the GTS.

Proposition 5.7
Restrict the graph domain to quantum circuits, the GTS to two-qubit rules and the inputs to a fixed number of qubits. Then hypothesis 2 holds for `CompleteGTS` and for `SingleRuleGTS`.

Let G GG be the input circuit with q q q qubits. Consider the covering Γ 1,…,Γ m\Gamma_1, \dots, \Gamma_mΓ 1​,…,Γ m​ of G GG as constructed above. By construction m=⌈N/ℓ⌉=Θ(∣G∣)m = \lceil N / \ell \rceil = \Theta(|G|)m=⌈N/ℓ⌉=Θ(∣G∣), where N N N is the maximum number of gates on a qubit of G GG.

The covering set Γ i\Gamma_iΓ i​ contains the set V i V_i V i​ of gates composed of the i ii-th sequence of ℓ\ellℓ gates for each qubit in G GG. Furthermore, for all v∈V i v \in V_i v∈V i​, if H H H is a match of a two-qubit rule that contains v v v, then H H H may contain at most 2 ℓ−1 2\ell - 12ℓ−1 other gates. Hence by construction, ∣Γ i∣⩽2 ℓ∣V∣=2 q ℓ 2=Θ(1)|\Gamma_i| \leqslant 2\ell|V| = 2q\ell^2 = \Theta(1)∣Γ i​∣⩽2ℓ∣V∣=2 q ℓ 2=Θ(1). This is a constant and thus there is a constant s=Θ(1)s = \Theta(1)s=Θ(1) such that for all 1⩽i⩽m 1 \leqslant i \leqslant m1⩽i⩽m there are most s ss matches of a two-qubit rule that intersect Γ i\Gamma_iΓ i​.

Finally, any match H H H spans two qubits; the gates on each qubit (at most ℓ\ellℓ) may belong to at most two distinct sequences of ℓ\ellℓ gates of that qubit. Thus, any match H H H spans at most γ=4\gamma = 4 γ=4 distinct covering sets. These arguments made no assumption on properties of the rule set and thus apply equally to `CompleteGTS` and `SingleRuleGTS`.

#### Upper bound on ∣F Δ∣|F_\Delta|∣F Δ​∣ #

The preservation of coverings under rewrites allows us to consider a covering of V(F Δ)V(F_\Delta)V(F Δ​): for each 1⩽i⩽m 1 \leqslant i \leqslant m1⩽i⩽m, let F Δ(i)⊆V(F Δ)F_\Delta^{(i)} \subseteq V(F_\Delta)F Δ(i)​⊆V(F Δ​) be the set of graphs in V(F Δ)V(F_\Delta)V(F Δ​) that are the result of a rewrite of its i ii-th covering subgraph. Every graph in V(F Δ)V(F_\Delta)V(F Δ​) is the result of a rewrite on some covering subgraph i ii, or is the input graph G GG. So, from a bound U Δ⩾∣F Δ(i)∣U_\Delta \geqslant |F_\Delta^{(i)}|U Δ​⩾∣F Δ(i)​∣ for all 1⩽i⩽m 1 \leqslant i \leqslant m1⩽i⩽m, we can obtain a bound

∣V(F Δ)∣⩽1+m⋅U Δ.|V(F_\Delta)| \leqslant 1 + m \cdot U_\Delta.∣V(F Δ​)∣⩽1+m⋅U Δ​.

The bound U Δ U_\Delta U Δ​ can be obtained recursively: U 1=s U_1 = s U 1​=s upper bounds by definition the number of rewrites in any covering subgraph of the root graph G GG, and thus the number of graphs in F 1(i)F_1^{(i)}F 1(i)​. We then proceed by induction for 1<δ⩽Δ 1 < \delta \leqslant \Delta1<δ⩽Δ.

A rewrite r∈E(F Δ)r \in E(F_\Delta)r∈E(F Δ​) overlaps with at most γ\gamma γ other covering subgraphs. It can overwrite at most one previous rewrite for each subgraph, and thus will have at most γ\gamma γ parent graphs in sets F Δ−1(i 1),⋯ ,F Δ−1(i γ)F_{\Delta-1}^{(i_1)}, \cdots, F_{\Delta-1}^{(i_\gamma)}F Δ−1(i 1​)​,⋯,F Δ−1(i γ​)​. Each of the γ\gamma γ sets is of size at most U δ−1 U_{\delta - 1}U δ−1​. Furthermore, there are at most s ss rewrites in any covering subgraph. We thus obtain the recursion:

U δ⩽s⋅U δ−1 γ, U_\delta \leqslant s \cdot U_{\delta - 1}^\gamma, U δ​⩽s⋅U δ−1 γ​,

Unrolling the recursion, we can write this as

U δ⩽s 1+γ+γ 2+⋯+γ δ−1=s γ δ−1 γ−1=s Θ(γ δ−1).U_\delta \leqslant s^{1 + \gamma + \gamma^2 + \dots + \gamma^{\delta - 1}} = s^{\frac{\gamma^\delta - 1}{\gamma - 1}} = s^{\Theta(\gamma^{\delta - 1})}.U δ​⩽s 1+γ+γ 2+⋯+γ δ−1=s γ−1 γ δ−1​=s Θ(γ δ−1).

Recalling that by construction ∣F Δ∣=∣D Δ∣|F_\Delta| = |\mathcal{D}_\Delta|∣F Δ​∣=∣D Δ​∣, we obtain:

Proposition 5.8Upper bound for ∣D Δ∣|\mathcal{D}_\Delta|∣D Δ​∣

The factorised search space size ∣D Δ∣|\mathcal{D}_\Delta|∣D Δ​∣ is in m⋅s Θ(γ Δ−1)m \cdot s^{\Theta(\gamma^{\Delta - 1})}m⋅s Θ(γ Δ−1).

### Discussion and empirical exploratory analysis #

We have derived bounds on the size of the search spaces and shown that under some assumptions on the properties of the GTS, the factorised search space grows linearly in the size of the input graph G GG. This stands in stark contrast to the lower bound of the naive search tree, which scales exponentially with the size of the input graph.

However, when considering the overall optimisation problem of finding the optimal solution over the set of reachable graphs in a GTS, the exponential overhead does not disappear: it is rather shifted to the extraction phase that relies on a SAT solver. It is therefore an open question whether the factorised search space can be used to improve optimisation problems on GTSs.

To this end, we devise a simple numerical experiment that assesses the potential of using the unfolding construction as presented in this chapter in the context of quantum computation optimisation.

The toy problem.We consider a very simple circuit optimisation problem that is desiged to require a deep search space (i.e. a large number of rewrites) to be solved. This will exacerbate the scaling difference between an optimiser that must traverse the naive search space and another that relies on the factorised representation instead.

The inputs are quantum circuits composed of two-qubit CX\textit{CX}CX and single-qubit Rz\textit{Rz}Rz rotation gates. The angles of the rotations are not relevant and set randomly. They are of the following form:

i.e. each pair of subsequent qubits have 2 CX\textit{CX}CX gates at either end and 10 Rz\textit{Rz}Rz rotation in-between, on the control qubits of the CX\textit{CX}CX gates. These circuits admit a very simple optimisation that can be expressed by the following two transformation rules:

Given the objective of minimising the number of CX\textit{CX}CX gates, the optimiser must commute the leftmost CX\textit{CX}CX gates through all of the rotation gates, until the two CX\textit{CX}CX on each qubit are adjacent and cancel out. We study the performance of the optimisers as we increase the number 2 q 2q2 q of qubits in the circuit.

Optimisers.We define two optimisers. Badger is a backtracking search through the naive search space of reachable graphs in the GTS: starting from the input, the search space is expanded by computing all possible rewrites at a given state. States with the lowest cost function are processed first. This is similar to an A* search Hart, 1968Peter Hart, Nils Nilsson and Bertram Raphael. 1968. A Formal Basis for the Heuristic Determination of Minimum Cost Paths. IEEE Transactions on Systems Science and Cybernetics 4, 2 (100--107). doi: 10.1109/tssc.1968.300136.

Seadog on the other hand performs the backtracking search on the factorised search space instead: when expanding a state of the search space, only rewrites that overlap with the last rewrite are considered and added to the search space, as discussed in section 5.4. In a second phase, the search space is encoded as a SAT problem that is solved using Z3 Moura, 2008Leonardo de Moura and Nikolaj Bjørner. 2008. Z3: An Efficient SMT Solver. In Tools and Algorithms for the Construction and Analysis of Systems. Springer Berlin Heidelberg, 337--340. doi: 10.1007/978-3-540-78800-3_24.

The Badger optimiser is released and publicly available as part of the open-source TKET package4. The Seadog optimiser on the other hand is still in early development; more benchmarks and a release will follow.

Results.We ran the experiment on an Apple M3 Max CPU (4.05GHz) for inputs between 2 22 (12 1212 gates) and 78 7878 qubits (468 468468 gates). Both optimisers ran on a single core. For each instance, we set a timeout of 2 22 seconds and report the relative CX\textit{CX}CX gate reduction, i.e.

CX init−CX final CX init.\frac{\textit{CX}_\text{init} - \textit{CX}_\text{final}}{\textit{CX}_\text{init}}.CX init​CX init​−CX final​​.

The results are shown in the figures on the right.

Discussion.On the left, we observe that both optimisers are able to find the optimum for circuits with up to 30 CX gates. Beyond that point, the time limit starts impacting Badger performance, which drops continuously and reaches 0% for inputs of 50 CX gates and above. Seadog on the other hand does not time out and is able to explore the entire (factorised) search space exhaustively up until 70 CX gates.

Observe that the Badger optimiser reaches the time limit for as few as 10 CX. Indeed, the complete naive search space size can be calculated to have 1 2 q 12^q12 q states (each pair of qubits can be in one of 12 states). For 2 q=6 2q = 62 q=6 we get 1728 17281728 states, but this already reaches over 2 0′000 20'00020′000 states for 2 q=8 2q = 82 q=8.

CX gate count reduction (left) and runtime (right) for the Badger and Seadog optimisers. 100% gate count reduction is optimal. A timeout was set to 2 seconds.

Size of factorised search space for Seadog.

On the other hand, the factorised search space will only contain 12 1212 states for each qubit pair. This results in a linear scaling of the search space size, as can clearly be seen in the second figure.

Where the runtime exceeds the 2 second timeout, this is due to pre- and post-optimisation steps such as memory allocation/deallocation, I/O, file parsing etc that are included in the measurements. The quadratic runtime scaling that we observe in Seadog is due to a hash function that is run on every state of the search space to detect and discard duplicates: as the number of states in the search space grows linearly with input size and each state requires a hash in linear time, the overall runtime grows quadratically. Future work may be able to address this issue by designing updateable hash functions that do not require the full graph to be rehashed when applying a local rewrite.

Future work should also investigate how to scale Seadog to larger input sizes on a broader class of problems. We have observed that the SAT-based extraction phase of Seadog corresponds to less than 1% of the runtime budget (under 15ms for all input sizes). Whilst being asymptotically exponential in the worst case, it is thus not currently a bottleneck. On the other hand, the number of states visited per second in the exploration phase is currently up to 10×10\times10× slower for Seadog compared to Badger. Further investigations into the causes of this are still required, but we expect that large performance improvements can be realised on the current implementation and as a result could scale to larger inputs.

1. The only constraint on the notion of graph size ∣⋅∣|\cdot|∣⋅∣ is that it must be compatible with the subgraph relation: if G⊆G′G \subseteq G'G⊆G′, then ∣G∣⩽∣G′∣.|G| \leqslant |G'|.∣G∣⩽∣G′∣. ↩︎

2. Note that this counting is already an act of clemency: we are not counting all permutations of the rewrites, which would be considered separately by a naive exploration that applies one graph rewrite at a time. In this case, the search tree for Δ=1\Delta = 1Δ=1 would contain n!⋅2 n n! \cdot 2^nn!⋅2 n graphs. ↩︎

3. This can always be made to hold by replacing any set of mutually disjoint rewrites with their cartesian product, in effect viewing the application of multiple disjoint rewrites as one large rewrite. Thi comes at the cost of a larger value for s. s.s. ↩︎

4. As a Python package on PyPI and a rust crate on crates.io). ↩︎

←Return to chapter