View on GitHub
Open this notebook in GitHub to run it yourself
grover_operator
Arguments:
-
oracle: QCallable[QArray[QBit]] - Oracle representing , accepting quantum state to apply on.
-
space_transform: QCallable[QArray[QBit]] - State preparation operator , 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:
| vars.x | vars.y | counts | probability | bitstring | predicate | |
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 989 | 0.482910 | 1001 | True |
| 1 | 2 | 1 | 956 | 0.466797 | 0110 | True |
| 2 | 0 | 1 | 13 | 0.006348 | 0100 | False |
| 3 | 3 | 1 | 13 | 0.006348 | 0111 | False |
| 4 | 2 | 0 | 11 | 0.005371 | 0010 | False |
| 5 | 0 | 2 | 9 | 0.004395 | 1000 | False |
| 6 | 2 | 3 | 8 | 0.003906 | 1110 | False |
| 7 | 1 | 0 | 7 | 0.003418 | 0001 | False |
| 8 | 2 | 2 | 7 | 0.003418 | 1010 | False |
| 9 | 3 | 2 | 7 | 0.003418 | 1011 | False |
| 10 | 0 | 3 | 7 | 0.003418 | 1100 | False |
| 11 | 1 | 1 | 5 | 0.002441 | 0101 | False |
| 12 | 1 | 3 | 5 | 0.002441 | 1101 | False |
| 13 | 0 | 0 | 4 | 0.001953 | 0000 | False |
| 14 | 3 | 0 | 4 | 0.001953 | 0011 | False |
| 15 | 3 | 3 | 3 | 0.001465 | 1111 | False |