Deterministic Algorithms for Compiling Quantum Circuits with Recurrent Patterns
DDeterministic Algorithms for Compiling Quantum Circuits withRecurrent Patterns
Davide Ferrari , Ivano Tavernelli , and Michele Amoretti ∗ Department of Engineering and Architecture - University of Parma, Italy Quantum Information Science @ University of Parma, Italy IBM Research - Zurich, R¨uschlikon, Switzerland
Abstract
Current quantum processors are noisy, have limited coherence and imperfect gate implemen-tations. On such hardware, only algorithms that are shorter than the overall coherence time canbe implemented and executed successfully. A good quantum compiler must translate an inputprogram into the most efficient equivalent of itself, getting the most out of the available hard-ware. In this work, we present novel deterministic algorithms for compiling recurrent quantumcircuit patterns in polynomial time. In particular, such patterns appear in quantum circuitsthat are used to compute the ground state properties of molecular systems using the variationalquantum eigensolver (VQE) method together with the RyRz heuristic wavefunction Ans¨atz.We show that our pattern-oriented compiling algorithms, combined with an efficient swappingstrategy, produces – in general – output programs that are comparable to those obtained withstate-of-art compilers, in terms of CNOT count and CNOT depth. In particular, our solutionproduces unmatched results on RyRz circuits. keywords - Quantum compilation, Recurrent patterns, RyRz circuits
The idea of quantum computing arose in 1982 during a speech by Richard Feynman about the dif-ficulty of simulating quantum mechanical systems with classical computers [1]. Feynman suggestedthe simulation of these systems using quantum computers, i.e., controlled quantum mechanicalsystems able to mimic them. Since then, quantum computing and quantum information theorycontinued to advance, proving that universal quantum computers could become, for some applica-tions, more powerful than Turing machines [2]. Quantum computing will potentially have a deepimpact on a variety of fields, from quantum simulation in physics and chemistry [3], to machinelearning [4, 5, 6, 7, 8], artificial intelligence [9] and cryptography [10, 11, 12].Current quantum computers are noisy, characterized by a reduced number of qubits (5-50) withnon-uniform quality and highly constrained connectivity. Such devices may be able to performtasks which surpass the capabilities of today’s most powerful classical digital computers, but noisein quantum gates limits the size of quantum circuits that can be executed reliably. ∗ [email protected] a r X i v : . [ qu a n t - ph ] F e b
12 34 (a) Q : q • • • Q : q • • Q : q Q : q Q : q (b) Q : q • • • Q : q • × Q : q × • Q : q Q : q (c) Figure 1: Compiling the 5 qubit circuit shown in (b) onto a 5 qubit device, namely ibmq yorktown ,whose coupling map is depicted in (a) . The compiled circuit is shown in (c) . The problem of quantum compilation , i.e., device-aware implementation of quantum algorithms,is a challenging one. A good quantum compiler must translate an input program into the mostefficient equivalent of itself [13], getting the most out of the available hardware. In general, thequantum compilation problem is NP-Hard [14, 15]. On noisy devices, quantum compilation isdeclined in the following tasks: gate synthesis [16], which is the decomposition of an arbitraryunitary operation into a quantum circuit made of single-qubit and two-qubit gates from a universalgate set; compliance with the hardware architecture, starting from an initial mapping of the virtualqubits to the physical ones, and moving through subsequent mappings by means of a clever swappingstrategy; and noise awareness. Quality indicators of the compiled quantum algorithm are, forexample, circuit depth, number of gates and fidelity of quantum states [17].As an example of compliance with the hardware architecture, consider the problem of compilingthe circuit in Fig. 1b onto a device with a coupling map such as the one shown in Fig. 1a. One couldchoose a trivial initial mapping of virtual qubits to the physical ones, such as the one depicted inred to the left of the circuit in Fig. 1b. However, with such a mapping, the CNOT between qubits0 and 3 could not be directly executed on the device. A more suitable mapping is instead the oneshown in blue to the left of the circuit in Fig. 1c, as it enables the execution of all CNOTs onto thedevice at the cost of inserting only one SWAP gate.
In this paper, we present novel deterministic algorithms for compiling recurrent quantum circuitpatterns in polynomial time. In particular, such patterns appear in quantum circuits that are usedto compute the ground state properties of molecular systems using the variational quantum eigen-solver (VQE) method together with the RyRz heuristic wavefunction Ans¨atz [18]. We implementedour algorithms in a Python software denoted as PADQC (PAttern-oriented Deterministic Quan-tum Compiler) that we integrated with Qiskit’s SABRE swapping strategy [19] and compilationroutine [20], from now on denoted as Qiskit(SABRE).We benchmarked PADQC+Qiskit(SABRE) using different quantum circuits, assuming IBMQuantum hardware. We show that our integrated solution produces – in general – output programsthat are comparable to those obtained with state-of-art compilers, such as t | ket (cid:105) [21], in terms ofCNOT count and CNOT depth. In particular, our solution produces unmatched results on RyRzcircuits. 2he paper is organized as follows. In Section 2, we discuss the state of the art in quantumcompiling. In Section 3, we present our algorithms. In Section 4, we illustrate the experimentalevaluation of PADQC+Qiskit(SABRE). Finally, in Section 5, we conclude the paper with an outlineof future work. Recently, some noteworthy quantum compiling techniques have been proposed. Here we surveythose that have been implemented into actual compilers, and benchmarked.The approach proposed by Zulehner et al. [22] is to partition the circuit into layers, each layerincluding gates that can be executed in parallel. For each layer, a compliant CNOT mappingmust be found, starting from an initial mapping obtained from the previous layer. Denoting thenumber of physical qubits as m and the number of logical qubits as n , in the worst case there are m !( m − n )! possible mappings. Such a huge search space cannot be explored exhaustively. The A ∗ search algorithm is adopted, to find the less expensive swap sequence. Moreover, a lookaheadstrategy is adopted to minimize additional operations to switch between subsequent mappings. Theproposed solution is efficient in terms of running time and output depth, but may not be scalablebecause of the exponential space complexity of the A ∗ search algorithm [23].SABRE by Li et al. [19] is a SWAP-based bidirectional heuristic search method. It requiresa preprocessing phase consisting of the following steps. First of all, the distance matrix over thecoupling map is computed. Then, the directed acyclic graph that represents the two-qubit gatedependencies of the circuit is generated. A data structure denoted as F (front layer) is initialized asthe set of two-qubit gates without unexecuted predecessors. The preprocessing phase ends up withthe generation of a random initial mapping. Then, the compiling phase consists in iterating thefollowing steps over F , until F is empty. First, all executable gates are removed from F and theirsuccessors are added to F . Second, for those gates in F that cannot be executed, the best SWAPsequence is selected using an heuristic cost function based on distance matrix. Experiment resultsshow that SABRE can generate hardware-compliant circuits with less or comparable overhead,with respect to the approach proposed by Zulehner et al. [22].In Qiskit (version 0.20) [20], the compiling process is implemented by a customizable Pass Man-ager that schedules a number of different passes: layout selection, unrolling (i.e., gate synthesis),swap, gate optimization, and more. Four swap strategies are currently available: Basic, Stochastic,Lookahead and SABRE. The Stochastic strategy uses a randomized algorithm to map the inputcircuit to the selected coupling map. This means that a single run does not guarantee to producethe best result.Currently, the most advanced quantum compiler is t | ket (cid:105) [21], which is written in C++. Thecompiling process proceeds in two phases: an architecture-independent optimisation phase, whichaims to reduce the size and complexity of the circuit; and an architecture-dependent phase, whichprepares the circuit for execution on the target machine. The architecture-independent optimisa-tion phase consists of peephole optimizations (targeting small circuit patterns) and macroscopicoptimizations (aiming to identify high-level macroscopic structures in the circuit). The end prod-uct of this process is a circuit that can be scheduled for execution by the runtime environment, orsimply saved for later.In Section 4, we compare our PADQC+Qiskit(SABRE) integration with pure Qiskit(SABRE)and t | ket (cid:105) . 3 a) Figure 2: RyRz circuit example.
Most compiling approaches aim at finding a general purpose compiler, able to cope with any circuitwithout the possibility to make assumptions on its structure or characteristics. This kind of solution,although effective in many cases, may not be as much efficient when facing circuits characterizedby well-defined peculiar sequences, i.e., patterns , of two-qubit operators. This is particularly true ifthose patterns repeat themselves many times in a circuit and are not compliant with the quantumdevice connectivity.This is the case of RyRz circuits used to compute the ground state properties of molecularsystems with the variational quantum eigensolver (VQE) method. These circuits were introducedfor the first time in [18] as a heuristic hardware-efficient wavefunction Ans¨atz for the calculation ofthe electronic structure properties of small molecular systems such as hydrogen H , lithium hydride,LiH, and berillium hydride, BH , on a quantum computer. Contrary to other quantum circuitsinspired by classical wavefunction expansion techniques (e.g., the coupled cluster expansion [24, 25]),in this case the nature of the circuit is solely motivated by the requirement of producing an entangledwavefunction for the many-electron systems that optimally fits the connectivity of the hardwareat disposal. In most cases, the RyRz circuit offers a well balanced compromise between these tworequirements. These circuits, when implemented with full entanglement (Fig. 2), are characterizedby repeated sequences of a pattern that we denote as inverted CNOT cascade .In Sections 3.2 and 3.3, we illustrate these patterns and how their features can be exploited tolay out efficient compiling algorithms. From now on, it will be assumed that the connectivity ofthe quantum device on which the circuit has to be compiled is similar to those featured by IBMQuantum devices [26] (Fig. 3). Table 1 presents an overview of the designed algorithms and theirtime complexity, which is computed by taking into account the worst case scenario and the runningtime of the subroutines.The compilation process starts with Algorithm 1, which searches for patterns of interests andtransforms them so that they are more easily mappable to the coupling map. Then, Algorithm 4optimizes the circuit, removing double CNOTs and double H gates that may results from theprevious transformations. Finally, Algorithm 5 finds a suitable initial mapping for the circuit. We are interested in the so called
CNOT cascade , shown in Fig. 4a. This pattern plays a prominentrole in several quantum algorithms such as the one used to produce GHZ states [27, 28] as shownin Fig. 5.The coupling maps in Fig. 3 prevent from placing all CNOT gates like in the ideal GHZ circuit,i.e., making a
CNOT cascade where n − n th qubit. It is indeed possible to turn4 lgorithm Subroutines Time Complexity1 patterns CheckCascade O ( g ) CheckInverseCascade CheckCascade O ( m ) CnotCancellation O ( lm ) GateCancellation O ( lm ) Chain CheckForIsolated O ( n ) ExpandChain CheckForIsolated O (1) ExpandChain O (1) Table 1: Overview of proposed algorithms and their time complexity. Notation: n is the numberof qubits of the device, m is the number of qubits used by the compiled circuit, g is the number ofgates in the circuit and l the number of layers.
05 61 2 3 47 8 9141312111015 16 17 18 19 (a)
05 61 2 3 47 8 9141312111015 16 17 18 19 (b)
Figure 3: (a)
20 qubits ibmq tokyo and (b) ibmq almaden [26].5 a) •• •• •• •• •• •• •• • (b) Figure 4: (a)
CNOT cascade. (b)
Decomposition of a CNOT cascadethe ideal GHZ circuit into an equivalent one characterized by a unique sequence of CNOT gates.It would only be a slight change to the technique discussed in a previous work [29].However, this technique works only if the aim is to produce a GHZ state starting from a | (cid:105) ⊗ n .This paper wants to focus on a more general case, where a CNOT cascade could appear at anypoint in the circuit and no assumption can be done on the state of the system. | (cid:105) ⊗ n + | (cid:105) ⊗ n √ Figure 5: GHZ circuit.A possible solution is to exploit the nearest neighbor decomposition for a uniformly controlledgate studied by Tucci [30]. The only requirement for Tucci’s decomposition is that qubits are tobe arranged in a linear chain.To realize the decomposition in Fig. 4b, Algorithm 1 analyzes the circuit layer by layer and,when a CNOT gate is encountered, Algorithm 2 checks if that CNOT is the first of a CNOTcascade. Each encountered CNOT cascade is replaced by its nearest-neighbor decomposition and,at the end, Algorithm 1 returns a new transformed circuit. Since Algorithm 1 just loops over allgates in a circuit, its complexity is O ( g ) with g being equal to the number of gates of the circuit.Algorithm 2 analyzes the circuit starting from a CNOT gate; here before and after are setsof gates that can be applied before and after the decomposition. If a CNOT cascade is found ,the decomposition is applied between the before and after gates sets, otherwise an empty set isreturned. In Algorithm 2, gate t is the target of gate and if gate is a CNOT, gate c is the controlqubit of gate . As it is expected that cascades are no longer than the number of qubits in the circuit,the algorithm stops when, after M AX = 2 m layers have been checked, no pattern is found. Thetime complexity of Algorithm 2 is O ( m ). Usually the number of gates g is greater than m , thus,the complexity of Algorithm 1 is O ( g ).We recall that the aim is to compile circuits characterized by repeated patterns. Let us lookat the circuit in Fig. 6a, where multiple CNOT cascades are repeated one after the other, actingon different target qubits. Algorithm 1 outputs the circuit in Fig. 6b, which despite being correct,has an increased depth.Fortunately, if two consecutive CNOT gates act on the same control and target qubit, theyelide each other, as a CNOT gate is the inverse gate of itself. Algorithm 3 loops over the circuit tocancel double CNOT gates until no further cancellation can be done.6 lgorithm 1 Patterns( circuit ) Input : a quantum circuit circuit
Output : a new transformed circuit1: new circuit ← ∅
2: to skip ← ∅
3: new layers ← [ ∅ for ≤ i < | circuit layers | ]4: for i = 0 to | circuit layers | do if i (cid:54) = 0 then for all g ∈ new layers[ i − do
7: put g into new circuit end for end if for all gate ∈ circuit layers [ i ] do if gate (cid:54)∈ to skip then if gate is CNOT then
13: transformed ← CheckCascade( circuit layers , i , new layers) if trasnformed (cid:54) = ∅ then
15: put transformed into to skip16: continue else
18: put gate into to skip19: put gate into new circuit end if else
22: put gate into to skip23: put gate into new circuit end if end if end for end for return new circuit lgorithm 2 CheckCascade( layers , i , new layers ) Input : the list of layers in the circuit layers ; the layer from where to start i ; the list of new layers to be added Output : the list of gates to skip, ∅ if no cascade was found
1: before ← ∅ , after ← ∅ , skip ← ∅ , off limits ← ∅ ,control ← cnot c , target ← cnot t , used ← ∅ , found ← false , ctrls ← ∅ , put target into used, i ← gate ← circuit [0], c ←
0, last ← i while i < MAX do for all gate ∈ layers [ i + c ] do if gate ∈ skip and gate t = target then c ← MAX break else if gate is a CNOT then if gate c = target then count ← MAX break else if gate c ∈ off limits or gate t ∈ off limits then
13: put gate c into off limits14: put gate c into used15: put gate t into off limits16: put gate t into used17: continue end if if gate t = target and gate c (cid:54)∈ ctrls and gate c (cid:54)∈ used then
20: put gate c into ctrls21: put gate c into used22: put gate into skip23: else if gate t (cid:54) = target and gate c (cid:54) = target then if gate t (cid:54)∈ used and gate c (cid:54)∈ used and last < c then
25: last ← i + c else
27: put gate c into off limits28: put gate c into used29: put gate t into off limits30: put gate t into used31: if last > i + c − then
32: last ← i + c − end if end if else count ← MAX break end if else if gate t ∈ off limits then continue else if gate t = target then
43: put gate into after44: put gate into skip45: c ← MAX break else if gate t (cid:54)∈ used then
48: put gate into before49: else
50: put gate into after51: end if
52: put gate into skip53: end if end if end for c ← c + 157: end while if | controls | > then for all g ∈ before do
60: put g into new layers [last]61: end for for all x ∈ reversed(ctrls) ∪ target do
63: put cnot x,x.next into new layers [last]64: end for for all y ∈ ctrls do
66: put cnot y,y.next into new layers [last]67: end for for all g ∈ after do
69: put g into new layers [last]70: end for return skip72: end if return ∅ ··· q • ··· q • • ··· q • • ··· q • • ··· q • • ··· q • • ··· q • • ··· q • • ··· • q • • ··· • (a) q ··· q • ··· q • • • ··· q • • • • ··· q • • • • ··· q • • • • ··· q • • • • ··· q • • • • ··· q • • • • ··· • q • • • • ··· • • (b) q q • q • q • q • q • q • q • q • q • • (c) Figure 6: (a)
Circuit with multiple CNOT cascades. (b)
Circuit after nearest-neighbor decompo-sition. (c)
Circuit after CNOT cancellation. q • • • • • • • • • ··· q • • • • • • • • ··· q ··· q ··· q ··· q ··· q ··· q ··· • • q ··· q ··· Figure 7: Circuit with multiple inverse CNOT cascades.Since each layer in the circuit has at most m gates, in the worst case Algorithm 3 needs m iterations to cancel every CNOT couple. Its time complexity is O ( lm ), where l is the number oflayers and usually m (cid:28) l . Algorithm 3
CnotCancellation( circuit ) Input : a quantum circuit circuit
Output : a new circuit without double CNOTs1: changed ← true while changed is true do
3: changed ← false for all layer ∈ circuit do for all gate ∈ layer do if gate is cnot then if cnot gate c ,gate t ∈ layer.next then
8: remove gate from layer
9: remove cnot gate c ,gate t from layer.next
10: changed ← true end if end if end for end for end while The result of such an optimization is shown in Fig. 6c. This new optimized circuit has a muchmore acceptable depth, even lower than the original circuit shown in Fig. 6a.
The pattern characterizing RyRz circuits, shown in Fig. 7, is very similar to the one in Fig. 4a.Indeed this pattern can be turned into the other one by inverting all of its CNOT gates by meansof H gates on both control and target qubits before and after the CNOT. Of course adding H H H • H H • H H • H H • H H • H H • H H • H H • H H • H H ··· q H H H H H H • H H • H H • H H • H H • H H • H H • H H • H H ··· q H H H H H H H H ··· q H H H H H H H H ··· q H H H H H H H H ··· q H H H H H H H H ··· q H H H H H H H H ··· q H H H H H H H H ···
H H • H H • H Hq H H H H H H H H ···
H H H Hq H H H H H H H H ···
H H H H (a) q H H ··· q H • H H H ··· q H • • H H • H ··· q H • • H H • • H ··· q H • • H H • • H ··· q H • • H H • • H ··· q H • • H H • • H ··· q H • • H H • • H ··· H Hq H • • H H • • H ··· H • Hq H • • H H • • H ··· H • • H (b) q H Hq H • Hq H • Hq H • Hq H • Hq H • Hq H • Hq H • Hq H • Hq H • • H (c) Figure 8: (a)
Circuit with multiple inverse CNOT cascades after CNOT inversion. (b)
Circuit withmultiple inverse CNOT cascades after nearest-neighbor decomposition. (c)
Circuit with multipleinverse CNOT cascades after gates cancellation.gates to invert a CNOT would alter the circuit identity, therefore, instead of adding an H gate,two H gates are added so that they can negate each other’s effects and leave the circuit identityuntouched. The result of this operation is shown in Fig. 8a.Using an algorithm similar to Algorithm 2, with the roles of control and target qubits exchanged,and a slight modification to Algorithm 1, the circuit in Fig. 8a can be compiled obtaining the onein Fig. 8b. Algorithm 4 optimizes the circuit producing the one shown in Fig. 8c. Like in theprevious case, the depth of the recompiled circuit is very close to the original. The time complexityof Algorithm 4 is O ( lm ). Algorithm 4
GateCancellation( circuit ) Input : circuit a quantum circuit Output : a new circuit without double CNOTs and double H
1: changed ← true while changed is true do
3: changed ← false for all layer ∈ circuit do for all gate ∈ layer do if gate is cnot then if cnot gate c ,gate t ∈ layer.next then
8: remove gate from layer
9: remove cnot gate c ,gate t from layer.next
10: changed ← true end if else if gate is H then if gate ∈ layer.next then
14: remove gate from layer
15: remove gate from layer.next
16: changed ← true end if end if end for end for end while
05 61 2 3 47 8 9141312111015 16 17 18 19
Figure 10: Qubit chain in ibmq almaden highlighted in red.
In the previous section we showed how to transform inverted CNOT cascades into nearest-neighborCNOT sequences. Clearly such a sequence of gates, where every qubit q i controls q i +1 , cannot bedirectly executed on the coupling map in Fig. 3b, as q i is not always connected with q i +1 .A possible solution is to find a path in the coupling map such that every qubit q i , with 1
1, with n being the number of qubits in the device, has a connection with its nearestneighbors q i − and q i +1 . This is related to the problem of finding an Hamiltonian path , i.e., a paththat visits each vertex of a graph exactly once. The Hamiltonian path problem is a special case ofthe
Hamiltonian cycle problem and is known to be NP-Complete, in fact it is an instance of thefamous traveling salesman problem [31].Fortunately, one can take advantage of the features of the coupling map such as its regularstructure and the fact that every qubit is identified by a number ranging from 0 to n . As eachundirected link can be seen as a couple of ingoing and outgoing links, the path obtained resemblesa chain and will be denoted as such, from now on.Algorithm 5 computes a chain in an undirected graph G starting from node 0, where C is thechain initialized as empty, S is the set of nodes to be explored and N x is the set of neighbors ofnode x . The algorithm loops over the nodes until the set of explored nodes E is equal to the set ofnodes in G . For every node added to C , the chain() algorithm checks if the node’s neighbors leadto a dead end, i.e., are isolated. If one neighbor is found to be isolated, it is added to the set ofisolated nodes I and also to E .After executing Algorithm 5 on the coupling map in Fig. 3b, the path obtained can be used toformulate an initial layout for the circuit in Fig. 9, such that logical qubit q i corresponds to chainelement C [ i ]. Fig. 10 shows the path obtained in the coupling map highlighted in red. Such aninitial layout eliminates the need to use SWAP gates and produces a circuit with ideally no increasein depth. 11 lgorithm 5 Chain( G , n ) Input : undirected graph G ; number of qubits n used by the circuit Output : a chain C connecting at least n nodes in G C ← ∅ S ← all nodes of G
3: put 0 into C S ← S / E ←
I ← ∅ x = C [ |C| − last back step ← − while |E| < |G| do N ← N x /E if |N | (cid:54) = ∅ then if x + 1 ∈ N x then x ← x + 114: else x ← min ( N x )16: end if
17: put x into E
18: put x into C S ← S /x if |E| < |G| − then N ← ∅ for all q ∈ N x do if q (cid:54)∈ E then
24: remove= true if | N q | = 1 and |E < | G | − | then
26: put q into E S ← S /q
28: put q into I continue end if for all r ∈ N q do if r (cid:54)∈ E and r = x then
33: remove= false end if if remove= true then
36: put q into E S ← S /q
38: put q into I end if end for end if end for end if else if last back step (cid:54) = C [ |C| − and |G| − |E| > | current − S [0] | then break end if
48: put x into I C ← C /x x ← C [ |C| − last back step ← x end if end while if |C| ≥ n then return C end if CheckForIsolated( G , C , E , I ) ExpandChain( G , C , I , n ) return C lgorithm 6 CheckForIsolated( G , C , E , I ) Input : an undirected graph G ; C a chain of nodes in G ; E nodes already explored; I nodes left outside C duringexploration1: for m = 0 to |G| − do if m (cid:54)∈ E and m (cid:54)∈ I then for all i ∈ I do if m ∈ N i then
5: put m into I
6: put m into E break end if end for for all n ∈ N m do if n ∈ C then
12: put m into I
13: put m into E break end if end for end if end for Algorithm 7
ExpandChain( G , C , I , n ) Input : an undirected graph G ; C a chain of nodes in G ; I nodes left outside C during exploration; n the number ofqubits used by the circuit1: r ← ( n − |C| )2: while r > do for all m ∈ I do x ← min ( N m ∩ C )5: if x (cid:54) = ∅ then
6: put m into C after x I ← I /m r ← r − break end if end for end while n nodes in the map, the timecomplexity of Algorithm 5 is O ( n ). We implemented the algorithms presented in Section 3 in a quantum compiler written in Pythonlanguage, denoted as PADQC . In the PADQC framework, quantum circuits are represented by QCircuit objects, which are based on the well known formalism of Directed Acyclic Graphs (DAGs).In DAGs, nodes represent quantum gates and the edges connecting them correspond to qubits andbits. A
QCircuit can then be easily converted into Open QASM [32] and vice versa, allowing PADQCto interact with Qiskit.
CNOT Gate Count ibmq tokyo ibmq almaden
Circuit Name n Initial Qiskit(SABRE) PADQC+Qiskit(SABRE) t | ket (cid:105) Qiskit(SABRE) PADQC+Qiskit(SABRE) t | ket (cid:105) H2 RYRZ 4 30 30 21 30 60 21 70LiH RYRZ 12 330 788 101 898 1256 101 1260H2O RYRZ 14 455 1242 121 1301 1763 121 1738Random 20q RYRZ 20 950 2735 182 3053 3976 201 4146
Table 2: Circuit CNOT gate count of the compiled quantum chemistry circuits, considering the ibmq tokyo and ibmq almaden architectures.
CNOT Depth ibmq tokyo ibmq almaden
Circuit Name n Initial Qiskit(SABRE) PADQC+Qiskit(SABRE) t | ket (cid:105) Qiskit(SABRE) PADQC+Qiskit(SABRE) t | ket (cid:105) H2 RYRZ 4 21 21 21 21 60 21 70LiH RYRZ 12 69 488 101 575 648 101 703H2O RYRZ 14 81 675 121 813 846 121 875Random 20q RYRZ 20 117 1361 182 1648 1562 201 1629
Table 3: Circuit CNOT depth of the compiled quantum chemistry circuits, considering the ibmq tokyo and ibmq almaden architectures.Using an Intel Xeon E5-2683v4 2.1GHz with 50 GB of RAM, we benchmarked the quantumcompiler with different quantum circuits. In particular, we considered a few quantum chemistrycircuits for the RyRz heuristic [18] wavefunction Ans¨atz (Fig. 2), and an heterogeneous set ofquantum circuits that has been used in most reference works [19, 22]. We assumed IBM Quantumhardware, namely ibmq tokyo and ibmq almaden architectures. They both have 20 qubits, but theircoupling maps are quite different (Fig. 3).We compared Qiskit(SABRE) with t | ket (cid:105) and Qiskit(SABRE) preceded by PADQC transfor-mations and mapping. Given that on NISQ devices multi-qubit operations tend to have error ratesand execution times an order of magnitude worse than single-qubit ones [33], the performance in-dicators used are CNOT gate gate count and CNOT depth of the circuit, i.e., the depth of thecircuit taking into account only CNOT gates. As shown in Table 2 and Table 3, the combination Source code: https://github.com/qis-unipr/padqc
14f PADQC and Qiskit(SABRE) outperforms both Qiskit(SABRE) alone and t | ket (cid:105) on all RyRzcircuits tested, regardless of the considered architecture.We also tested PADQC on a larger set of circuits. We compiled a total of 190 circuits , takenfrom RevLib [34], Quipper [35] and Scaffold [36], plus the quantum chemistry ones. The results aresummarized in Fig. 11 to 12, where the initial value of the considered metric is on the x-axis andthe value for the compiled circuit on the y-axis.When compiling on the ibmq tokyo architecture, we can see, with the help of tendency linescalculated using the least squares method, that the combination of PADQC and Qiskit(SABRE)not only boosts Qiskit(SABRE) performance but can also compete with t | ket (cid:105) . As we switch tothe less connected ibmq almaden architecture, PADQC can still boost Qiskit(SABRE) performancewhile being up to par with t | ket (cid:105) . In this paper, we proposed novel deterministic algorithms for compiling recurrent quantum circuitpatterns in polynomial time. Starting from this set of algorithms, we have implemented PADQC,which has two main features. First, it identifies CNOT cascades and exploits useful circuit identitiesto transform them into CNOT nearest-neighbor sequences. Second, it finds an initial mapping thatcan comply with circuits characterized by recurrent CNOT nearest-neighbor sequences. Finally, weintegrated PADQC with Qiskit’s SABRE swapping strategy and compilation routine.We illustrated the results of the experimental evaluation of our integrated solution using differentquantum programs and assuming IBM Quantum hardware. Among others, we compiled quantumcircuits that are used to compute the ground state properties of molecular systems using theVQE method together with the RyRz heuristic wavefunction Ans¨atz. PADQC+Qiskit(SABRE),in general, produces output programs that are on par with those produced by state-of-art tools, interms of CNOT count and CNOT depth. In particular, our solution produces unmatched resultson RyRz circuits.In future work, we plan to expand PADQC to other patterns of interests and look for furthercircuit identities as the one found between nearest-neighbor CNOT sequences and CNOT cascade.These identities proved to be crucial in the quest for optimal quantum compilation. Moreover,we will investigate to possibility of integrating PADQC pattern transformation and mapping al-gorithms with alternative swapping strategies, which could produce an appreciable performanceimprovement.While effective, CNOT count and CNOT depth are only pseudo-objectives. What really mattersis the fidelity of a computation when run on actual quantum hardware. We believe that the proposedcompiler could be enhanced with noise related information (such as gate error rates and decoherencetimes) with the aim of finding a good trade-off between circuit depth and computation fidelity.
Acknowledgements
This research benefited from the HPC (High Performance Computing) facility of the University ofParma, Italy. Benchmark circuits QASM files: https://github.com/qis-unipr/padqc/tree/master/benchmarks_qasm ibmq tokyo and ibmq almaden . 16igure 12: Comparing the CNOT depth of the circuits compiled on ibmq tokyo and ibmq almaden .17 eferences [1] R. P. Feynman. Simulating physics with computers.
International Journal of TheoreticalPhysics , 21(6-7):467–488, 1982.[2] P. W. Shor. Algorithms for quantum computation: discrete logarithms and factoring. In
Proceedings 35th Annual Symposium on Foundations of Computer Science , pages 124–134,1994.[3] A. Chiesa, F. Tacchino, M. Grossi, P. Santini, I. Tavernelli, D. Gerace, and S. Carretta.Quantum hardware simulating four-dimensional inelastic neutron scattering.
Nature Physics ,15:455–459, 2019.[4] S. Lloyd, M. Mohseni, and P. Rebentrost. Quantum principal component analysis.
NaturePhysics , 10(9):631–633, 2014.[5] Jacob Biamonte, Peter Wittek, Nicola Pancotti, Patrick Rebentrost, Nathan Wiebe, and SethLloyd. Quantum machine learning.
Nature , 549(7671), September 2017.[6] Vojtˇech Havl´ıˇcek, Antonio D. C´orcoles, Kristan Temme, Aram W. Harrow, Abhinav Kandala,Jerry M. Chow, and Jay M. Gambetta. Supervised learning with quantum-enhanced featurespaces.
Nature , 567(7747):209–212, March 2019.[7] Christa Zoufal, Aur´elien Lucchi, and Stefan Woerner. Quantum Generative Adversarial Net-works for learning and loading random distributions. npj Quantum Information , 5(1):1–9,November 2019.[8] Iris Cong, Soonwon Choi, and Mikhail D. Lukin. Quantum convolutional neural networks.
Nature Physics , 15(12), December 2019.[9] F. Tacchino, C. Macchiavello, D. Gerace, and D. Bajoni. An artificial neuron implemented onan actual quantum processor.
NPJ Quantum Information , 5:26:1–8, 2019.[10] A. K. Ekert. Quantum cryptography based on Bell’s theorem.
Phys. Rev. Lett. , 67:661–663,1991.[11] C. Portmann and R. Renner. Cryptographic security of quantum key distribution.arxiv:1409.3525, 2014.[12] Joseph F. Fitzsimons. Private quantum computation: an introduction to blind quantumcomputing and related protocols. npj Quantum Information , 3(1), June 2017.[13] A. D. C´orcoles, A. Kandala, A. Javadi-Abhari, D. T. McClure, A. W. Cross, K. Temme, P. D.Nation, M. Steffen, and J. M. Gambetta. Challenges and opportunities of near-term quantumcomputing systems.
Proceedings of the IEEE , 108(8):1338–1352, 2020.[14] A. Botea, A. Kishimoto, and R. Marinescu. On the Complexity of Quantum Circuit Com-pilation. In
The Eleventh International Symposium on Combinatorial Search (SOCS 2018) ,2018.[15] M. Soeken, G. Meuli, B. Schmitt, F. Mozafari, H. Riener, and G. De Micheli. Boolean satisfi-ability in quantum compilation.
Phil. Trans. Royal Soc. A , 378(2164):1–16, 2019.1816] V. Kliuchnikov, D. Maslov, and M. Mosca. Practical Approximation of Single-Qubit Uni-taries by Single-Qubit Quantum Clifford and T Circuits.
IEEE Transactions on Computers ,65(1):161–172, 2016.[17] E. Munoz-Coreas and H. Thapliyal. Quantum circuit design of a T-count optimized integermultiplier.
IEEE Transactions on Computers , 68(5):729–739, 2019.[18] Abhinav Kandala, Antonio Mezzacapo, Kristan Temme, Maika Takita, Markus Brink, Jerry M.Chow, and Jay M. Gambetta. Hardware-efficient variational quantum eigensolver for smallmolecules and quantum magnets.
Nature , 549(7671):242–246, September 2017.[19] Gushu Li, Yufei Ding, and Yuan Xie. Tackling the qubit mapping problem for nisq-era quan-tum devices. In
Proceedings of the Twenty-Fourth International Conference on ArchitecturalSupport for Programming Languages and Operating Systems , ASPLOS ’19, page 1001–1014,2019.[20] H´ector Abraham et al. Qiskit: An open-source framework for quantum computing, 2019.[21] Seyon Sivarajah, Silas Dilkes, Alexander Cowtan, Will Simmons, Alec Edgington, and RossDuncan. t | ket (cid:105) : a retargetable compiler for NISQ devices. Quantum Science and Technology ,6(1):014003, 2020.[22] Alwin Zulehner, Alexandru Paler, and Robert Wille. An efficient methodology for mappingquantum circuits to the IBM QX architectures.
IEEE Trans. on CAD of Integrated Circuitsand Systems , 38(7):1226–1236, 2019.[23] S. Russell and P. Norvig.
Artificial Intelligence: A Modern Approach 4th Edition . Pearson,2020.[24] A. Peruzzo, J. McClean, P. Shadbolt, M.-H. Yung, X.-Q. Zhou, P. J. Love, A. Aspuru-Guzik,and J. L. O’Brien. A variational eigenvalue solver on a photonic quantum processor.
NatureCommunications , 5(4213):1–7, 2014.[25] Panagiotis Kl. Barkoutsos, Jerome F. Gonthier, Igor Sokolov, Nikolaj Moll, Gian Salis, AndreasFuhrer, Marc Ganzhorn, Daniel J. Egger, Matthias Troyer, Antonio Mezzacapo, Stefan Filipp,and Ivano Tavernelli. Quantum algorithms for electronic structure calculations: Particle-holeHamiltonian and optimized wave-function expansions.
Phys. Rev. A , 98:022322, Aug 2018.[26] IBM. Quantum computation center opens.[27] D. M. Greenberger, M. A. Horne, and A. Zeilinger. Going beyond bell’s theorem. In M. Kafatos,editor,
Bell’s Theorem, Quantum Theory, and Conceptions of the Universe , pages 69–72.Kluwer Academic Publishers, 1989.[28] S. Deffner. Demonstration of entanglement assisted invariance on IBM’s quantum experience.
Heliyon , 3(11), 2017.[29] D. Ferrari and M. Amoretti. Efficient and effective quantum compiling for entanglement-basedmachine learning on ibm q devices.
International Journal of Quantum Information , 16(08),2018.[30] Robert R. Tucci. QC Paulinesia. arxiv:0407215, July 2004.1931] C. H. Papadimitriou and K. Steiglitz.
Combinatorial Optimization: Algorithms and Complex-ity . Dover Books on Computer Science. Dover Publications, 1998.[32] Andrew W. Cross, Lev S. Bishop, John A. Smolin, and Jay M. Gambetta. Open QuantumAssembly Language. arxiv:1707.03429, 2017.[33] Frank Arute, Kunal Arya, Ryan Babbush, Dave Bacon, et al. Quantum supremacy using aprogrammable superconducting processor.
Nature , 574(7779):505–510, Oct 2019.[34] R. Wille, D. Große, L. Teuber, G. W. Dueck, and R. Drechsler. Revlib: An online resourcefor reversible functions and reversible circuits. In
SIGPLAN Not. , 48(6):333–342,June 2013.[36] Ali JavadiAbhari, Shruti Patil, Daniel Kudrow, Jeff Heckey, Alexey Lvov, Frederic T. Chong,and Margaret Martonosi. Scaffcc: Scalable compilation and analysis of quantum programs.