Circuit Design for K-coloring Problem and it's Implementation on Near-term Quantum Devices
CCircuit Design for K-coloring Problem and it’sImplementation on Near-term Quantum Devices
Amit Saha , , Debasri Saha , and Amlan Chakrabarti A. K. Choudhury School of Information Technology, University of Calcutta, Kolkata - 700 106, India ATOS, Pune, India
Abstract —Now-a-days in Quantum Computing, implementa-tion of quantum algorithm has created a stir since NoisyIntermediate-Scale Quantum (NISQ) devices are out in themarket. Researchers are mostly interested in solving NP-completeproblems with the help of quantum algorithms for its speed-up. As per the work on computational complexity by Karp[1], if any of the NP-complete problem can be solved then anyother NP-complete problem can be reduced to that problem inpolynomial time. In this Paper, K-coloring problem (NP-completeproblem) has been considered to solve using Grover’s search.A comparator-based approach has been used to implementK-coloring problem which enables the reduction of the qubitcost comparing to the state-of-the-art. An end-to-end automatedframework has been proposed to implement K-coloring problemfor any unweighted and undirected graph on any available NoisyIntermediate-Scale Quantum (NISQ) devices, which helps ingeneralizing our approach.
Index Terms —K-coloring problem, Grover’s Search, NISQ,
I. I
NTRODUCTION
As development of Noisy Intermediate-Scale Quantum(NISQ) computer [2] has achieved a remarkable success in re-cent times, everyone has shown a striking interest to implementquantum algorithms, which give a potential speedup over theirclassical counterparts. With the growing quantum wave, thereis a huge urge for implementing NP-complete problems onnear term quantum devices. It would be helpful for any naiveperson, if we could provide them with an automated end-to-end framework for implementing a NP-complete problem sothat they can easily map their computational problem withouthaving much knowledge about gate-based quantum circuitimplementation. In this paper, we have focused on K-coloringproblem.K-coloring problem finds whether a given graph’s verticesor nodes are properly colored or not using k colors by takinginto account that the every two vertices linked by an edge havedifferent colors. Suppose n is the number of nodes of a givengraph, k is the number of colors, then to find exact solutionusing classical algorithm requires O (2 n ∗ logk ) number of steps.Whereas, using the decision oracle and the diffusion operatorof Grover’s algorithm [3], finding the exact solution requires O √ N number of iterations where N is n ∗ logk . Previouslyin [4] [5], Graph coloring problem using Grover’s algorithmhas been discussed in the context of quantum system. But,in [6] SAT reduction technique has been used to solve 3-coloring problem and gave an end-to-end framework forimplementing it in IBMQ quantum processor [7]. For this SAT reduction technique, the qubit cost is immense, hence circuitcost becomes inefficient.In this paper, we have proposed an automated qubit cost-efficient comaparator-based approach to implement K-coloringproblem for mapping high level description to any hardware-specific low-level quantum operations with an abstraction. Thenovelty of this paper is as follows: • We propose an end-to-end automated framework for K-coloring problem using quantum search algorithm, whichtakes graph and number of color ( k ) as input and auto-matically implements on NISQ device. • We propose a comparator-based approach to implementthe K-coloring problem which has less qubit cost com-paring to the state-of-the-art. • The framework is designed in such a way that the Quan-tum solution of K-coloring problem can be mapped intoany available NISQ devices, which makes our approachgeneralized in nature.The structure of this paper is as follows. The synopsis ofGrover’s algorithm, Quantum circuits, and NISQ devices aredescribed in section II. In section III, proposed methodologyhas been discussed. Implementation of K-coloring problem hasbeen illustrated in section IV. Concluding remarks appear inSection V. II. B
ACKGROUND
In this section, we have mainly described about quantumcircuit, Grover’s algorithm and finally NISQ devices.
A. Quantum circuit
Any quantum algorithm can be expressed or visualized inthe form of quantum circuit. These quantum circuits constituteof logical qubits and quantum gates [8].
1) Qubits:
Logical qubit that is used to encode input oroutput of a quantum algorithm is known as data qubit. Thereis an another type of qubit that is used to store temporaryresults are known as ancilla qubit.
2) Quantum Gates:
Unitary quantum gates need to beapplied on qubits to modify the quantum state of a quantumalgorithm. To synthesize our proposed circuit, we use NOTgate, Controlled-NOT gate, Toffoli gate, Hadamard gate andMulti Control Toffoli gate(MCT). All the mentioned gatesexcept MCT are described in Table I. The description of MCTgate is as follows: a r X i v : . [ c s . ET ] S e p ABLE IM
ATRIX AND C IRCUIT R EPRESENTATION OF Q UANTUM G ATES
Quantum Gates Matrix Representation Circuit RepresentationHadamard Gate √ √ √ − √ Not Gate Controlled-NOT Gate
Toffoli Gate
Multi-Controlled Toffoli Gate:
There are n number ofinputs and outputs in an n -bit MCT. This MCT gate passesthe first n − inputs, which are referred as control bits to theoutput unaltered. It inverts the n th input, which is referred asthe target bit if the first n − inputs are all ones. An MCTgate is shown in Figure 1 Black dots • represent the controlbits and the target bit is denoted by a ⊕ . Fig. 1. Multi-Controlled Toffoli Gate
B. Grover’s Algorithm
Grover’s algorithm has two parts, namely oracle and dif-fusion operator. The oracle depends on the specific instanceof the search problem. The diffusion operator block is alsoknown as inversion about the average operator and it amplifiesthe amplitude of the marked state to increase its measurementprobability. The block diagram of a typical Grover’s algorithmis shown in Figure 2.
Fig. 2. Generalized Circuit for Grover’s algorithm [3]
To perform Grover’s search algorithm, at least n + 1 qubitsare required and the function f is encoded by a unitary U f : | x (cid:105) n ⊗ | y (cid:105) → | x (cid:105) n ⊗ | y ⊕ f ( x ) (cid:105) .More elaborately, The steps of the Grover’s algorithm areas follows: Initialization : The algorithm starts with the uniform su-perposition of all the basis states on input qubits n . The lastancilla qubit is used as an output qubit which is initialized to H | (cid:105) . Thus, we obtain the binary quantum state | ψ (cid:105) . Sign Flip : Flip the sign of the vectors for which U f givesoutput 1. Amplitude Amplification : We need to perform the inver-sion about the average of all coefficient of the quantum statefor a certain number of iterations to get the coefficient of themarked state is large enough that it can be obtained from ameasurement with probability close to 1. This phenomenonis known as amplitude amplification which is performed byusing diffusion operator.
Number of Iterations : Grover’s Search algorithm requires (cid:112)
N/M many iterations to get the probability of one of themarked states M out of total N number of states set. C. NISQ Devices
NISQ devices are “noisy,” due to the constraint of thenumber of qubits, hence one has to allow a certain rangeof error while estimating the simulated result of a quantumstate [2]. Superconducting quantum circuit, ion trap, quantumdot, neutral atom are the most popular NISQ technologiesto implement the quantum circuit. Every one of them havespecific qubit topology, as shown in Figure 3, so as to mapthe logical synthesized circuit to quantum hardware. Table IIillustrates certain 1-qubit and 2-qubit gates that are supportedby most of the quantum hardwares. One has to realize theirlogical quantum gates to these hardware-specific gates to makeit hardware compatible for implementation.
Fig. 3. Qubit Topology [7], [9]
III. P
ROPOSED M ETHODOLOGY OF C IRCUIT S YNTHESISFOR
K-C
OLORING P ROBLEM USING G ROVER ’ S A LGORITHM
The flowchart as shown in Figure 4 describes the completeflow of our proposed automated end-to-end framework. Ourframework is mainly based on three algorithms: AutoGenOra-cle K-color, MCT Realization and SABRE(Qubit Mapping).Firstly, adjacency matrix of the given graph and the numberof color ( k ) is given as input to AutoGenOracle K-color algo-rithm and we get the quantum circuit netlist in the form QASMas output. AutoGenOracle K-color algorithm automaticallygenerates Oracle circuit for K-coloring problem using Groversearch and is based on newly designed comparator. Now,MCT Realization algorithm takes generated circuit netlist asinput and realizes MCT gates to NISQ hardware compatible1-qubit and 2-qubit gates [10]. Finally SABRE [11] algorithmhas been used for mapping generated circuit to NISQ devicesbased on the qubit topology. ABLE IIG
ATE S ET FOR
NISQ D
EVICES gate type gate set1-qubit gates id, x, y, z, h, r2, r4, r8, rx, ry, rz, u1, u2, u3, s, t, sdg, tdg2-qubit gates swap, srswap, iswap, xy, cx, cy, cz, ch, csrn, ms, yy, cr2, cr4, cr8, crx, cry, crz, cu1, cu2, cu3, cs, ct, csdgFig. 4. Flowchart of our proposed work
This section outlines the proposed methodology for the Or-acle circuit synthesis of k-Coloring problem as an applicationof the Grover’s search algorithm.
A. Proposed Oracle for K-Coloring Problem
The quantum circuit block of Oracle for K-coloring problemis shown in Fig 7. The construction of Oracle for K-coloringproblem is divided into five parts starting with initialization,which is essentially required in Grover’s Algorithm.
1) Initialization:
If there are n vertices, e edges in theinput graph and k is the number of color, then the totalnumber of data qubits required to represent all the coloredvertices are n ∗ (cid:100) log k (cid:101) . The Oracle checks for all the rightcombination of properly colored vertices with k or less colorsfrom a combination of all possible colored vertices. Hence,a superposition of m = n ∗ (cid:100) log k (cid:101) qubits will generateall possible combination colored vertices. The initial dataqubits in Fig 7 include m qubits prepared in the groundstate | ψ (cid:105) = | (cid:105) ⊗ m , due to the re-usability property of ancillaqubits, r = n ancilla qubits in the exited state | θ (cid:105) = | (cid:105) ⊗ r (These r ancilla qubits are required to prepare Invalid Colordetector block and Comaprator block which are described innext subsection thoroughly), one ancilla qubit in the groundstate | ζ (cid:105) = | (cid:105) (1 ancilla is required iff invalid color exists),and one output qubit in the excited state | φ (cid:105) = | (cid:105) is requiredto perform CNOT/Toffoli/MCT operation of the Oracle. Thisentire initialization can be mathematically written as: | ψ (cid:105) ⊗ | θ (cid:105) ⊗ | ζ (cid:105) ⊗ | φ (cid:105) = | (cid:105) ⊗ m ⊗ | (cid:105) ⊗ r ⊗ | (cid:105) ⊗ | (cid:105)
2) Hadamard Transformation:
After the initialization, theHadamard transform H ⊗ m on data qubits and H on outputqubit is performed, therefore all possible states are superposedas | ψ (cid:105) ⊗ | θ (cid:105) ⊗ | ζ (cid:105) ⊗ | φ (cid:105) , where | ψ (cid:105) = 1 √ m m − (cid:88) i =0 | i (cid:105)| θ (cid:105) = | .....r ( times ) (cid:105)| ζ (cid:105) = | (cid:105)| φ (cid:105) = 1 √ | (cid:105) − | (cid:105) )
3) Proposed U f Transformation::
This proposed unitary U f transformation has two distinct parts. (1)Reduction of Invalid Colors: Since c = (cid:100) log k (cid:101) , hencewe consider maximum c colors. If c = k , then all colors arevalid colors, else there will be a set of c − k invalid colors.The search space should be optimized with valid colors. Thiscan be carried out using following steps: Qubit Activation:
Colors are needed to be numbered as { , , .... c − } . After Hadamard transformation, the inputdata qubit lines act as binary representation of combination ofall possible colored vertices. But, the oracle checks only thecombination of valid colors k . To make sure that the Oracleis checking only the k -colored combination of vertices, all theinput qubit lines are needed to be in the exited state | (cid:105) forthose particular combination of invalid colors by making inputqubit lines suitable as control lines for CNOT/Toffoli/MCToperation. A number of NOT gates have to be imposedon the input qubit lines, which are in the ground state | (cid:105) followed by the application of ’Invalid Color Detector’. This’Qubit Activation’ has to be applied again after ’Invalid ColorDetector’ to return back to initial superposed quantum state. Invalid Color Detector:
If any invalid color is detectedin any combination of colored vertices then that combinationis discarded using following function ICD (Invalid ColorDetector):
ICD ( I , I , .., I n , f ) = (cid:26) f = 0 , if I orI or..I n = Invalid color ; f = 1 , No invalid color . (1)Figure 5 describes the circuit synthesis of ’Invalid ColorDetector’ for n vertices, where I , I , .., I n are the data qubits. Fig. 5. Invalid Color Detector
A newly proposed binary com-parator circuit can be defined as:
Comparator ( a, b, f ) = (cid:26) f = 0 , if a = b ; f = 1 , a (cid:54) = b. (2)where a and b are the comparing inputs which representthe colored vertices of given graph and f is the ancilla qubit.Circuit synthesis for -qubit and 4-qubit comparator is shownin Figure 6. CNOT, NOT, Toffoli/MCT gates are used to designthe complete circuit synthesis for binary comparator. Fig. 6. Example Comparator: (a) 2-qubit; (b) 4-qubit
With the help of these invalid color reduction function andnewly proposed comparator, The design of U f of an Oraclefor K-coloring problem is effectively developed.
4) MCT Operation:
The output qubit state | φ (cid:105) is initiallyset as √ ( | (cid:105) − | (cid:105) ) . Applying an MCT gate on output lineconsidering ancilla qubits as control, results in an eigenvaluekickback − , which causes a phase shift for the respectiveinput state/states, which helps to find out all the combination ofproperly colored set of vertices. The algorithm that generatesthe gate level synthesis of the proposed method is outlined innext subsection. B. Proposed Algorithm for Oracle Circuit Synthesis
The proposed algorithm Algorithm 1 (AutoGenOracleK-Coloring) of automated oracular circuit synthesis for the K-coloring problem is illustrated in this subsection. The algo-rithm takes as input the adjacency matrix of the given graphand the number of colors k . The output of the algorithm iscircuit netlist in the form of QASM.From the details of adjacency matrix and the number ofgiven color, it can be easily estimated that the total number ofqubit lines required to generate the Oracle circuit. All the inputdata qubits are initialized with | (cid:105) followed by Hadamard,ancilla lines ( A r ) are initialized with | (cid:105) , ancilla line A r +1 is initialized with | (cid:105) and the output line is initialized with | (cid:105) followed by Hadamard. First of all, apply Invalid ColorDetector with suitable Qubit Activation (if invalid color exists)with I r , A r as control and A r +1 as target. Then, between twoadjacent vertices ( i, j ) , a comaparator circuit is used with twoinput lines ( i, j ) as control and the ancilla line( A r ) as outputand perform this same task for all the adjacent vertices. Then,an MCT gate is used with all the ancilla lines A r and A r +1 as control and the output line as output for the flip operationof Grover’s Oracle. To mirror everything of Oracle circuit, wehave repeated the previous steps as shown in Algorithm 1. C. Circuit Cost Estimation
The design of generalized Oracle for our algorithm isalready described. Now, the circuit cost analysis of oracularcircuit is given in Table III.
ALGORITHM 1:
AutoGenOracleK-Coloring( G ( V, E ) ) INPUT : Adjacency matrix adj ( n, n ) of graph(G) G ( V, E ) , V = n and E = e where, V is the set ofnodes and E is the set of edges, Number of inputdata qubit lines required I r = n ∗ (cid:100) log k (cid:101) (input linesfor n nodes and k colors) + ancilla lines required = n +1 ancila line for reduction of invalid colors(ifrequired) +1 (output line( O )), A r represents ancillaline where, ≤ r ≤ n , A r +1 represents ancilla linefor invalid color (if required). OUTPUT : Circuit netlist (QASM) Initialize I r input lines with | (cid:105) followed byHadamard gate, ancilla lines A r with | (cid:105) , A r +1 with | (cid:105) , and output line O with | (cid:105) followed by aHadamard gate. Apply Invalid Color Detector (if required) for allpossible invalid colors with suitable Qubit Activationwith I r , A r as control and A r +1 as target. l ← n , f ← for i ← to n − do r ← f , m ← f for j ← i + 1 to n do if adj ( i, j ) ← ( i and j are connected by anedge( e )) then Use a comparator circuit with the input lines( I i , I j ) corresponding ( i, j ) as control and theancilla line A r as target. r ← r + 1 end if end for if r > f + 1 then Use a Toffoli/MCT gate with all ancilla lines A r as control and A l as target l ← l − for m ← i + 1 to n do if adj ( i, j ) ← ( i and j are connected by anedge( e )) then Use a comparator circuit with the inputlines ( I i , I m ) corresponding ( i, j ) as controland the ancilla line A m as target. m ← m + 1 end if end for else if r = f + 1 then f ← f + 1 end if end for Use an MCT gate with all the ancilla lines A , A , . . . A r +1 as control and O as output. Repeat step 5-26.
Repeat step 4.
For n -vertices graph and k given color, n ∗ (cid:100) log k (cid:101) dataqubits are required. For n -vertices graph, at most n +1 number ig. 7. Block Diagram of Generalized Oracular CircuitFig. 8. Gate level representation of 3-coloring problem for example graphTABLE IIIC IRCUIT C OST A NALYSIS OF O RACLE
No. of Vertex Maximum Ancilla Required Maximum Gate Count n O ( n ) O ( n ∗ log n ) of ancilla are needed and at most O ( n ∗ log n ) gates arerequired to design the oracular circuit. The gate-optimizedcircuit synthesis of 3-coloring problem for example graph ofthree vertices with three connected edges ( K ) is shown inFigure 8. D. Diffusion
The second part of Grover’s algorithm is the circuit im-plementing the function of diffusion. When the operation isapplied to a superposition state, it actually keeps the com-ponent in the | ψ (cid:105) direction unchanged, while inverting thecomponents in dimensions that are perpendicular to | ψ (cid:105) . Thiscan be represented as I | ψ ⊥ (cid:105) = − I | ψ (cid:105) where, | ψ (cid:105) = 1 √ n n − (cid:88) i =0 | i (cid:105) The diffusion operator is a unitary matrix. The general ma-trix for the diffusion operator for an N -dimensional quantumsystem is shown in Fig. 9. Fig. 9. Matrix Representation of N-dimensional Diffusion Operator
IV. M
APPING OF
K-C
OLORING P ROBLEM TO
NISQD
EVICES
This section focuses on the mapping of generated Oraclecircuit to NISQ devices through MCT realization and SABREalgorithm for qubit mapping.
A. Realization of MCT Gate
Figure 10 shows how to decompose MCT gate to NISQcompatible 1-qubit and 2-qubit gates [10]. Firstly MCT gateneeds to be decomposed to MCZ gate. Then, the realization ofMCZ gate into MC R x ( π ) is performed. Lastly, MC R x ( π ) isreduced to 1-qubit and 2-qubit gates without using any ancillaqubit. B. Qubit Mapping to NISQ Devices
Since, our proposed quantum circuit is logical, hence thereis no constraint of qubit connectivity. For NISQ devices, thereexists specific qubit topology or coupling graph. Couplinggraph defines the interaction between two physical qubits.This varies for different NISQ devices. Thus, it is obviousthat mapping the logical circuit to the physical one is achallenge. The solution to this problem is the insertion ofSWAP gates between the two qubits to satisfy the hardwareconstraint without compromising on the logic of the quantumcircuit. The idea of a good qubit mapping problem is tominimize the number of SWAP insertion gates and minimizethe depth of the circuit. Li et. al. proposed SWAP-basedBidiREctional heuristic search algorithm (SABRE) in [11],which is a benchmark, since it deals with any arbitrary qubittopology for any NISQ device. Mainly three features makeSABRE stand out. Firstly, it doesn’t perform exhaustive searchon the entire circuit, but it performs SWAP-based heuristicsearch considering the qubit dependency. It then optimizesthe initial mapping using a novel reverse traversal technique.Last but not the least, the introduction of the decay effect forenabling the trade-off between the depth and the number ofgates of the entire algorithm. We use SABRE protocol so that ig. 10. (a) Decomposition of MCT to MCZ; (b) Decomposition of MCZ to MC R x ( π ) (c) Decomposition of 4-control R x ( π ) gate our proposed circuit can easily be mapped to any arbitraryqubit topology. C. Experimental result of K-coloring Problem in NISQ Device
As shown in Figure 8, the generated oracle circuit forexample graph has been taken as an example case for thesimulation of K-coloring problem which is performed onIBMQ cloud based physical device [7].
Fig. 11. Amplitudes of Quantum States
The resultant output after applying Grover’s operator isshown in Fig. 11, where the amplitude of the solutionstate has been amplified. The location of the solution statesare | (cid:105) , | (cid:105) , | (cid:105) , | (cid:105) , | (cid:105) , and | (cid:105) where , , and are the valid colors as wetake as invalid color. These are the properly colored vertexcombinations in the given example graph that solves the K-coloring problem with high probability. D. Comparative Analysis
As compared to [6], our proposed comparator-based oraclegives better reuslt with respect to data qubit and ancilla qubitas n ∗ (cid:100) log k (cid:101) and O ( n ) respectively. Table IV shows thecomparative analysis. TABLE IVC
OMPARATIVE A NALYSIS
Parameters Hu et. al. [6] This workData Qubit Cost n ∗ k n ∗ (cid:100) log k (cid:101) Ancilla Qubit Cost O (( n ∗ k ) ) O ( n ) Processor IBMQ Any NISQ Device
V. C
ONCLUSION
In this paper, we have proposed an automated end-to-endframework which includes mapping of K-coloring problem to any NISQ devices through automatic generation of Oraclecircuit using Grover search taking into account any undirectedand unweighted given graph and number of given color( k ), automatic MCT realization and automatic qubit mappingusing SABRE for given qubit topology. Our comparator-basedapproach has outperformed the reduction-based approach from3-SAT problem to 3-Color problem quite convincingly. Thedata qubit cost has been reduced to n ∗ (cid:100) log k (cid:101) whereas itwas n ∗ k . In future, the swap-operation can be used for re-usability of the qubits for further optimization while generatingthe Oracle circuit. A CKNOWLEDGMENT
This work has been supported by the grant from CSIR,Govt. of India, Grant No. 09/028(0987)/2016-EMR-I.R
EFERENCES[1] R. Karp, “Reducibility among combinatorial problems,” in
Complexityof Computer Computations , R. Miller and J. Thatcher, Eds. PlenumPress, 1972, pp. 85–103.[2] J. Preskill, “Quantum computing in the nisq era and beyond,”
Quantum , vol. 2, p. 79, Aug 2018. [Online]. Available: http://dx.doi.org/10.22331/q-2018-08-06-79[3] L. K. Grover, “A fast quantum mechanical algorithm for databasesearch,” 1996.[4] A. Saha, A. Chongder, S. B. Mandal, and A. Chakrabarti, “Synthesisof vertex coloring problem using grover’s algorithm,” in ,2015, pp. 101–106.[5] K. Shimizu and R. Mori, “Exponential-time quantum algorithms forgraph coloring problems,” 2019.[6] S. Hu, P. Liu, C. R. Chen, M. Pistoia, and J. Gambetta, “Reduction-based problem mapping for quantum computing,”
Computer , vol. 52,no. 6, pp. 47–57, 2019.[7] IBM, “IBMQ experience device,” 2018. [Online]. Available: https://quantumexperience.ng.bluemix.net/qx/devices[8] A. Barenco, C. H. Bennett, R. Cleve, D. P. DiVincenzo, N. Margolus,P. Shor, T. Sleator, J. A. Smolin, and H. Weinfurter, “Elementarygates for quantum computation,”