Content uploaded by Stanislav Protasov

Author content

All content in this area was uploaded by Stanislav Protasov on Feb 24, 2022

Content may be subject to copyright.

GROVER BINARY SEARCH FOR DISCRETE QUANTUM

OPTIMIZATION

Ayaz Baykov, Stanislav Protasov

Innopolis University, Innopolis, Russia

{a.baykov, s.protasov}@innopolis.university

ABS TRACT

Contemporary quantum algorithms, being efﬁcient theoretically, fail to execute on real QPUs. One

reason for these failures is the algorithm’s probabilistic nature, which is ampliﬁed by hardware

implementation imperfections. Grover search is such a probabilistic method, which enables other

methods in quantum optimization and machine learning. In this work we improve the theoretical

worst case complexity of Grover Adaptive Search by replacing iterations with binary search. We

observe in the experiments that our method shows better success rate in general, and is sufﬁciently

better for a speciﬁc type of optimization landscapes with plateaus.

Keywords Grover search ·quantum computing ·quantum optimization ·knapsack problem

1 Introduction

Solving optimization problems is one of the most promising areas of quantum computing applications. Typically, we

restate a well-known NP-hard discrete optimization problem using completely different mathematics. This trick allows to

make use of operations, which are proven to be faster when run on a QPU. Such methods are Shor’s algorithm [

1

], which

converts a factorization problem into a frequency estimation task; quantum version of discrete Fourier transform [

2

],

which instead of a straightforward “algorithmic” implementation utilizes unitary property of transformation operator.

And of course, Grover search [

3

], which instead of naïve iterations beneﬁts from parallel predicate execution for the

argument superposition. Grover’s algorithm, as well as Shor’s algorithm, is not just an algorithm. This is a framework,

which requires a quantum oracle implementation. It can be used for solving multiple problems, if they provide a proper

oracle. Here we concentrate on the application of Grover search to discrete optimization, and we illustrate our ﬁndings

with a simpliﬁed knapsack packing problem.

2 Previous work

In this paper, we present an improvement for Grover Adaptive Search (GAS) algorithm [

4

]. Original algorithm

is an iterative hybrid (utilizing both CPU and QPU computations) general-purpose framework for solving discrete

optimization problems. This framework supposes we can convert a problem statement into the following conditions:

–

Slow(x) = {low < cost(x)} ∧ valid(x)(1)

where

x

is a candidate solution among

N

possible (hereinafter we use

N

to denote a problem search space cardinality),

cost

is a function to maximize, and

valid

predicate is responsible for problem constraints. E.g. in knapsack packing,

given a set A, for choosing an optimal subset:

x⊆A,

N= 2|A|,

valid(x) = weight(x)≤limit

(2)

Predicate

Slow(x)

is then encoded as a quantum oracle. It is used inside Grover search algorithm, which solves the

problem of satisﬁability of

Slow(x)

. If there exists

x

satisfying

Slow(x)

,

cost(x)

value is used to update

low

boundary

until convergence. Let us deﬁne the cost

sol

of the unknown optimal solution. In the worst case, lower bound improves

by the constant each iteration, thus the classical (CPU) part of the method will trigger QPU method

O(sol −low)

times.

In section 3 we show, how to improve worst case complexity estimation to

O(log( ˜

sol −low))

. Here

˜

sol

means the

solution estimation from above. In the discussion section we show the cases where this improvement is practically

important.

3 Methodology

We call our optimization method Grover Binary Search (GBS). The method relies on binary search algorithms, which

for

k

sorted objects guarantees

O(log k)

complexity on CPU. It also has a quantum implementation [

5

] with the same

complexity estimation. Here we propose to use this algorithm instead on iterative search proposed in the original paper.

If we explicitly reproduce the original idea and replace GAS iteration with binary search, we can use a function

count(Slow(x))

. The function must return the number of solutions satisfying the oracle. This function is non-increasing

for variable

low

, thus it can be used in binary search. It can be implemented with quantum counting method [

6

], which

is just an application of Quantum Phase Estimation [

7

]. Unfortunately, this method requires doubled number of qubits,

O(log(N))

runs of controlled Grover iteration, plus

QF T †

[

2

] (which uses order of

2 log N

gates). Also, this method

provides an approximation of count value, instead of exact answers.

To overcome these complications we propose to replace the non-decreasing

count

with another non-decreasing function:

anylow(x)def

=count(Slow(x)) >0.(3)

In our method, we search for the smallest

low

, for which solutions count is 0:

argmin

low

[count(Slow(x)) = 0]

. For this

condition both functions

count

and

any

return the same answer. To implement function

any

we follow standard Grover

search procedure for unknown number of answers, which requires

O(log N)

non-controlled Grover iterations. Any

Grover search answer x, which satisﬁes Slow(x), means anylow (x) = T rue.

Altogether, our method in the worst case will run

O(log2(˜

sol −low))

(better than is GAS) iterations of binary search,

each of which will run

O(log(N))

Grover iterations (same as in GAS). Pseudocode of our method is shown in listing 1.

2

–

Algorithm 1: Binary Grover search for optimization problem

Input: P– problem search space

Result: R– solution

low ←Greedy1(P);

high ←Greedy2(P); // here we greedily estimate maximum cost(x)

R← ∅;

do

i←1;

while i2<|P|do

m=⌊low+high

2⌋;

x←GroverSearchi(P, m);// run iGrover iterations to find x∈P

// in case of knapsack, valid(x) = weight(x)≤limit

if valid(x)and cost(x)> m then

low ←cost(x);

R←x;

i←1;

else

i←i∗2;

end

end

high ←m;

while high −low > 1;

return R;

4 Implementation and analysis

We test our solution on a simpliﬁed knapsack packing problem: we assign cost equal to weight for the sake of a simpler

input and circuit. This allows to run simulator tests for a bigger search space, while keeping the problem exponentially

hard. In a classical 0/1 problem statement, we would need an additional quantum register for weights, limiting our

simulation opportunities.

In section 1 we mentioned, that Grover search is a generic framework, thus it requires additional implementations.

First, we need to implement a quantum oracle for the problem. In the case of simpliﬁed knapsack, our oracle should

implement the condition:

Slow(x) = {low < X

item∈x

cost(item)≤limit}.(4)

Note that in a classical 0/1 knapsack packing, the oracle should check

Pitem∈xweight(item)≤limit

instead. In our

implementation we avoid this by setting cost =weight.

We do our implementation and tests using IBM’s Qiskit framework v0.31.0 [

8

], running on Windows. We use the basic

probabilistic noiseless BasicAer simulator. We do not consider noise and concentrate on probabilistic effects only.

3

–

Circuit 1 represents an oracle implementation. We use controlled QFT adders [

9

] to implement the sum of weights.

Uncontrolled adders together with

CN OT

, controlled by a data sign qubit, are used for inequalities. This technique

was described in chapter 5 of the book [

10

].

Uncomputing

is a block of inverse adders to bring

data

and

key

qubits to

the initial state. We add

+1

to lower bound to replace strict inequality

low < cost

with non-strict

0≤cost −(low + 1)

,

and

+1

to upper bound to convert

cost ≤limit

into

cost −(limit + 1) <0

. To avoid unnecessary manipulations, the

limit is encoded as low + (limit −low) = 5 + 2.

Figure 1: Example oracle implementation for

S5(x)

condition:

5+1≤cost(x)<(5 + 2) + 1

. Controlled addition

operations implement

cost(x)

function (costs of knapsack candidates), while uncontrolled addition set inequality

boundaries.

We run simulator experiment to check the validity of our implementations. Available items are

{6,3,5,4}

,

low = 5

,

and limit = 7. Thus, solution set is {{3,4},{6}}. In the plot 2 we observe two peaks where they should be.

Figure 2: Results of Grover search algorithm for a prepared oracle.

0101

correspond to {3, 4} knapsack, while

1000

is

{6} candidate. Both options satisfy oracle conditions.

The main experiment is planned as follows. We test GAS and our GBS methods on random sets with 4..11 items

(which is equivalent to 16..2048 problem search space). Each item’s weight is uniformly sampled from 1..63 integer

4

–

Figure 3: Comparison or Grover Adaptive Search (GAS) and proposed method (GBS). Number of QPU circuit launches.

range. Knapsack limit is uniformly chosen from

[Pitems

4,Pitems]

integer range. We run 32 random experiments for

each problem size. According to the proposed algorithm 1, for

low

estimation

Greedy1

algorithm takes a sum of ﬁrst

elements which it does not exceed the

limit

, while

Greedy2

for upper bound

high

takes the

limit

value. Among the

values which differ between the methods, we measure number of times QPU circuit is launched, and the correctness of

given answers.

We present our results of QPU launches in ﬁgure 3. We observe two major patterns. First, the median number of

launches for both methods does not grow with the size of the problem. This is a projection of theoretical prediction, that

number of iterations is expected logarithm for GAS and guaranteed logarithmic for GBS, with respect to the upper limit.

In our experiment maximum limit grows linearly with the number of items, and thus logarithmically for problem search

space size. This means here we observe

log log N

tendency, which grows very slow to catch. Second observation is

that GBS launches twice as many quantum circuits. This pattern holds for oracle launch counts as well – this metric is

proportional to the number of utilized quantum gates. This value is essential in practice, while e.g., IonQ QPU pricing

schema is per gate execution [

11

]. Code proﬁling showed that our method can spend a lot of launches to prove that

there is no item in the range.

Proposed GBS method inherits the deterministic bisection method, thus incorrect Grover Search is the only source of

mistakes in the result. At the same time non-deterministic convergence procedure of GAS can be an additional source

of mistakes. We observed, that our method has a systematically higher success rate on experimental data (see ﬁgure 4).

We think this observation supports deterministic approach.

5 Discussion

We want to highlight, that our experiments are neither a proof of supremacy in precision, nor a justiﬁcation of worse

gate expenditure. We showed that for a random problem generation with no speciﬁc tuning, our method achieves correct

solution with a high probability, and shows expected asymptotic complexity characteristics.

Nevertheless, we want to share two observations derived from experiments. First, both GAS and proposed GBS

methods strongly depend on the lower bound estimation at the ﬁrst iteration. If constraints on the problem are loose

(in our example

low

estimation is unsatisfactory), Grover search algorithm behaves extremely bad, as it ampliﬁes the

5

–

Figure 4: Success rate of GAS and proposed (GBS) algorithms.

probabilities of incorrect solutions instead. In cases when the number of valid solutions is close to the half of the search

space, Grover search is equivalent to random sampling from the search space. Only a good estimation of a lower bound

can kickstart a method, which uses Grover search inside.

Second, GAS and GBS, probably, best suit different problems. Imagine a problem search space with a plateau of

multiple similar costs and a single optimal solution above the plateu. Iterative method can easily get stuck in this

plateau, doing minor improvements at each iteration, while binary search proceeds if it sees any solution “ahead”, with

higher costs. To support the observation, we composed a synthetic example, which has a very low chance to succeed

with GAS, but works great for GBS: [21, 19, 1, 1, 1, 1, 1, 1, 17] with the limit of 38. We run 50 experiments for each

method, and GBS found correct answer in 66% of launches, while GAS could succeed in only 22% of cases. We

recommend for practical problems use both GAS and GBS methods if the cost function behavior is unknown.

6 Conclusion

In this paper, we present a novel optimization Grover Binary Search method, which combines a brilliant idea of Grover

Adaptive Search with deterministic nature of binary search. New method appears to be asymptotically better, but in

practice it consumes more quantum gates, which is essential in NISQ era. Still, in simulations our method showed

systematically better success rate. Moreover, we could dedicate a separate subset of optimization cost landscapes, which

suit much better for GBS method. We support our ﬁndings with the experiment, where with GBS we could achieve

66% of success rate, compared to 22% for GAS.

Additionally, while today’s QPU access is mostly cloud base, we think that it is perspective to design fully-quantum

methods to avoid multiple data encoding-decoding. Binary search has a quantum version, thus it is potentially possible

to build a quantum-only implementation of GBS. This method will be qubit-hungry, but it can be still preferred to

multiple CPU-QPU communication cycles.

6

–

References

[1]

Peter W Shor. Algorithms for quantum computation: discrete logarithms and factoring. In Proceedings 35th

annual symposium on foundations of computer science, pages 124–134. Ieee, 1994.

[2] D. Coppersmith. An approximate fourier transform useful in quantum factoring, 2002.

[3]

Lov K Grover. A fast quantum mechanical algorithm for database search. In Proceedings of the twenty-eighth

annual ACM symposium on Theory of computing, pages 212–219, 1996.

[4]

Austin Gilliam, Stefan Woerner, and Constantin Gonciulea. Grover adaptive search for constrained polynomial

binary optimization. Quantum, 5:428, 2021.

[5]

Andrew M. Childs, Andrew J. Landahl, and Pablo A. Parrilo. Quantum algorithms for the ordered search problem

via semideﬁnite programming. Phys. Rev. A, 75:032335, Mar 2007.

[6]

Gilles Brassard, Peter Høyer, and Alain Tapp. Quantum counting. In Kim G. Larsen, Sven Skyum, and Glynn

Winskel, editors, Automata, Languages and Programming, pages 820–831, Berlin, Heidelberg, 1998. Springer

Berlin Heidelberg.

[7] A. Yu. Kitaev. Quantum measurements and the abelian stabilizer problem, 1995.

[8] MD SAJID ANIS et al. Qiskit: An open-source framework for quantum computing, 2021.

[9] Thomas G Draper. Addition on a quantum computer. arXiv preprint quant-ph/0008033, 2000.

[10]

Eric R Johnston, Nic Harrigan, and Mercedes Gimeno-Segovia. Programming Quantum Computers: essential

algorithms and code samples. O’Reilly Media, 2019.

[11]

IonQ. Google cloud platform: Ionq quantum cloud. https://console.cloud.google.com/marketplace/product/ionq-

public/ionq.

7