dimod.binary.as_bqm

as_bqm(*args, cls: None = None, copy: bool = False, 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]

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 and cls kwargs below.

as_bqm(bqm, vartype)

Creates a BQM from another BQM, changing to the appropriate vartype if necessary. See copy and cls 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, ...}, and quadratic 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, ...}, and quadratic is a square array_like or a dictionary of the form {(u, v): b, ...}, and offset 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.