CQM Presolve

Presolver

Class

class Presolver(cqm: dimod.constrained.constrained.ConstrainedQuadraticModel, *, move: bool = False)[source]

Presolver for constrained quadratic models.

Parameters
  • cqm – A dimod.ConstrainedQuadraticModel.

  • move – If True, the original constrained quadratic model is cleared and its contents are moved to the presolver. This is useful for large models where memory is a concern.

Example

>>> import dimod
>>> from dwave.preprocessing import Presolver

Given a CQM with one variable fixed by bounds

>>> cqm = dimod.ConstrainedQuadraticModel()
>>> i = dimod.Integer('i', lower_bound=-5, upper_bound=5)
>>> j = dimod.Integer('j', lower_bound=5, upper_bound=10)
>>> cqm.set_objective(i + j)
>>> c0 = cqm.add_constraint(j <= 5)  # implicitly fixes 'j'

Then run the presolved with default settings.

>>> presolver = Presolver(cqm)
>>> presolver.load_default_presolvers()
>>> presolver.apply()

# The model has been reduced

>>> reduced_cqm = presolver.copy_model()
>>> reduced_cqm.num_variables()
1
>>> reduced_cqm.num_constraints()
0

Methods

apply()

Apply any loaded presolve techniques to the held model.

copy_model

Return a copy of the held CQM.

clear_model

Clear the held model.

detach_model

Create a dimod.ConstrainedQuadraticModel` from the held model.

load_default_presolvers

Load the default presolvers.

restore_samples

Restore a set of reduced samples to the original variable labels.

C++ API

Warning

doxygenclass: Cannot find class “dwave::presolve::Presolver” in doxygen xml output for project “minorminer” from directory: /home/docs/checkouts/readthedocs.org/user_builds/d-wave-systems-dwave-ocean-sdk/checkouts/stable/minorminer/docs/build-cpp/xml/

Warning

doxygenclass: Cannot find class “dwave::presolve::Postsolver” in doxygen xml output for project “minorminer” from directory: /home/docs/checkouts/readthedocs.org/user_builds/d-wave-systems-dwave-ocean-sdk/checkouts/stable/minorminer/docs/build-cpp/xml/