Variables#

D-Wave’s samplers mostly[1] solve quadratic models of various sorts. Quadratic models are characterized by having one or two variables per term. A simple example of a quadratic model is,

\[D = Ax + By + Cxy\]

where \(A\), \(B\), and \(C\) are constants. Single variable terms—\(Ax\) and \(By\) here—are linear with the constant biasing the term’s variable. Two-variable terms—\(Cxy\) here—are quadratic with a relationship between the variables.

The variables in these models may be of the following types.

Table 101 Supported Variables#

Variable

Usage

Quadratic Model

Nonlinear Model

Binary.

\(v_i \in\{-1,+1\} \text{ or } \{0,1\}\).

Typically used for applications that optimize over decisions that could either be true (or yes) or false (no); for example,

  • Should the antenna transmit or no?

  • Did a network node experience failure?

BINARY and SPIN

BinaryVariable

Discrete.

For example, a variable that can be assigned one of the values of the set {red, green, blue, yellow}.

Typically used for applications that optimize over several distinct options; for example,

  • Which shift should employee X work?

  • Should the state be colored red, blue, green or yellow?

INTEGER

Integer.

Typically used for applications that optimize the number of something; for example,

  • How many widgets should be loaded onto the truck?

INTEGER

IntegerVariable

Real.

Typically used for applications that optimize over an uncountable set; for example,

  • Where should the sensor be built?

REAL

Variable Representations and Labels#

Ocean software enables you to represent a variable with a quadratic model, as described in the Symbolic Math section. This makes it important to distinguish between such a variable’s representation and its label.

For example, in the code below, variables a, i, j are represented by QuadraticModel objects and the ten variables in array x by BinaryQuadraticModel objects:

>>> a = dimod.Real("a")
>>> i, j = dimod.Integers(["i", "j"])
>>> x = dimod.BinaryArray([f"x{i}" for i in range(10)])

Each such variable is represented by a quadratic model that has a single linear bias of 1,

>>> x[0]
BinaryQuadraticModel({'x0': 1.0}, {}, 0.0, 'BINARY')

with its single variable having a specified label; e.g., x0 for the first model in x.

The code below adds two variables to a ConstrainedQuadraticModel. The first, using the add_variable() method, adds a variable by specifying a label, "b", and the type of required variable, "REAL". The second, using the add_constraint_from_model() method, specifies the variable i instantiated above as a QuadraticModel object.

>>> cqm = dimod.ConstrainedQuadraticModel()
>>> cqm.add_variable("b", "REAL")
'b'
>>> cqm.add_constraint_from_model(i, ">=", 2, "Min i")
'Min i'
>>> cqm.variables
Variables(['b', 'i'])