Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version

Grover

Grover(oracle, init_state=None, incremental=False, num_iterations=1, mct_mode='basic', quantum_instance=None)

GitHub(opens in a new tab)

The Grover’s Search algorithm.

Grover’s Search is a well known quantum algorithm for searching through unstructured collections of records for particular targets with quadratic speedup compared to classical algorithms.

Given a set XX of NN elements X={x1,x2,,xN}X=\{x_1,x_2,\ldots,x_N\} and a boolean function f:X{0,1}f : X \rightarrow \{0,1\}, the goal of an unstructured-search problem is to find an element xXx^* \in X such that f(x)=1f(x^*)=1.

Unstructured search is often alternatively formulated as a database search problem, in which, given a database, the goal is to find in it an item that meets some specification.

The search is called unstructured because there are no guarantees as to how the database is ordered. On a sorted database, for instance, one could perform binary search to find an element in O(logN)\mathbb{O}(\log N) worst-case time. Instead, in an unstructured-search problem, there is no prior knowledge about the contents of the database. With classical circuits, there is no alternative but to perform a linear number of queries to find the target element. Conversely, Grover’s Search algorithm allows to solve the unstructured-search problem on a quantum computer in O(N)\mathcal{O}(\sqrt{N}) queries.

All that is needed for carrying out a search is an oracle from Aqua’s oracles module for specifying the search criterion, which basically indicates a hit or miss for any given record. More formally, an oracle OfO_f is an object implementing a boolean function ff as specified above. Given an input xXx \in X, OfO_f implements f(x)f(x). The details of how OfO_f works are unimportant; Grover’s search algorithm treats the oracle as a black box.

For example the LogicalExpressionOracle can take as input a SAT problem in DIMACS CNF format(opens in a new tab) and be used with Grover algorithm to find a satisfiable assignment.

Parameters

  • oracle (Oracle) – The oracle component
  • init_state (Optional[InitialState]) – An optional initial quantum state. If None (default) then Grover’s Search by default uses uniform superposition to initialize its quantum state. However, an initial state may be supplied, if useful, for example, if the user has some prior knowledge regarding where the search target(s) might be located.
  • incremental (bool) – Whether to use incremental search mode (True) or not (False). Supplied num_iterations is ignored when True and instead the search task will be carried out in successive rounds, using circuits built with incrementally higher number of iterations for the repetition of the amplitude amplification until a target is found or the maximal number logN\log N (NN being the total number of elements in the set from the oracle used) of iterations is reached. The implementation follows Section 4 of Boyer et al. <https://arxiv.org/abs/quant-ph/9605034(opens in a new tab)>
  • num_iterations (int) – How many times the marking and reflection phase sub-circuit is repeated to amplify the amplitude(s) of the target(s). Has a minimum value of 1.
  • mct_mode (str) – Multi-Control Toffoli mode (‘basic’ | ‘basic-dirty-ancilla’ | ‘advanced’ | ‘noancilla’)
  • quantum_instance (Union[QuantumInstance, BaseBackend, None]) – Quantum Instance or Backend

Raises

AquaError – evaluate_classically() missing from the input oracle


Attributes

backend

qiskit.providers.basebackend.BaseBackend

Returns backend.

Return type

BaseBackend

qc_amplitude_amplification_iteration

qc amplitude amplification iteration

quantum_instance

Union[None, qiskit.aqua.quantum_instance.QuantumInstance]

Returns quantum instance.

Return type

Optional[QuantumInstance]

random

Return a numpy random.


Methods

construct_circuit

Grover.construct_circuit(measurement=False)

Construct the quantum circuit

Parameters

measurement (bool) – Boolean flag to indicate if measurement should be included in the circuit.

Returns

the QuantumCircuit object for the constructed circuit

Return type

QuantumCircuit

run

Grover.run(quantum_instance=None, **kwargs)

Execute the algorithm with selected backend.

Parameters

Returns

results of an algorithm.

Return type

dict

Raises

AquaError – If a quantum instance or backend has not been provided

set_backend

Grover.set_backend(backend, **kwargs)

Sets backend with configuration.

Return type

None

Was this page helpful?
Report a bug or request content on GitHub.