Models#
To express your problem as an objective function and submit to a D-Wave sampler for solution, you formulate a model.
Constrained Versus Unconstrained#
Many real-world problems include constraints. For example, a routing problem might limit the number of airplanes on the ground at an airport and a scheduling problem might require a minimum interval between shifts.
Constrained models such as the ConstrainedQuadraticModel
model
can support constraints by encoding both an objective and its set of
constraints, as models or in symbolic form.
Unconstrained quadratic models are used to submit problems to samplers such as D-Wave quantum computers[1] and some quantum-classical hybrid samplers[2]. When using such samplers to handle problems with constraints, you typically formulate the constraints as penalty models.
The Supported Models section below lists constrained and unconstrained models.
Supported Models#
The following table shows the models currently supported by Ocean software, the variables you can use with each, and some related classes.
Model |
Variables |
Ocean Class & Sampler |
---|---|---|
Constrained: |
||
Binary, integer |
||
Binary, integer, real |
||
Unconstrained: |
||
Spin |
||
Binary |
||
Binary, spin |
||
Binary, discrete |
Nonlinear Model#
Nonlinear models typically represent general optimization problems with an objective function and/or one or more constraints over integer and/or binary variables; the model supports constraints natively.
This model is especially suited for use with decision variables that represent a common logic, such as subsets of choices or permutations of ordering. For example, in a traveling salesperson problem permutations of the variables representing cities can signify the order of the route being optimized and in a knapsack problem the variables representing items can be divided into subsets of packed and not packed.
For an introduction to Ocean software’s nonlinear model, see the Model Construction (Nonlinear Models) section.
Constrained Quadratic Model#
Constrained quadratic models (CQM) are typically used for applications that optimize problems that might include binary-valued variables (both \(0/1\)-valued variables and \(-1/1\)-valued variables), integer-valued variables, and real variables (also known as continuous variables); the model supports constraints natively.
The constrained quadratic model (CQM) are problems of the form:
where \(\{ x_i\}_{i=1, \dots, N}\) can be binary[3], integer, or continuous[4] variables, \(a_{i}, b_{ij}, c\) are real values, \(\circ \in \{ \ge, \le, = \}\) and \(M\) is the total number of constraints.
For binary variables, the range of the quadratic-term summation is \(i < j\) because \(x^2 = x\) for binary values \(\{0, 1\}\) and \(s^2 = 1\) for spin values \(\{-1, 1\}\).
Real-valued variables are currently not supported in quadratic interactions.
For constructing quadratic models in Ocean software, see the Model Construction (Quadratic Models) section.
Binary Quadratic Models#
Binary quadratic models (BQM) are unconstrained and typically represent problems of decisions that could either be true (or yes) or false (no); for example, should an antenna transmit, or did a network node fail? The model uses \(0/1\)-valued variables and \(-1/1\)-valued variables; constraints are typically represented as penalty models.
The binary quadratic model (BQM) class encodes Ising and quadratic unconstrained binary optimization (QUBO) models used by samplers such as the D-Wave quantum computer.
The BQM equation,
can represent both.
Ising Model#
The Ising model is traditionally used in statistical mechanics. In the formula below, \(N\) variables \(s=[s_1,...,s_N]\) correspond to physical Ising “spin up” (\(\uparrow\)) and “spin down” (\(\downarrow\)) states, which can represent \(+1\) and \(-1\) values in an objective function.
Here, the linear coefficients, \(h_i\), correspond to qubit biases, and relationships between the spins (interactions: correlations or anti-correlations), \(J_{i,j}\), correspond to coupling strengths.
QUBO#
QUBO problems are traditionally used in computer science. Variables take values \(1\) (TRUE) and \(0\) (FALSE).
A QUBO problem is defined using an upper-diagonal matrix \(Q\), which is an \(N \times N\) upper-triangular matrix of real weights, and \(x\), a vector of binary variables, as minimizing the function
where the diagonal terms \(Q_{i,i}\) are the linear coefficients and the nonzero off-diagonal terms \(Q_{i,j}\) are the quadratic coefficients.
This can be expressed more concisely as
In scalar notation, the objective function expressed as a QUBO is as follows:
Note
Quadratic unconstrained binary optimization problems—QUBOs—are unconstrained in that there are no constraints on the variables other than those expressed in Q.
Other Models#
Ocean software also supports these additional models.
Quadratic Models#
Quadratic models are polynomials with one or two variables per term. A simple example of a quadratic model is,
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.
Quantum computers solve hard problems by minimizing an objective function. Quadratic models are useful objective functions because the quantum processing unit (QPU) can represent binary variables as the states of the qubits and linear and quadratic coefficients as, respectively, the physical biases and couplings applied to these qubits. Hybrid quantum-classical samplers, which minimize some parts of the objective function using classical heuristics and some by using the QPU, enable the further abstraction of problem representation.
Ocean supports various quadratic models:
Ising Model and QUBO
Binary Quadratic Models are unconstrained and support binary variables.
Constrained Quadratic Model can be constrained and support real, integer and binary variables.
Discrete Quadratic Models are unconstrained and support discrete variables.
Ocean also provides support for higher order models, which are typically reduced to quadratic for sampling.
Discrete Quadratic Models#
The discrete quadratic model (DQM) is a polynomial over discrete variables,
with all terms of degree two or less, where a discrete variable represents some
collection of distinct values, such as {red, green, blue, yellow}
or
{3.2, 67}
, which are called the variable’s cases.
A discrete quadratic model may be defined as
where \(\bf{d}_i\) are the discrete variables, \(a_i()\) and \(b_{i,j}()\) are real-valued functions, and \(c\) is a constant (offset).
You can represent any DQM with an equivalent model over binary variables by replacing each discrete variable, \(\bf{d}_i\), with a vector of binary variables using one-hot encoding, where exactly one binary variable is True and all others are False: \(\sum_a x_{i,a} = 1 \quad \forall i\).
In particular, a discrete quadratic model for \(N\) discrete variables, \(\bf{d}_i\), each with \(n_i\) cases, is then defined by using a binary variable, \(x_{i,u}\), to indicate whether discrete variable \(\bf{d}_i\) is set to case \(u\). The objective function can be expressed by the equation:
Both representations are equivalent over the feasible space; that is, the solutions that meet the one-hot-encoding constraints. The second representation ascribes energies both to the feasible space (satisfying constraints), and an infeasible space (violating constraints). The second representation is used by Ocean tools.
The dimod.DiscreteQuadraticModel
class can contain this model and its
methods provide convenient utilities for working with representations
of a problem.