Deterministic Grover search with a restricted oracle

Grover's quantum search algorithm provides a quadratic quantum advantage over classical algorithms across a broad class of unstructured search problems. The original protocol is probabilistic, returning the desired result with significant probability on each query, but in general, requiring several iterations of the algorithm. We present a modified version to return the correct result with certainty without having user control over the quantum search oracle. Our deterministic, two-parameter"D2p"protocol utilizes generalized phase rotations replacing the phase inversions after a standard oracle query. The D2p protocol achieves a 100% success rate in no more than one additional iteration compared to the optimal number of steps in the original Grover's search enabling the same quadratic speed up. We also provide a visualization using the Bloch sphere for enhanced geometric intuition.

Grover's quantum search algorithm provides a quadratic quantum advantage over classical algorithms across a broad class of unstructured search problems. The original protocol is probabilistic, returning the desired result with significant probability on each query, but in general, requiring several iterations of the algorithm. We present a modified version to return the correct result with certainty without having user control over the quantum search oracle. Our deterministic, twoparameter "D2p" protocol utilizes generalized phase rotations replacing the phase inversions after a standard oracle query. The D2p protocol achieves a 100% success rate in no more than one additional iteration compared to the optimal number of steps as in the original Grover's search enabling the same quadratic speed up. We also provide a visualization using the Bloch sphere for enhanced geometric intuition.

I. INTRODUCTION
An efficient algorithm to search a large unstructured search space has a wide range of applications. While the time complexity of a classical search algorithm scales linearly with the size of the space, Grover's quantum search algorithm [1] provides a quadratic speedup. Though the quantum advantage is not exponential as in some quantum algorithms it can be applied very broadly, to any problem whose result can be verified efficiently. The search is performed by an "oracle", a quantum algorithm that the user may not have access to. The oracle could be a quantum random access memory [2,3] to access an unstructured classical or quantum database. Alternatively, the oracle could be a quantum version of a one-way function such as a hash, symmetric key encryption, or number theory conjecture, etc. Given a space with N unsorted inputs and quantum oracle that identifies M marked states, Grover's search algorithm is guaranteed to produce better than 50% success probability with O( N/M ) oracle queries, whereas a classical algorithm needs on average N/(2M ) interrogations.
Grover's algorithm is composed of two steps -the oracle query, which flips the phase of the marked states, and the application of the diffusion operator (also known as the reflection or inversion operator) that amplifies the amplitude of the marked states. In the original protocol [1], both steps use a phase-flip operator that restricts the evolution of the initial superposition state in a way that the success is probabilistic. A family of nondeterministic Grover-type searching algorithms has also been found to provide similar quadratic speedup [4]. One can achieve the target state with certainty by controlling the phases of the phase-flip and diffusion operators when the ratio λ = M/N is known [5,6]. Other works aim to improve the success rate for an unknown λ (with a * Corresponding author: roytanay@uchicago.edu modest guess of the lower bound) by performing multiphase matching [7][8][9]. However, these protocols require one to control the phase of the oracle, which might not always be plausible as the user may not have knowledge of or access to the oracle. Practically, the search oracle should be treated as a fixed unitary determined by some physical process with no user-tunable parameters.
In this work, we present an algorithm to find a marked state deterministically with the constraint that the user does not have control over the oracle phase. We show that only two phase parameters for the consecutive diffusion operators are sufficient to find a target state with certainty by making k opt = π 4 sin −1 √ λ − 1 2 oracle queries for a given λ.

II. OVERVIEW OF GROVER'S ALGORITHM
The original Grover's algorithm constitutes of successive application of the oracle and diffusion operators on the initial equal-superposition state (containing mostly unmarked states) that is transformed into a superposition of mostly marked states. Assuming N = 2 n as the number of total states, one can prepare an equalsuperposition state |ψ 0 by applying a Walsh-Hadamard transformation individually to all the qubits initiated to |0 . Instead of using the full 2 n -dimensional Hilbert space, it is more convenient to map the system to a twodimensional sub-space spanned by the orthogonal vectors |T and |R , where |T (|R ) represents the equalsuperposition of all marked (unmarked) states |t j (|r j ), In this case, the user is assumed to have control over both the oracle and the reflection operator steps so that one can set α = β = θ0 (see Eq. (6)).
Then the initial state can be expressed in the new basis |R = ( 1 0 ) and |T = ( 0 1 ) as The evolution of |ψ 0 can be visualized as a moving unit vector on the Bloch sphere spanned by |R (north pole) and |T (south pole) as shown in Fig. 1(a). The initial state (solid green arrow) lies in the ZX plane making an angle θ = 2 sin −1 √ λ with the z-axis. The oracle is a unitary operator representing a generalized controlled-phase gate -rotation of the vector about z-axis by an angle α with I being the identity operator. The special case of S o (π) on |ψ 0 can be simply thought as a reflection with respect to the vertical axis. Next, we define the generalized Grover's reflection following the convention used in Ref. 8 (up to a global phase) which represents a rotation of the state about |ψ 0 by an angle β (see Fig. 1(a)). The product of the oracle and the reflection operator is often called the Grover's iterate G(α, β) = −S r (β)S o (α). The original Grover's iterate with α = ±π and β = ±π rotates the state vector by 2θ about the y-axis (dashed pink line in Fig. 1(b)), restricting the trajectory in the ZX plane. Since the angular distance of |ψ 0 from the south pole is π − θ, the number of steps needed to reach |T becomes (π−θ)/(2θ), which is, in general, a fractional number. Therefore, the optimal number of steps for the original Grover's search becomes the nearest integer [5] In general the final state vector (red arrow in Fig. 1 (b)) will not always align with south pole providing a maximum success probability of sin[(k opt + 1/2)θ] 2 . This situation of undershooting (overshooting) the target state is often called "undercooking (overcooking)". One can, however, cleverly choose a different plane of rotation so that the final state always lands on the south pole in k ≥ k opt steps as shown in Fig. 1 (c). The corresponding Grover's iterate needs α = β = θ 0 with [5]  which corresponds to an axis of rotation (dashed pink line in Fig. 1(c)) not parallel to the y-axis in general.

III. THE D2P PROTOCOL
The success of the protocol in Ref. 5 relies on the fact that the oracle is user-controllable which might not be always feasible. In this paper, we explore the possibility of deterministic outcome using a fixed oracle. In particular, we consider the standard phase flip operator with α = π. We show that, interestingly enough, only two phase parameters are needed to obtain zero failure rate, i.e., we apply Grover iterates G(π, θ 1 ) = G d (θ 1 ) and G(π, θ 2 ) = G d (θ 2 ) alternatively to the initial state |ψ 0 until k opt oracle queries are made. We call it deterministic 2-parameter (D2p) Grover's search algorithm. The requirement of only two phase parameters can be very intuitively understood from the fact that one needs only two non-colinear axes of rotation to span the full SU (2) space. An example of the resulting trajectory for λ = 0.005 is illustrated in Fig. 2 (a).
The goal of this protocol then reduces to determining the phases that will ensure landing of the final state along the south pole. We first consider the case when the number of queries k is an even number, so that the final state is Imposing the condition R |ψ f = 0 leads to the following two equations where cos(φ) = cos (9) These equations can always be solved for {θ 1 , θ 2 } when k ≥ k opt and λ ≤ 1/4. When k is odd, the final state is and one can find two equations similar to Eq. (8) that can be solved to obtain the optimal phase parameters (see Appendix B for explicit equations). Figure 2 (b) plots θ 0 , θ 1 and θ 2 as a function of λ with k = k opt . The sharp jumps occur when the query complexity k opt changes by one as depicted in Fig. 2(c). Note that for sufficiently small λ, θ 1 −θ 2 θ 0 . A comparison of the success probabilities between the standard Grover's search (green dashed line) and the D2p protocol (solid green line) is also shown in Fig. 2(c). One can always choose more than two phase parameters to obtain determinism, but any additional phase doesn't provide extra degree of freedom (as the reduced Bloch sphere has only two dimensions) and thus reaching the target state faster than k opt steps is not possible. The D2p protocol can be generalized to quantum amplitude amplification [10][11][12][13] where we prepare a random initial state |ψ 0 = A |0 instead of the equalsuperposition state |ψ 0 . Here, A could be any unitary as long as |ψ 0 has a finite overlap with marked state |T . Similar to Eq. (2), one can use the basis |T and |R to express where |R is now consists of a generic (normalized) superposition of unmarked states. The reflection unitary in Eq. (4) will be similarly modified to An identical analysis can be performed by replacing λ and |ψ 0 with λ and |ψ 0 to arrive at Eqs. (8). However, note that the knowledge of overlap λ = | ψ 0 | T | 2 is still required to achieve determinism. Next, we turn to the circuit implementation of the D2p protocol as depicted in Fig. 3(a). Hadamard gates are applied to individual qubits (initialized to |0 ) to prepare the equal-superposition state |ψ 0 . The modified Grover's iterates G d (θ) are applied alternatively with θ = θ 1 and θ = θ 2 for k opt times. The last iterate is G d (θ 1(2) ) if k opt is an odd (even) number and the final state becomes an equal superposition of the marked states guaranteeing a success when a projective measurement is performed. Each Grover iterate G d (θ) is composed of two generalized multiply-controlled phase gates and Hadamard gates as shown in Fig. 3(b). A generalized multiply-controlled phase gate involving n qubits can be deconstructed using two generalized multiplycontrolled NOT gates involving n qubits and one generalized multiply-controlled phase gate involving (n − 1) qubits along with two single-qubit phase gates as displayed in Fig. 3(c). This decomposition can be inductively applied to construct the target gate using O(n 2 ) controlled NOT gates and single qubit rotations [14]. The final two-qubit generalized controlled-phase gate in this decomposition method can be constructed using two twoqubit gates and three single-qubit Z rotations as shown in Fig. 3(d).

IV. CONCLUSION
We have presented a modified version of Grover's search algorithm to find the correct answer with zero failure rate without having user control over the oracle implementation. The main advantage of our D2p protocol is that it requires only two phase parameters to be used in the generalized multiply-controlled phase gates while providing quadratic speedup. The phases can be numerically determined for any marked-to-total number of states ratio λ ≤ 1/4. For 1/4 < λ < 1/2, one can use a single query of standard Grover's search [1] (non-deterministic) or any classical algorithm as there is no significant quantum advantage. The visual representation of this protocol using the Bloch-sphere pic-ture makes it very intuitive and can be adapted to other phase-matching protocols [7][8][9].
The D2p protocol can be readily applied to any framework where the quantum amplitude amplification [11][12][13]15], a generalization of Grover's search algorithm, is used including search using qudits. A few examples include element distinctness problem [16,17], minima finding [18,19], and collision problems [20]. Other interesting directions worth pursuing would be to investigate the range of (fixed) phases in the oracle compatible with the D2p protocol (see Appendix C), and explore deterministic variants of the generalized Grover-type searching algorithms [4]. One drawback is, however, the requirement of accurate knowledge of λ, which is true for other deterministic search algorithms as well [5]. There are attempts to bound the failure rate when λ is unknown by using multiple phase-matching [8] albeit at the expense of using more oracle queries than the standard optimal number k opt and having control over the oracle operator. Another extension of our protocol would be to address the possibility of achieving similar fixed-point behavior without user-controlled oracles. The D2p protocol can be applied to the cases when the oracle phase α = π. While k opt steps are sufficient to achieve zero failure rate for a range of α around π, increasingly more number of iterations are required with larger deviations. This property is demonstrated in Fig. 4 for λ = 1/16, chosen as an example. Exploring the dependence of optimal number of iterations and corresponding phase parameters as function of α and λ is a subject of future research.