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 | 985 | 0.480957 | 1001 | True |
| 1 | 2 | 1 | 949 | 0.463379 | 0110 | True |
| 2 | 2 | 2 | 13 | 0.006348 | 1010 | False |
| 3 | 0 | 3 | 13 | 0.006348 | 1100 | False |
| 4 | 3 | 3 | 13 | 0.006348 | 1111 | False |
| 5 | 3 | 0 | 10 | 0.004883 | 0011 | False |
| 6 | 2 | 3 | 9 | 0.004395 | 1110 | False |
| 7 | 1 | 1 | 8 | 0.003906 | 0101 | False |
| 8 | 0 | 2 | 8 | 0.003906 | 1000 | False |
| 9 | 0 | 0 | 7 | 0.003418 | 0000 | False |
| 10 | 1 | 0 | 7 | 0.003418 | 0001 | False |
| 11 | 2 | 0 | 6 | 0.002930 | 0010 | False |
| 12 | 0 | 1 | 6 | 0.002930 | 0100 | False |
| 13 | 3 | 1 | 5 | 0.002441 | 0111 | False |
| 14 | 3 | 2 | 5 | 0.002441 | 1011 | False |
| 15 | 1 | 3 | 4 | 0.001953 | 1101 | False |