dimod.BinaryQuadraticModel.from_qubo

classmethod BinaryQuadraticModel.from_qubo(Q, offset=0.0)[source]

Create a binary quadratic model from a QUBO model.

Parameters:
  • Q (dict) – Coefficients of a quadratic unconstrained binary optimization (QUBO) problem. Should be a dict of the form {(u, v): bias, …} where u, v, are binary-valued variables and bias is their associated coefficient.
  • offset (optional, default=0.0) – Constant offset applied to the model.
Returns:

Binary quadratic model with vartype set to Vartype.BINARY.

Return type:

BinaryQuadraticModel

Examples

This example creates a binary quadratic model from a QUBO model.

>>> import dimod
>>> Q = {(0, 0): -1, (1, 1): -1, (0, 1): 2}
>>> model = dimod.BinaryQuadraticModel.from_qubo(Q, offset = 0.0)
>>> model.linear    # doctest: +SKIP
{0: -1, 1: -1}
>>> model.vartype
<Vartype.BINARY: frozenset({0, 1})>