English
Languages
English
Shortcuts



GurobiOptimizer

class GurobiOptimizer(disp=False)[source]

Bases: qiskit_optimization.algorithms.optimization_algorithm.OptimizationAlgorithm

The Gurobi optimizer wrapped as an Qiskit OptimizationAlgorithm.

This class provides a wrapper for gurobipy to be used within the optimization module.

Examples

>>> from qiskit_optimization.problems import QuadraticProgram
>>> from qiskit_optimization.algorithms import GurobiOptimizer
>>> problem = QuadraticProgram()
>>> # specify problem here, if gurobi is installed
>>> optimizer = GurobiOptimizer() if GurobiOptimizer.is_gurobi_installed() else None
>>> # Suppress gurobipy print info to stdout
>>> import sys
>>> class DevNull:
...     def noop(*args, **kwargs): pass
...     close = write = flush = writelines = noop
>>> sys.stdout = DevNull()
>>> result = optimizer.solve(problem)

Initializes the GurobiOptimizer.

Parameters

disp (bool) – Whether to print Gurobi output or not.

Raises

MissingOptionalLibraryError – Gurobi is not installed.

Attributes

disp

Returns the display setting.

Methods

get_compatibility_msg(problem)

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

is_gurobi_installed()

Returns True if gurobi is installed

solve(problem)

Tries to solves the given problem using the optimizer.