Quantum computing. Quantum computing is one of the most promising emerging computation technology. Theory promises algorithmic speed ups ranging from quadratic, for unstructured problems, up to exponential for some particular key problems. Besides the some problems such as integer factoring and its obvious applications in cryptology, very few applicable large scale algorithms have been derived or studied. In 2015 especially, Montanaro  presented a general method to obtain speedups of backtracking-based algorithms, relying on Belovs’ previous work  (merged in ). The algorithm uses Quantum Walks, a well developed quantum algorithmic tool intensively studied in the scope of search algorithms [1, 2, 9, 18, 20, 25, 26].
Constraint satisfaction problems. CSPs form a very general class of problems, that encompass a large set of practical problems. The most famous examples are the Boolean satisfiability problem (SAT)  and the graph coloring problem . Both have applications in many fields, like scheduling  or timetabling 
for graph coloring, and in computer science or artificial intelligence, among others, for SAT (refer to for a wide list of applications of SAT).
CSPs have been widely studied and a well known tool taking advantage of their structure to solve them is backtracking. For example, the DPLL [10, 11] backtracking-based algorithm has been introduced in 1962 and is currently the procedure at the basis of some of the most efficient SAT solvers [14, 16, 27]. Since backtracking algorithms explore a tree whose vertices are partial solutions to the associated CSP , one can think of using a quantum walk to obtain a speedup.
used these works to speed up the two most efficient forms of enumeration (a lattice algorithm) known. They claim that it affects the security estimates of several lattice-based submissions to the NIST post-quantum standardization process. In turn, Montanaro  has presented how to get a quantum speedup of branch-and-bound algorithms by using Ambainis-Kokainis’ work and his own. Thus, Montanaro’s algorithm is of high interest in computing science and cryptography. In 2018, Campbell, Khurana and Montanaro  reviewed its complexity when applied to the graph coloring problem and SAT, assuming access to a very large amount of qubits, since they aggressively optimized the circuit depth. The aim of this work is to investigate a memory efficient implementation of this backtracking algorithm, in order to be able to validate the algorithm on small instances via classical emulation.
The paper is organized as follows. Section 2 introduces definitions. We discuss the choice of heuristic in section 3. Then, section 4 is about the use of the predicate, how to implement it and how to check some generic constraints. We conclude by presenting some of the results we got for graph coloring, thanks to a simulator, in section 5.
Thereafter, we will denote by a constraint satisfaction problem defined by a triple , where is a set of variables, is a set of values and is a set of constraints. We will also use to denote the extended domain in which each variable can take its value, standing for "the variable has no value".
Let be an assignment of values to the variables of a CSP . It will be said to be a solution to if it verifies all the constraints in ; complete if , partial otherwise; valid if it is partial and can be extended to a solution; invalid if it is partial and not a solution.
2.1 Backtracking algorithm
A standard approach for solving a CSP is the technique of backtracking. For this, we assume that we have access to a predicate which can receive an assignment (complete or partial) of values as argument and returns "true" if is a solution, "indeterminate" if it is valid, "false" otherwise. We also assume access to a heuristic which specifies which variable should be instantiated next. The general algorithm is presented as algorithm 1.
2.2 Montanaro’s algorithm
The algorithm presented in  is based on a quantum walk on trees. The idea is summarized as follows. Consider a rooted tree with vertices, labeled , the vertex being the root of . Hereafter, (resp.
) will denote the set of vertices at an even (resp. odd) distance fromand will mean that is a child of in the tree. The quantum walk operates on the space spanned by , and starts in the state . It is based on a set of diffusion operators , where is the identity if is a solution, otherwise, diffuses on the subspace spanned by . A step of the walk consists in applying the operator , where :
Thanks to these operators, an algorithm for detecting a solution in a tree can be established (algorithm 2). It is the phase estimation of the operator which allows the quantum walker to go through the paths leading to a solution in . By applying the detection algorithm to wisely chosen vertices of , it is possible to construct an hybrid algorithm for finding a solution (algorithm 3). Montanaro has shown that it finds a solution in time complexity and if there exists a unique solution, it is shown to be . For more details on the quantum walk, refer to .
3 Variable ordering heuristics
In order to be able to test the algorithm with the means we have, our glance was initially towards the choice of the heuristic. In fact, the largest qubit overhead in the implementation comes from the heuristic implementation, since one has to store variable indexes inside the quantum memory ( qubits are needed). Moreover, even though the depth overhead of the heuristic is asymptotically negligible compared to the rest of the algorithm, it seems that for instances of reasonable size, this overhead is not negligible.
Since we are interested in optimizing the number of qubits, we chose to deal with static variable ordering (SVO) heuristics, which can be classically precomputed at the start of the meta-algorithm. This has two main benefits: only data qubits are required to store an assignment and we do not have to produce a reversible implementation of a dynamic variable ordering (DVO) heuristic.
In  and , the implementation of Montanaro’s algorithm has been optimized in depth and its complexity has been studied considering the use of a DVO heuristic. However, the benefit of implementing a DVO heuristic is unclear in the range of parameters for which it is claimed in  that a graph could be colored in one day (up to approximately 150 vertices). Let (resp. ) be the number of vertices in the backtracking tree associated with a SVO (resp. DVO) heuristic and (resp. ) the number of calls to made by Montanaro’s algorithm. If we denote the depth of the overhead due to the implementation of a DVO heuristic by and the depth of the operators and without heuristic by , we have that using a dynamic heuristic is more efficient than using a static one if: , i.e. if . This is asymptotically true but thanks to the script computing algorithm 3 complexity to solve graph coloring given in , one can compute an estimate of (Fig. 1). In the considered range of parameters, we can see that using a DVO heuristic would be better than using a SVO one if . Unfortunately, as far as we know, no DVO heuristic has been proved to verify such a bound. Thus, the time-saving trick allowed by a DVO heuristic may not be obvious and it might be worth using a SVO heuristic for "small" instances.
The modified algorithm for and is presented as algorithm 4.
In order to test our implementation of Montanaro’s algorithm, we used the following SVO heuristics:
Maximum cardinality (MC) : chooses the variable with the largest number of neighbors to be the first one and then orders the others by choosing at each step the most connected one with previously ordered ones;
Maximum degree (MD) : orders the variables in the decreasing order of the size of their neighborhood;
Minimum width (MW) : orders the variables from last to first by choosing at each step the one having the minimum number of neighbors in the subproblem where previously ordered variables have been deleted.
To get an idea of the efficiency of these heuristics compared to the naive one, we emulated Montanaro’s algorithm on the graph coloring problem by replacing algorithm 2 with a backtracking one in algorithm 3. For fixed values of and , we generated 1000 random graphs for a varying number of edges, ran algorithm 3 on these graphs and counted the number of calls to the emulated algorithm in average. The same pattern arose when took different values between 10 and 20 and between 3 and 6 (Fig. 2). We observed that the MD heuristic offered the best (and optimal) results and that MC and MW heuristics led to very similar results. Of course, we can not extrapolate for higher values of and .
4 Generic implementation
Thereafter, we will use the following notations : , and .
The most straightforward way of implementing the predicate is to compute a logical of the result of the evaluation of each constraint over the current variable assignment. This would lead to a circuit using work qubits. We present another solution, a quantum counter, using only qubits.
In the case of the partial predicate, an index stored in a quantum register indicates that the first variables have been assigned a value. Therefore, if is sufficient to check the constraints that depends on at least one variable in . To find out if a constraint has to be checked, we use a system of comparison of values, one of which is quantum and the other classical. The overall process requires additions on qubits.
Similarly, if we apply the detection algorithm to a vertex located at the -th level of the backtracking tree, it is unnecessary to check the constraints that depend solely on the variables in .
Thanks to these optimizations, the deeper we go in the backtracking tree, the more qubits, quantum gates and time are saved.
4.1 How to implement a predicate
Let be a CSP. For all , the binary representation of the value assigned to is denoted by . The symbol will be encoded by 0.
The circuit (a)a is used to verify if an assignment is solution to , by checking for all the constraint . An ancillary register is used as a counter. In order to check , a subroutine depending on the set of involved variables in will be used and will increase the counter if is not verified. Once all the constraints have been checked, the counter will be equal to the number of constraints that are violated. Thus, if it is 0, we set an ancillary qubit to 1. Then, we reverse the checking operations to reset the counter to 0. At the end of the circuit, we have in the ancillary qubit the wanted value: .
We also want to be able to verify if a partial assignment is valid for . In this aim, we have to check for all the constraint if . In the following, , will denote and .
In order to compute the comparison operator, we add a bit (most significant one) to (call it , initialize it to ) and use the following procedure ((b)b):
If , subtract it from , otherwise, add it to ;
If then some overflow will occur and thus, will be flipped. Use it to control the checking operation.
In circuit (c)c, the ancillary qubit is set to 1. Thus, the comparison operator will flip if , i.e. if . Thanks to we can control the checking operation. For the rest of the circuit, the idea is the same as the one of the circuit (a)a.
Within the scope of an optimization of the depth of our implementation, note that constraint checking operations can easily be parallelized (figure 8). We just have to divide in sets of constraints and use a copy of the registers and a counter for checking each one. This involves using qubits but the depth of the predicate would be divided by (we just have then to fan-out/fan-in registers to copies, which can be done in depth ).
4.2 How to check a constraint
The circuit (a)a is used to check if the variable has been assigned a value (e.g. if the -th vertex of a graph has been colored). It uses the ancillary register which contains a bit string corresponding to the counter. Since we have chosen that the value 0 means that , we just have to check that is different from 0. The counter is increased by 1 if has not been assigned a value.
The circuit (b)b is used to check if the variables and have different values (e.g. if the coloring of the edge between the -th and the -th vertices of a graph is well colored). It uses the ancillary register , which is increased by 1 if (i.e. ). For that, we apply a bit-wise XOR to the values of the two variables (the result is stocked in the register of the second value).
For the specific case of boolean variables, we suggest to represent the bit 0 by the quantum state , the bit 1 by the quantum state and the unassigned symbol by . In the following, we will denote the left qubit by an in exponent and the right qubit by an in exponent. Our suggestion stems from the fact that thanks to this choice, it will be simpler to manipulate the variables. The left qubit will allow us to do the negation of the boolean variable without having a side effect on the unassigned values. The right qubit will allow us to distinguish 1 from and 0, which will be useful to check a disjunction of literals.
4.3 General structure
Thanks to the precedent subsections, step 2 and most of step 5 of algorithm 4 can be realized. The rest of the implementation is most straightforward, circuits of the operators and are given in appendix (resp. Fig. 9 and 10). Note that contrary to what is said in , we just need to add one control qubit to three (resp. one) controlled-Z gates in step 6 to control the whole operator (resp. ).
5 Simulation results
Now, we present some results of our simulations for the problem of graph coloring. In order to check the constraints, the circuits (a)a and (b)b can be used. The colors red (circle), green (square) and blue (triangle) will be denoted by , and . We will denote any partial assignment which is not trivially false by and if the values are of importance by .
By applying the algorithm 3 on the root of the complete tree associated to the graph in Fig. (a)a, it is supposed to detect that there is no possible coloring for this graph with two colors. Thus, the subtree presented here may not be visited thanks to the quantum part. For the second example, the algorithm 3 will travel along the dark gray tree (if it outputs all the solutions in Fig. (b)b).
Tab. (c)c (resp. (c)c) presents some probabilities of obtaining eigenvalue 1 depending on the precision used for the phase estimation in the algorithm 2 and the partial assignment at the root of the subtree on which it is applied. Some of these probabilities (y-axis) depending on the precision (x-axis) are presented in Fig. (d)d (resp. (d)d).
For the first example, we look at the results where the algorithm has been applied on . We can see that for a precision smaller than 4, the algorithm 2 will fail with high probability, since the threshold probability of acceptance fixed in  is (blue line). For the second example, we look at the results where the algorithm has been applied on (plus signs) and (crosses). We can see that for a precision equal to 1, the algorithm 2 will fail with high probability.
In this paper, we discussed our implementation of Montanaro’s algorithm, but an improved quantum algorithm for backtracking has been introduced by Ambainis and Kokainis , reducing the queries complexity from to , where is the number of vertices of actually explored by a classical backtracking algorithm. Nevertheless, Montanaro’s algorithm can not be left out since it is a component of Ambainis-Kokainis’ algorithm.
While Campbell, Khurana and Montanaro  assumed access to an extremely large number of physical qubits to propose a depth optimized method to implement Montanaro’s algorithm, we have presented techniques minimizing the space usage. For that, we especially looked at the implementation of the predicate and the heuristic. We have proposed the use of a quantum counter for the former and highlighted the fact that up to a certain point, the latter might not be quantumly implemented. However, these propositions are not asymptotically competitive, although our implementation of the predicate could be parallelized to be efficient and could lead to a trade-off between the space usage and the time usage. As far as the heuristic is concerned, it would be interesting to establish a precise resource estimation and define to what extent a SVO heuristic would present benefits compared to a DVO one.
Acknowledgments. This work was supported by Atos. The implementation was developed in python using Atos’ pyAQASM library. All simulations were performed on the Atos Quantum Learning Machine. We acknowledge support from the French ANR project ANR-18-CE47-0010 (QUDATA), the QuantERA ERA-NET Cofund in Quantum Technologies implemented within the European Union’s Horizon 2020 Program (QuantAlgo project), and the French ANR project ANR-18-QUAN-0017 (QuantAlgo Project).
-  A. Ambainis. Quantum walks and their algorithmic applications. International Journal of Quantum Information 01(04) 507–518, 2003.
-  A. Ambainis. Quantum walk algorithm for element distinctness. SIAM J. Comput. 37(1) 210–239, 2007.
-  A. Ambainis and M. Kokainis. Quantum algorithm for tree size estimation, with applications to backtracking and 2-player games. ACM, 2017.
-  Y. Aono, P. Q. Nguyen, and Y. Shen. Quantum Lattice Enumeration and Tweaking Discrete Pruning. Springer, 2018.
-  A. Belovs. Quantum walks and electric networks. arXiv:1302.3143, 2013.
-  A. Belovs, A. M. Childs, S. Jeffery, R. Kothari, and F. Magniez. Time-efficient quantum walks for 3-distinctness. Springer, 2013.
-  E. Campbell, A. Khurana, and A. Montanaro. Applying quantum algorithms to constraint satisfaction problems. Quantum 3(167), 2018.
-  L. Chen, S. Jordan, Y.-K. Liu, D. Moody, R. Peralta, R. Perlner, and D. Smith-Tone. Report on post-quantum cryptography. NISTIR 8105, 2016.
-  A. M. Childs, R. Cleve, E. Deotto, E. Farhi, S. Gutmann, and D. A. Spielman. Exponential algorithmic speedup by a quantum walk. ACM, 2003.
-  M. Davis, G. Logemann, and D. Loveland. A machine program for theorem-proving. Communications of the ACM 5(7) 394–397, 1962.
-  M. Davis and H. Putnam. A computing procedure for quantification theory. JACM 7(3) 201–215, 1960.
-  D. de Werra. An introduction to timetabling. European Journal of Operational Research 19(2) 151–162, 1985.
-  R. Dechter and I. Meiri. Experimental evaluation of preprocessing techniques in constraint satisfaction problems. Morgan Kaufmann Publishers Inc., 1989.
-  N. Eén and N. Sörensson. An extensible SAT-solver. Springer, 2004.
-  E. C. Freuder. A sufficient condition for backtrack-free search. JACM 29(1) 24–32, 1982.
-  C. P. Gomes, H. Kautz, A. Sabharwal, and B. Selman. Satisfiability solvers. Elsevier, 2008.
-  J. Gu, P. W. Purdom, J. Franco, and B. W. Wah. Algorithms for the satisfiability (SAT) problem: a survey. Amer Mathematical Society, 1997.
-  J. Kempe. Quantum random walks: an introductory overview. Contemporary Physics 44(4) 307–327, 2003.
-  F. T. Leighton. A graph coloring algorithm for large scheduling problems. Journal of research of the NBS 84(6), 1979.
-  F. Magniez, A. Nayak, J. Roland, and M. Santha. Search via quantum walk. Theory of Computing, 2007.
-  E. Malaguti and P. Toth. A survey on vertex coloring problems. International Transactions in Operational Research 17, 2010.
-  A. Montanaro. Quantum walk speedup of backtracking algorithms. Theory of Computing 14(15) 1–24, 2015.
-  A. Montanaro. Data from Quantum algorithms for CSPs. 07 2019.
-  A. Montanaro. Quantum speedup of branch-and-bound algorithms. arXiv:1906.10375, 2019.
-  M. Santha. Quantum walk based search algorithms. Springer, 2008.
Quantum speed-up of Markov chain based algorithms. IEEE, 2004.
-  P. van Beek. Backtracking search algorithms. Elsevier, 2006.