Vartype

Enumeration of valid variable types for binary quadratic models.

Examples

Vartype is an Enum. Each vartype has a value and a name.

>>> vartype = dimod.SPIN
>>> vartype.name
'SPIN'
>>> vartype.value == {-1, +1}
True
>>> vartype = dimod.BINARY
>>> vartype.name
'BINARY'
>>> vartype.value == {0, 1}
True

The as_vartype() function allows the user to provide several convenient forms.

>>> from dimod import as_vartype
>>> as_vartype(dimod.SPIN) is dimod.SPIN
True
>>> as_vartype('SPIN') is dimod.SPIN
True
>>> as_vartype({-1, 1}) is dimod.SPIN
True
>>> as_vartype(dimod.BINARY) is dimod.BINARY
True
>>> as_vartype('BINARY') is dimod.BINARY
True
>>> as_vartype({0, 1}) is dimod.BINARY
True
class Vartype[source]

An Enum over the types of variables for the binary quadratic model.

SPIN

Vartype for spin-valued models; variables of the model are either -1 or 1.

Type:Vartype
BINARY

Vartype for binary models; variables of the model are either 0 or 1.

Type:Vartype
as_vartype(vartype)[source]

Cast various inputs to a valid vartype object.

Parameters:vartype (Vartype/str/set) –

Variable type. Accepted input values:

  • Vartype.SPIN, 'SPIN', {-1, 1}
  • Vartype.BINARY, 'BINARY', {0, 1}
Returns:Either Vartype.SPIN or Vartype.BINARY.
Return type:Vartype