Grover's Algorithm
An implementation in Pyquil, using only basic gates T, T_inverse, H, X, CNOT, and CZ.
Various test cases and graphings are commented out at the bottom of the code. More robust test suite and user interface coming!
Grover(Qubits, bitstring)
gives you a program which you can run and measure using qvm.run_and_measure()
or qvm.wavefunction()
. testGrover
is a helper function for running tests and summarizing results.
>>> testGrover(3, '010')
"""Searching for 010 with 2 iterations...
Result: Counter({(0, 1, 0): 947, (0, 0, 0): 13, (1, 1, 1): 9, (0, 1, 1): 9, (0, 0, 1): 6, (1, 1, 0): 6, (1, 0, 1): 5, (1, 0, 0): 5})"""
Resources
Building multi-qubit gates from simple gates Rieffel and Polak, Quantum Computing: A Gentle Introduction, Ch 6.4
Proving Correctness of Amplification Circuit
Presentation of the circuit building blocks
Thanks to Monica Schleier-Smith and Jordan Cotler!