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(value)[source]

An Enum over the types of variables for quadratic models.

SPIN[source]

Vartype for spin-valued binary quadratic models and variables of quadratic models that have values that are either -1 or 1.

BINARY[source]

Vartype for binary quadratic models and variables of quadratic models that have values that are either 0 or 1.

INTEGER[source]

Vartype for variables in quadratic models that have values of type int.

REAL[source]

Vartype for variables in quadratic models that have values of type float.

as_vartype(vartype: Union[dimod.vartypes.Vartype, str, frozenset], extended: bool = False) dimod.vartypes.Vartype[source]

Cast various inputs to a valid vartype object.

Parameters
  • vartype (Vartype/str/set) –

    Variable type. Accepted input values:

  • extended (bool, optional, default=False) –

    If True, vartype can also be:

Returns

Either SPIN or BINARY. If extended is True, can also be INTEGER or REAL

Return type

Vartype

Bound Information

vartype_info(vartype, dtype=<class 'numpy.float64'>)[source]

Information about the variable bounds by variable type.

Parameters
  • vartype

    Variable type. One of:

  • dtype – One of float64 and float32.

Returns

A named tuple with default_min, default_max, min, and max fields. These specify the default and largest bounds for the given variable type.