dimod.binary.Binaries#

Binaries(labels: int | Iterable[Hashable], dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any] = None) Iterator[BinaryQuadraticModel][source]#

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

Parameters:
  • 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.

Yields:

A BinaryQuadraticModel for each binary variable.

Examples

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]