dimod.binary.SpinArray#

SpinArray(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) ndarray[source]#

Return a NumPy array of binary quadratic models, each with a single spin variable.

Parameters:
  • labels – Either an iterable of variable labels or the number of required models. If a number, labels are generated using uuid.UUID.

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

Returns:

Array of BinaryQuadraticModels, each representing a single spin-valued binary variable.

Examples

This example creates a BQM for a ferromagnetic chain of ten spin variables (representing, for instance, ten coupled qubits) with increasing biases.

>>> import numpy as np
>>> x = dimod.SpinArray(range(10))
>>> lin_biases = np.linspace(1, 10, 10)
>>> bqm = x.dot(lin_biases) - dimod.quicksum(x[1:10] * x[0:9])
>>> print(bqm.to_polystring())           
v0 + 2*v1 + 3*v2 + ... + 9*v8 + 10*v9 - v0*v1 - v1*v2 - v2*v3 - ... - v8*v9