dimod.utilities.ising_to_qubo¶
- ising_to_qubo(h, J, offset=0.0)[source]¶
Convert an Ising problem to a QUBO problem.
Map an Ising model defined on spins (variables with {-1, +1} values) to quadratic unconstrained binary optimization (QUBO) formulation \(x' Q x\) defined over binary variables (0 or 1 values), where the linear term is contained along the diagonal of Q. Return matrix Q that defines the model as well as the offset in energy between the two problem formulations:
\[s' J s + h' s = offset + x' Q x\]See
qubo_to_ising()
for the inverse function.- Parameters
h (dict[variable, bias]) – Linear biases as a dict of the form {v: bias, …}, where keys are variables of the model and values are biases.
J (dict[(variable, variable), bias]) – Quadratic biases as a dict of the form {(u, v): bias, …}, where keys are 2-tuples of variables of the model and values are quadratic biases associated with the pair of variables (the interaction).
offset (numeric, optional, default=0) – Constant offset to be applied to the energy. Default 0.
- Returns
A 2-tuple containing:
dict: QUBO coefficients.
float: New energy offset.
- Return type
Examples
This example converts an Ising problem of two variables that have positive biases of value 1 and are positively coupled with an interaction of value 1 to a QUBO problem and prints the resulting energy offset.
>>> h = {1: 1, 2: 1} >>> J = {(1, 2): 1} >>> dimod.ising_to_qubo(h, J, 0.5)[1] -0.5