Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
The Grover operator is a unitary used in amplitude estimation and amplitude amplification algorithms [1]. The Grover operator is given by Q=Q(A,χ)=AS0A1SχQ = Q(A,\chi) = -AS_0A^{-1}S_\chi where AA is a state preparation operator, A0=ψA|0 \rangle= |\psi \rangle SχS_\chi marks good states and is called an oracle, Sχx={xif χ(x)=1xif χ(x)=0S_\chi\lvert x \rangle = \begin{cases} -\lvert x \rangle & \text{if } \chi(x) = 1 \\ \phantom{-} \lvert x \rangle & \text{if } \chi(x) = 0 \end{cases} and S0S_0 is a reflection about the zero state. S0=I200S_0 = I - 2|0\rangle\langle0| Function: grover_operator Arguments:
  • oracle: QCallable[QArray[QBit]]
  • Oracle representing SχS_{\chi}, accepting quantum state to apply on.
  • space_transform: QCallable[QArray[QBit]]
  • State preparation operator AA, accepting quantum state to apply on.
  • packed_vars: QArray[QBit]
  • Packed form of the variable to apply the grover operator on.

Example

The following example implements a grover search algorithm using the grover operator for a specific oracle, with a uniform superposition over the search space. The circuit starts with a uniform superposition on the search space, followed by 2 applications of the grover operator.
Output:
And the next is a verification of the amplification of the solutions to the oracle:

References

[1] G. Brassard, P. Hoyer, M. Mosca, and A. Tapp, “Quantum Amplitude Amplification and Estimation,” arXiv:quant-ph/0005055, vol. 305, pp. 53-74, 2002, doi: 10.1090/conm/305/05215.