# qiskit.optimization.algorithms.GroverOptimizer¶

class GroverOptimizer(num_value_qubits, num_iterations=3, quantum_instance=None, converters=None, penalty=None)[source]

Uses Grover Adaptive Search (GAS) to find the minimum of a QUBO function.

Parameters
• num_value_qubits (int) – The number of value qubits.

• num_iterations (int) – The number of iterations the algorithm will search with no improvement.

• quantum_instance (Union[QuantumInstance, Backend, BaseBackend, None]) – Instance of selected backend, defaults to Aer’s statevector simulator.

• converters (Union[QuadraticProgramConverter, List[QuadraticProgramConverter], None]) – The converters to use for converting a problem into a different form. By default, when None is specified, an internally created instance of QuadraticProgramToQubo will be used.

• penalty (Optional[float]) – The penalty factor used in the default QuadraticProgramToQubo converter

Raises

TypeError – When there one of converters is an invalid type.

__init__(num_value_qubits, num_iterations=3, quantum_instance=None, converters=None, penalty=None)[source]
Parameters
• num_value_qubits (int) – The number of value qubits.

• num_iterations (int) – The number of iterations the algorithm will search with no improvement.

• quantum_instance (Union[QuantumInstance, Backend, BaseBackend, None]) – Instance of selected backend, defaults to Aer’s statevector simulator.

• converters (Union[QuadraticProgramConverter, List[QuadraticProgramConverter], None]) – The converters to use for converting a problem into a different form. By default, when None is specified, an internally created instance of QuadraticProgramToQubo will be used.

• penalty (Optional[float]) – The penalty factor used in the default QuadraticProgramToQubo converter

Raises

TypeError – When there one of converters is an invalid type.

Methods

 __init__(num_value_qubits[, num_iterations, …]) type num_value_qubits int get_compatibility_msg(problem) Checks whether a given problem can be solved with this optimizer. is_compatible(problem) Checks whether a given problem can be solved with the optimizer implementing this method. solve(problem) Tries to solves the given problem using the grover optimizer.

Attributes

 quantum_instance The quantum instance to run the circuits.
get_compatibility_msg(problem)[source]

Checks whether a given problem can be solved with this optimizer.

Checks whether the given problem is compatible, i.e., whether the problem can be converted to a QUBO, and otherwise, returns a message explaining the incompatibility.

Parameters

problem (QuadraticProgram) – The optimization problem to check compatibility.

Return type

str

Returns

A message describing the incompatibility.

is_compatible(problem)

Checks whether a given problem can be solved with the optimizer implementing this method.

Parameters

problem (QuadraticProgram) – The optimization problem to check compatibility.

Return type

bool

Returns

Returns True if the problem is compatible, False otherwise.

property quantum_instance

The quantum instance to run the circuits.

Return type

QuantumInstance

Returns

The quantum instance used in the algorithm.

solve(problem)[source]

Tries to solves the given problem using the grover optimizer.

Runs the optimizer to try to solve the optimization problem. If the problem cannot be, converted to a QUBO, this optimizer raises an exception due to incompatibility.

Parameters

problem (QuadraticProgram) – The problem to be solved.

Return type

OptimizationResult

Returns

The result of the optimizer applied to the problem.

Raises
• AttributeError – If the quantum instance has not been set.

• QiskitOptimizationError – If the problem is incompatible with the optimizer.