Binaries(labels: Union[int, Iterable[Hashable]], dtype: Union[numpy.dtype, None, type, numpy.typing._dtype_like._SupportsDType[numpy.dtype], str, Tuple[Any, int], Tuple[Any, Union[typing_extensions.SupportsIndex, Sequence[typing_extensions.SupportsIndex]]], List[Any], numpy.typing._dtype_like._DTypeDict, Tuple[Any, Any]] = None) Iterator[dimod.binary.binary_quadratic_model.BinaryQuadraticModel][source]

Yield binary quadratic models, each with a single binary variable.

  • labels – Either an iterable of variable labels or a number. If a number labels are generated using uuid.UUID.

  • dtype – Data type for the returned binary quadratic models.


A BinaryQuadraticModel for each binary variable.


This example generates a BQM that represents a Boolean NOT gate as a penalty model, \(2xy - x - y\), described in Ocean documentation’s NOT example. The output of the brute-force solver, ExactSolver, shows that best solutions are for assignments of the variables where \(z = \overline{x}\).

>>> x, y = dimod.Binaries(["x", "y"])
>>> bqm = 2*x*y - x - y
>>> print(bqm.to_polystring())
-x - y + 2*x*y
>>> print(dimod.ExactSolver().sample(bqm).lowest())
   x  y energy num_oc.
0  1  0   -1.0       1
1  0  1   -1.0       1
['BINARY', 2 rows, 2 samples, 2 variables]