dimod.binary.Spin

Spin(label: Optional[Hashable] = None, bias: Union[float, numpy.floating, numpy.integer] = 1, dtype: Union[numpy.dtype[Any], None, Type[Any], numpy._typing._dtype_like._SupportsDType[numpy.dtype[Any]], str, Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], numpy._typing._dtype_like._DTypeDict, Tuple[Any, Any]] = None) dimod.binary.binary_quadratic_model.BinaryQuadraticModel[source]

Return a binary quadratic model with a single spin variable.

Parameters
  • label – Hashable label to identify the variable. Defaults to a generated uuid.UUID as a string.

  • bias – The bias to apply to the variable.

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

Returns

A BinaryQuadraticModel representing a spin-valued binary variable.

Examples

This example generates a BQM to represent the polynomial, \(3s - 1.5\), where \(s\) is a binary variable with spin values \(\{-1, 1\}\).

>>> s = dimod.Spin('s')
>>> bqm = 3*s - 1.5
>>> print(bqm.to_polystring())
-1.5 + 3*s