Graph coloring using the reduced quantum genetic algorithm

Genetic algorithms (GA) are computational methods for solving optimization problems inspired by natural selection. Because we can simulate the quantum circuits that implement GA in different highly configurable noise models and even run GA on actual quantum computers, we can analyze this class of heuristic methods in the quantum context for NP-hard problems. This paper proposes an instantiation of the Reduced Quantum Genetic Algorithm (RQGA) that solves the NP-hard graph coloring problem in O(N1/2). The proposed implementation solves both vertex and edge coloring and can also determine the chromatic number (i.e., the minimum number of colors required to color the graph). We examine the results, analyze the algorithm convergence, and measure the algorithm's performance using the Qiskit simulation environment. Our Reduced Quantum Genetic Algorithm (RQGA) circuit implementation and the graph coloring results show that quantum heuristics can tackle complex computational problems more efficiently than their conventional counterparts.

: Panel a) shows the Erdős-Rényi graph generated with edge probability 0.4 and 4 nodes, which we used for the coloring problem. Panel b) shows the same graph colored with the solution found by our algorithm. Nodes 1, 2, and 3 have the same color and node 0 is colored differently. The best result for this graph uses only 2 colors.The chromatic number for this graph is 2 and the algorithm, even if it is configured to use 3 colors, it determined that the best solution for coloring the graph is by using only 2 colors, thus determining both the coloring and the chromatic number. Panel c) depicts the experimental results; in each iteration the algorithm found only best solutions.  Figure S2: Panel a) shows an Erdős-Rényi graph generated with an edge probability of 0.4 and 4 nodes, which we used for coloring problem. Panel b) shows the same graph colored with the solution found by the algorithm. The result for this graph uses only 2 colors, so that nodes 1 and 2 share one color while nodes 0 and 3 are colored using the second one. The chromatic number for this graph is 2 and the algorithm, even if it is configured to use 3 colors, it determined that the best solution for coloring the graph is by using only 2 colors, thus determining both the coloring and the chromatic number. Panel c) depicts the experimental results, in each iteration, the algorithm found only best solutions with a maximum of 5 solutions found after 4 iterations. (c) Figure S3: Panel a) shows the Erdős-Rényi graph generated with edge probability 0.4 and 4 nodes, which we used for the coloring problem. Panel b) shows the same graph colored with the solution found by our algorithm. The result for this graph uses only 2 colors: nodes 0, 1 and 2 have the same color and node 3 is colored differently. The chromatic number for this graph is 2 and the algorithm, even if it is configured to use 3 colors, it determined that the best solution for coloring the graph is by using only 2 colors, thus determining both the coloring and the chromatic number. Panel c) presents the experimental results; in each iteration the algorithm found only best solutions, with a maximum of 5 solutions found in iterations 1 and 4. (c) Figure S4: Panel a) shows an Erdős-Rényi graph generated with edge probability 0.4 and 4 nodes, which we used for the coloring problem. Panel b) shows the same graph colored with the solution found by our algorithm. The result for this graph uses only 2 colors, so that nodes 1 and 3 are colored using first color and nodes 0 and 2 are colored using the second one. The chromatic number for this graph is 2 and the algorithm, even if it is configured to use 3 colors, it determined that the best solution for coloring the graph is by using only 2 colors, thus determining both the coloring and the chromatic number. Panel c) depicts the experimental results; after 1 Grover iteration the algorithm produced 5 valid solutions from which 2 are best solutions.  Figure S5: Panel a) shows an Erdős-Rényi graph generated with edge probability 0.4 and 5 nodes, which we used for the coloring problem. Panel b) shows the same graph colored with the solution found by our algorithm. The solution for this graph uses 2 colors, so that nodes 0 and 3 are colored using the first color, and nodes 1, 2 and 4 are colored using the second one. The chromatic number for this graph is 2 and the algorithm, even if it is configured to use 3 colors, it determined that the best solution for coloring the graph is by using only 2 colors, thus determining both the coloring and the chromatic number. Panel c) depicts the experimental results: after 3 iterations the algorithm produced 6 valid solutions from which 2 are best solutions. (c) Figure S6: Panel a) shows an Erdős-Rényi graph generated with edge probability 0.4 and 5 nodes, which we used for the coloring problem. Panel b) shows the same graph colored with the solution found by our algorithm. The solution for this graph uses 2 colors, so that nodes 0, 3 and 4 are colored using the first color and nodes 1 and 2 are colored using the second one. The chromatic number for this graph is 2 and the algorithm, even if it is configured to use 3 colors, it determined that the best solution for coloring the graph is by using only 2 colors, thus determining both the coloring and the chromatic number. Panel c) depicts the experimental results; after 4 iterations the algorithm produced 3 valid solutions from which 2 are best solutions.  Figure S7: Panel a) shows an Erdős-Rényi graph generated with edge probability 0.4 and 5 nodes, which we used for the coloring problem. Panel b) shows the same graph colored with the solution found by our algorithm. The solution for this graph uses 3 colors, so that nodes 3 and 2 are colored using the first color; nodes 1 and 4 are colored using the second color; node 0 is colored using the third color. Panel c) depicts the experimental results: after 4 iterations, the algorithm produced 7 valid solutions from which 2 are best solutions.  Figure S8: Panel a) shows an Erdős-Rényi graph generated with edge probability 0.4 and 5 nodes, which we used for the coloring problem. Panel b) shows the same graph colored with the solution found by our algorithm. The solution for this graph uses 3 colors, so that nodes 0, 1 and 3 are colored using the same color and nodes 2 and 4 are colored using different colors. Panel c) depicts the experimental results: after 2 iterations, the algorithm produced 6 valid solutions from which 2 are best solutions.

Graph coloring example
In this section, we present an example of how the Reduced Quantum Genetic Algorithm is applied to a typical genetic search problem. Problem: Considering the graph in Figure S9 and a number of 3 colors, find a way of coloring the nodes such that no two adjacent nodes are colored with the same color.
Solution: In a classical genetic approach, we start by generating a population with each chromosome encoding 4 genes, each gene representing a color. In the quantum version, the chromosome encoding requires 8 qubits. Each color is represented with 2 qubits, thus we will consider the combination 11 as an invalid color. The chromosome will encode valid and invalid colors as superposed basis states, a chromosome that contains at least one invalid color is considered an invalid solution, as presented in Table 1.
We start with the initial state In Table 1 we present the chromosome encoding on 8-qubit classical values in superposition with valid and invalid flags.
We apply the fitness function defined in Section Implementation over the individual registers |u⟩ i obtaining the state presented in (2).
All least significant 8 bits of the fitness values represent two's complement numbers and the 9th bit represents the validity of the individual, 0 indicates an invalid individual, while 1 indicates a valid one.
The next step is to apply the oracle over the fitness register. We count the number of edges in graph-in this example is 4-and apply the oracle implemented as in Figure 4. In Equation (3) |ψ⟩ 1 3 is the pair register state after subtracting the number of edges from the fitness value and applying phase-shift. The pair register state after applying the Oracle is presented in Equation (4).
Having the highest fitness value, if we measure the individual register of |ψ⟩ 4 we obtain the corresponding individual (or one of the corresponding individuals, if there are more solutions). We get, with a high probability, one of the following basis states: |00010001⟩ , |00010010⟩. Assuming that |00010001⟩ is measured, we update the max value with the corresponding fitness value, and repeat the steps above until the max is not improved.
Suppose that, after applying Grover iterations, we measure |00010010⟩ in individual register of |ψ⟩ m−1 , then in fitness register we will have |100000100⟩. Since max value is not improved, we have the solution for our problem.

Circuit implementation
Listing 1: Quantum registers initialization ind_qreg = QuantumRegister(ind_qreg_size, "ireg") fit_qreg = QuantumRegister(fit_qreg_size + 1 , "freg") carry_qreg = QuantumRegister(carry_size, "carryreg") oracle = QuantumRegister(oracle_ws_size, "oreg") pos_no_of_edges = QuantumRegister(fit_qreg_size,"pedgesreg") creg = ClassicalRegister(ind_qreg_size,"reg") qc = QuantumCircuit(ind_qreg, fit_qreg, carry_qreg, oracle_ws, neg_no_of_edges, pos_no_of_edges, creg) qc.h(ind_qreg) qc.h(oracle_ws) In Listing 1 we present the initialization step of the algorithm. In this step the quantum registers are initialized, the circuit is created and the individual quantum register and the oracle qubit are put in superposition. The individual quantum register contains the color combinations for solving the graph coloring and fitness quantum register is used for storing the fitness value. The carry quantum register is used in the oracle for performing the subtraction and addition. The quantum register named in Listing 1 as pos no of edges stores the number of edges in the graph and is used in the oracle. This value is used along with the fitness value to perform the subtraction and addition.
Listing 2: Appending U f it Sub-circuit qc.append (ufit_instr, [ind_qreg[q] for q in range(0,ind_qreg_size)]+ [fit_qreg [q] for q in range(0,fit_qreg_size+1)] ) Listing 2 shows the append of U f it subcircuit to the circuit with individual and fitness quantum registers as inputs. The implementation of U f it subcircuit is presented in Algorithm 2. The oracle subcircuit implementation is presented in Algorithm 3 while the subcircuit usage is presented in Listing 3. As it can be observed, pos no of edges, fitness and oracle quantum registers are used as an input to the subcircuit. In Listing 4 the appending of Grover diffuser subcircuit is presented. The implementation for this subcircuit is provided in Figure 6 and is applied to the fitness quantum register, valid and oracle qubits.