dimod.binary.as_bqm#
- as_bqm(*args, cls: None = None, copy: bool = False, 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) BinaryQuadraticModel [source]#
Convert the input to a binary quadratic model.
Converts the following input formats to a binary quadratic model (BQM):
- as_bqm(vartype)
Creates an empty binary quadratic model.
- as_bqm(bqm)
Creates a BQM from another BQM. See
copy
andcls
kwargs below.- as_bqm(bqm, vartype)
Creates a BQM from another BQM, changing to the appropriate
vartype
if necessary. Seecopy
andcls
kwargs below.- as_bqm(n, vartype)
Creates a BQM with
n
variables, indexed linearly from zero, setting all biases to zero.- as_bqm(quadratic, vartype)
Creates a BQM from quadratic biases given as a square array_like or a dictionary of the form
{(u, v): b, ...}
. Note that when formed with SPIN-variables, biases on the diagonal are added to the offset.- as_bqm(linear, quadratic, vartype)
Creates a BQM from linear and quadratic biases, where
linear
is a one-dimensional array_like or a dictionary of the form{v: b, ...}
, andquadratic
is a square array_like or a dictionary of the form{(u, v): b, ...}
. Note that when formed with SPIN-variables, biases on the diagonal are added to the offset.- as_bqm(linear, quadratic, offset, vartype)
Creates a BQM from linear and quadratic biases, where
linear
is a one-dimensional array_like or a dictionary of the form{v: b, ...}
, andquadratic
is a square array_like or a dictionary of the form{(u, v): b, ...}
, andoffset
is a numerical offset. Note that when formed with SPIN-variables, biases on the diagonal are added to the offset.
- Parameters:
*args – See above.
cls – Deprecated. This function always returns a
BinaryQuadraticModel
.copy – If False, a new BQM is only constructed when necessary.
dtype – Data type of the returned BQM.
- Returns:
A binary quadratic model.