dimod.utilities.qubo_to_ising#

qubo_to_ising(Q, offset=0.0)[source]#

Convert a QUBO problem to an Ising problem.

Map a quadratic unconstrained binary optimization (QUBO) problem \(x' Q x\) defined over binary variables (0 or 1 values), where the linear term is contained along the diagonal of Q, to an Ising model defined on spins (variables with {-1, +1} values). Return h and J that define the Ising model as well as the offset in energy between the two problem formulations:

\[x' Q x = offset + s' J s + h' s\]

See ising_to_qubo() for the inverse function.

Parameters:
  • Q (dict[(variable, variable), coefficient]) – QUBO coefficients in a dict of form {(u, v): coefficient, …}, where keys are 2-tuples of variables of the model and values are biases associated with the pair of variables. Tuples (u, v) represent interactions and (v, v) linear biases.

  • offset (numeric, optional, default=0) – Constant offset to be applied to the energy. Default 0.

Returns:

A 3-tuple containing:

dict: Linear coefficients of the Ising problem.

dict: Quadratic coefficients of the Ising problem.

float: New energy offset.

Return type:

(dict, dict, float)

Examples

This example converts a QUBO problem of two variables that have positive biases of value 1 and are positively coupled with an interaction of value 1 to an Ising problem, and shows the new energy offset.

>>> Q = {(1, 1): 1, (2, 2): 1, (1, 2): 1}
>>> dimod.qubo_to_ising(Q, 0.5)[2]
1.75