Overview

11 Search-based quantum optimization

This chapter shows how Grover’s algorithm can be repurposed from unstructured search to search-based optimization. It introduces Grover Adaptive Search (GAS) to cope with unknown numbers of “good” solutions and then builds a Grover optimizer, a hybrid loop that interleaves quantum searches with classical updates to efficiently push toward global optima. With carefully chosen iteration schedules and a stopping rule, the approach aims for a quadratic reduction in oracle calls while remaining practical on near-term devices.

Grover Adaptive Search assumes a state-preparation circuit A, a problem oracle O that tags desirable outcomes, and the Grover operator G. Because the ideal iteration count depends on the (unknown) fraction of good states, GAS tries a sequence of iteration counts (e.g., simple [0, 1] schedules or more elaborate patterns), performs measurements, and checks for success, halting when a stopping condition is met. The chapter illustrates this with function encoding: map inputs to outputs via a polynomial of binary variables, represent signed integers in Two’s Complement, and use an oracle that tags non-negative outputs by inspecting the sign bit. Even a single Grover iteration can dramatically amplify the probability of measuring a desired outcome, while the surrounding orchestration and decision logic remain classical.

Building on GAS, the Grover optimizer repeatedly tightens the search by updating the encoded function so that the current best result becomes the new threshold: for maximization, shift the function so the latest best value becomes negative, then search again for non-negative outcomes. A worked example finds the maximum of a concave quadratic, demonstrating the hybrid loop of prepare–search–assess–update. The method then solves a small knapsack instance by encoding three registers—selection, value, and weight—adjusting constraints with transformations like w′ = capacity − w and raising the value threshold v′ = v − min_value, and using a multi-register oracle that tags feasibility and quality via sign bits. Practical guidance includes iteration schedules, stopping criteria, register sizing for signed arithmetic, and leveraging classical heuristics to seed the quantum search and accelerate convergence.

A dependency diagram of concepts covered in this chapter.
CH11 F01 gonciulea
A flow diagram of Grover Adaptive Search.
CH11 F02 gonciulea
The quantum state encoding the function \(f(k) = k^2 - 5\) with \(0 \le k < 4\).
CH11 F03 gonciulea
The quantum state encoding the function \(f(k) = k^2 - 5\) with \(0 \le k < 4\) after applying one Grover iteration.
CH11 F04 gonciulea
The quantum state encoding the function \(f(k) = k^2 - 5\) with \(0 \le k < 4\) after applying two Grover iterations.
CH11 F05 gonciulea
A flow chart of the Grover optimizer.
CH11 F06 gonciulea
Construct or update the circuit \(A\). These parameters are updated depending on the results of the previous search.
CH11 F07 gonciulea
The grid state representation of the quantum state encoding the function \(f(k) = -(k-3)^2 + 3\).
CH11 F08 gonciulea
Choose a schedule that determines the number of iterations \(r \ge 0\) to be performed at each step.
CH11 F09 gonciulea
Apply the Grover operator \(G^r A\), where \(r\) is the number of iterations according to the chosen schedule.
CH11 F10 gonciulea
Check if the result of this search is better than the result at the previous step (or the default value).
CH11 F11 gonciulea
If progress was not made, check the stop condition.
CH11 F12 gonciulea
The grid state representation of the quantum state encoding the function \(f(k) = -(k-3)^2 + 3\) and applying one Grover iteration.
CH11 F13 gonciulea
Check if the result of this search is better than the result at the previous step (or the default value).
CH11 F14 gonciulea
Construct or update the circuit \(A\). These parameters are updated depending on the results of the previous search.
CH11 F15 gonciulea
The grid state representation of the quantum state encoding the function \(f(k) = -(k-3)^2 + 3\) shifted by -4.
CH11 F16 gonciulea
Once the stopping condition is met, the optimal value is returned.
CH11 F17 gonciulea
Three registers encoding an item selection, its total value, and its total weight for solving the knapsack problem.
CH11 F18 gonciulea
A quantum state after encoding the values and weights of each possible selection.
CH11 F19 gonciulea
The selection register outcome probabilities after looking for selections with a maximum weight of 4 and a minimum value of 3.
CH11 F20 gonciulea
The selection register outcome probabilities after looking for selections with a maximum weight of 4 and a minimum value of 4.
CH11 F21 gonciulea

Summary

  • We can encode multiple (polynomial) functions of the same binary variables in different registers of a quantum circuit. The functions can represent a value or cost associated with the inputs.
  • A Grover optimizer iteratively uses Grover’s algorithm to find optimal values or costs by using previous best results to narrow the size of the search space.
  • The key to an efficient Grover optimizer is using an efficient underlying oracle. Searching for negative or non-negative integers can be done with oracles using the Two’s Complement interpretation.

FAQ

What is Grover Adaptive Search (GAS) and why is it useful for optimization?GAS is a hybrid algorithm that uses Grover’s operator with a schedule of iteration counts to find “good” outcomes when the number of good states is unknown. It avoids the overhead of amplitude estimation/quantum counting and can still provide quadratic speedup in oracle calls over classical search for suitable problems.
How do I choose the number of Grover iterations, and what does r = 0 mean?You pick r from a schedule (e.g., a simple [0, 1] loop, a random exponentially growing range, or a published fixed pattern). Using r = 0 means no amplification—just measure the prepared state. This is useful early on when the fraction of good states is unknown or possibly large.
What counts as a “good outcome,” and how is the oracle constructed in these examples?A good outcome is one that meets a target criterion, typically “non-negative” in a Two’s Complement value register. The oracle flips the phase of states with 0 in the most significant bit (MSB) of the value register. For multi-criteria (e.g., knapsack), the oracle can tag outcomes whose MSB is 0 in both the value and weight registers.
Why use Two’s Complement and how do I decide the number of value qubits?Two’s Complement lets you encode negative function outputs in a fixed-width register. Choose enough value qubits to cover the full range of intermediate and adjusted values; otherwise they wrap modulo the register size. In small examples the register is sized generously; in general you may need to increase it if wraparound is detected.
How does the Grover optimizer update the search target after finding a better result?For maxima, it shifts the encoded function’s constant term so the latest best value maps to −1, and the oracle continues to tag non-negative values only if they improve on the current best. For knapsack, it similarly adjusts the minimum acceptable value (v' = v − min_value) and enforces the weight constraint (w' = max_weight − w).
What stopping condition should I use?A simple and practical choice is a failure counter: stop when consecutive searches fail to improve the best result beyond a threshold (e.g., failure_count > 7). Tighter thresholds reduce runtime but risk stopping early; looser ones increase robustness but cost more oracle calls.
How are classical functions encoded as polynomials of binary variables in the circuit?Write k as a sum of powers of 2 (k = Σ 2^j k_j), expand terms like k and k^2, and gather monomials into tuples (coefficient, variable indices). These terms drive circuit builders (e.g., build_polynomial_circuit or encode_term) to add contributions into value/weight registers via QFT/IQFT-based adders.
How are measurements used inside the hybrid loop?Each step measures (often with multiple shots), picks the most frequent outcome, decodes it (process_outcome) into meaningful values, checks progress versus the current best, and either updates circuit parameters (resetting failure_count) or increments failure_count and possibly stops per the stopping rule.
How is the knapsack problem mapped to GAS?Use three registers: key (item selection bits), value, and weight. Encode v(k) and w(k), then adjust to v' = v − min_value and w' = max_weight − w so feasible, valuable selections yield non-negative integers. The oracle checks MSB=0 in both value and weight registers. The optimizer raises min_value when progress is made.
What practical considerations matter on current hardware?Encoding circuits and Grover reflections add depth and noise sensitivity. Using small iteration schedules (e.g., [0, 1]) and modest register sizes helps. Multi-shot sampling stabilizes estimates versus single-shot schedules. Classical pre-processing (e.g., initial bounds or heuristics) can shrink the search space and improve success.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building Quantum Software with Python ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building Quantum Software with Python ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building Quantum Software with Python ebook for free