dimod.binary.SpinArray¶
- SpinArray(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) numpy.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
BinaryQuadraticModel
s, 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