Skip to content

Commit

Permalink
Merge pull request #23 from rigetticomputing/doc-update/grovers
Browse files Browse the repository at this point in the history
Update documentation with Grover's
  • Loading branch information
willzeng authored Apr 17, 2017
2 parents c373dcf + 5018b74 commit a7155dd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
21 changes: 21 additions & 0 deletions docs/grover.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Grover's Search Algorithm
=========================

Overview
--------

Quantum search algorithm via amplitude amplification.

Source Code Docs
----------------

Here you can find documentation for the different submodules in phaseestimation.

grove.grover.grover
~~~~~~~~~~~~~~~~~~~

.. automodule:: grove.grover.grover
:members:
:undoc-members:
:show-inheritance:

1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ of which has its own self-contained documentation.
qaoa
qft
phaseestimation
grover

Indices and Tables
__________________
Expand Down
14 changes: 9 additions & 5 deletions grove/grover/grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def n_qubit_control(controls, target, u, gate_name):
Uses a number of gates quadratic in the number of qubits, and defines a linear number of new
gates. (Roots and adjoints of u.)
:param controls: The indices of the qubits to condition the gate on.
:param target: The index of the target of the gate.
:param u: The unitary gate to be controlled, given as a numpy array.
Expand Down Expand Up @@ -81,8 +82,9 @@ def diffusion_operator(qubits):
significant qubit to least significant qubit.
The diffusion operator is the diagonal operator given by(1, -1, -1, ..., -1).
:param qubits: A list of ints corresponding to the qubits to operate on. The operator
operates on bistrings of the form |qubits[0], ..., qubits[-1]>.
operates on bistrings of the form |qubits[0], ..., qubits[-1]>.
"""
p = pq.Program()

Expand All @@ -107,13 +109,14 @@ def grover(oracle, qubits, query_qubit, num_iter=None):
Implementation of Grover's Algorithm for a given oracle.
The query qubit will be left in the zero state afterwards.
:param oracle: An oracle defined as a Program. It should send |x>|q> to |x>|q \oplus f(x)>,
where |q> is a a query qubit, and the range of f is {0, 1}.
where |q> is a a query qubit, and the range of f is {0, 1}.
:param qubits: List of qubits for Grover's Algorithm. The last is assumed to be query for the
oracle.
oracle.
:param query_qubit: The qubit |q> that the oracle write its answer to.
:param num_iter: The number of iterations to repeat the algorithm for. The default is
int(pi(sqrt(N))/4.
int(pi(sqrt(N))/4.
:return: A program corresponding to the desired instance of Grover's Algorithm.
"""
if len(qubits) < 1:
Expand Down Expand Up @@ -158,9 +161,10 @@ def basis_selector_oracle(bitstring, qubits, query_qubit):
Defines an oracle that selects the ith element of the computational basis.
Sends the state |x>|q> -> |x>|!q> if x==bitstring and |x>|q> otherwise.
:param bitstring: The desired bitstring, given as a string of ones and zeros. e.g. "101"
:param qubits: The qubits the oracle is called on, the last of which is the query qubit. The
qubits are assumed to be ordered from most significant qubit to least signicant qubit.
qubits are assumed to be ordered from most significant qubit to least signicant qubit.
:param query_qubit: The qubit |q> that the oracle write its answer to.
:return: A program representing this oracle.
"""
Expand Down

0 comments on commit a7155dd

Please sign in to comment.