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.
- as_vartype(vartype: Literal[Vartype.SPIN, 'SPIN', Vartype.BINARY, 'BINARY', Vartype.INTEGER, 'INTEGER', Vartype.REAL, 'REAL'], extended: bool = False) Vartype [source]#
Cast various inputs to a valid vartype object.
- Parameters:
- Returns:
Either
SPIN
orBINARY
. If extended is True, can also beINTEGER
orREAL
- Return type:
See also
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
andfloat32
.
- Returns:
A named tuple with
default_min
,default_max
,min
, andmax
fields. These specify the default and largest bounds for the given variable type.