Problem Formulation Guide: Whitepaper
Problem Formulation Guide: Whitepaper
WHITEPAPER
2020-10-27
Overview CONTACT
Corporate Headquarters
This guide steps users through the process of developing a model suit-
3033 Beta Ave
able for the D-Wave quantum processing unit (QPU) or hybrid solvers. Burnaby, BC V5G 4M9
By reading through this guide and working through the provided exer- Canada
cises, a new user with little to no prior experience with D-Wave tech- Tel. 604-630-1428
nology will able to model small problems using the binary quadratic US Office
model (BQM). 2650 E Bayshore Rd
Palo Alto, CA 94303
Email: [email protected]
www.dwavesys.com
14-1044A-B
D-Wave Whitepaper Series
Notice and Disclaimer
D-Wave Systems Inc. (“D-Wave”) reserves its intellectual property rights in and to this doc-
ument, any documents referenced herein, and its proprietary technology, including copyright,
trademark rights, industrial design rights, and patent rights. D-Wave trademarks used herein
include D-WAVE®, Leap™ quantum cloud service, Ocean™, Advantage™ quantum system,
D-Wave 2000Q™, D-Wave 2X™, and the D-Wave logo (the “D-Wave Marks”). Other marks used in
this document are the property of their respective owners. D-Wave does not grant any license, assign-
ment, or other grant of interest in or to the copyright of this document or any referenced documents,
the D-Wave Marks, any other marks used in this document, or any other intellectual property rights
used or referred to herein, except as D-Wave may expressly provide in a written agreement.
2 Definitions 2
2.1 Binary Quadratic Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Quadratic Unconstrained Binary Optimization . . . . . . . . . . . . . . . . . . . 3
2.2.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.2 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Ising Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3.2 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Equivalence of QUBO and Ising . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4.1 QUBO to Ising . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4.2 Ising to QUBO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4.3 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.5 Summary of Key Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
References 22
1.3 Exercise
How can we split the following problem up into an objective and constraints?
A business is trying to figure out the best way to pack a box full of items. There are five
items, with values 1, 5, 3, 4, and 2 dollars. These items have weights 2, 4, 4, 1, and 3 lbs,
respectively. The contents of the box must weigh exactly 6 lbs. What is the best way to pack
the box so that the box has the highest total value?
1.4 Resources
Many other resources are available for new users getting with D-Wave. Below is a selection
of some that may be especially useful.
2 Definitions
2.1 Binary Quadratic Model
The binary quadratic model (BQM) class of problems consists of Ising models and quadratic
unconstrained binary optimization (QUBO) models. These two forms are mathematically
equivalent, and our software tools allow you to work in either domain. In this guide, we
will provide examples and exercises in both forms. Note that some problems may see better
results with Ising over QUBO, and vice versa.
A BQM takes the following form.
!
min ∑ ai vi + ∑ ∑ bi,j vi v j + c
i i j >i
The coefficients ai and bi,j are constant numbers we choose to define our problem, as is the
constant term c. The binary variables vi and v j are the values that we are looking for to solve
our problem. The best solution for these variables is the value for each vi that produces
the smallest value for the overall expression. Searching for the variables that minimize an
expression is called an “argmin” in mathematics.
Let’s break this expression down.
Quadratic Terms. The second summation, ∑ ∑ bi,j vi v j , contains quadratic terms, with
each term in the summation containing a product of two variables.
Constants. In the general BQM form we may or may not include constants. Since we are
looking for an argmin, any constant terms will not affect our final answer. However, it may
be useful when interpreting the output from D-Wave solvers and samplers.
The binary variables xi and x j may take values from {0, 1}.
When we are ready to run a QUBO with the D-Wave Ocean software tool kit, one method
is to store the QUBO in a matrix format for the Ocean SDK. We can map a QUBO to a
matrix by placing linear terms along the diagonal and quadratic terms in the off-diagonal
positions.
2.2.1 Example
We can map x1 + 2x2 + 3x3 + 12x1 x2 + 13x1 x3 + 14x2 x4 to the following matrix.
1 12 13 0
0 2 0 14
0 0 3 0
0 0 0 0
In this matrix, we place coefficient ai in matrix position (i, i ) and coefficient bi,j in matrix
position (i, j).
2.2.2 Exercise
Put the following QUBO into matrix form.
x1 + x1 x2 − 3x3 + 5
The binary variables si and s j may take values from {−1, +1}.
When it comes time to write Ocean programs, we will need to represent our Ising model
as a matrix and a vector. We can map the quadratic terms of an Ising model to a matrix
by placing them in the off-diagonal positions, and the linear terms to a vector as a list of
coefficients as shown below.
2.3.1 Example
We can map s1 + 2s2 + 3s3 + 12s1 s2 + 13s1 s3 + 14s2 s4 to the following list and matrix.
Linear.
h= 1 2 3 0
Quadratic.
0 12 13 0
0 0 0 14
J=
0
0 0 0
0 0 0 0
2.3.2 Exercise
Put the following Ising model into matrix form.
s1 + s1 s2 − 3s3 + 5
si + 1
xi 7 →
2
Example.
f (x) = −22x1 − 6x2 − 14x 3 +20x1 x2+ 28x1 x3 + 9
s1 +1
= −22 2 − 6 s2 2+1 − 14 s3 2+1
+20 s1 2+1 s2 +1
2 + 28 s1 2+1 s3 +1
2 +9
= −11s1 − 11 − 3s2 − 3 − 7s3 − 7 + 5s1 s2
+5s1 + 5s2 + 5 + 7s1 s3 + 7s1 + 7s3 + 7 + 9
= s1 + 2s2 + 5s1 s2 + 7s1 s3
si 7→ 2xi − 1
Example.
2.4.3 Exercise
Convert the following QUBO model to an Ising model.
x1 + x1 x2 − 3x3 + 5
s1 + s1 s2 − 3s3 + 5
• The solution is the value of each binary variable that minimizes the expression.
The constraint satisfaction table is similar to a truth table - it covers all possible values for
our two variables and considers whether or not the constraint that we are modeling is true
or false for each choice of values.
3.2 Example
We start with a simple problem. We have two variables, say v1 and v2 , and we want a BQM
that represents the constraint v1 = v2 . For QUBO and Ising we follow the same process.
QUBO Ising
x1 x2 s1 s2 Equal
0 0 -1 -1 Yes
0 1 -1 +1 No
1 0 +1 -1 No
1 1 +1 +1 Yes
Next, replace the final column of yes/no values with small/large values, respectively.
0 0 -1 -1 0
0 1 -1 +1 1
1 0 +1 -1 1
1 1 +1 +1 0
In this step, we choose a small value when the constraint is satisfied because the QPU
is designed to minimize a BQM. By choosing a small value, we line up the ground state
(lowest energy the QPU can find) with the constraint being satisfied. Note that any choice
of small and large value can be used.
QUBO: a1 x1 + a2 x2 + b1,2 x1 x2 + c
Ising: h1 s1 + h2 s2 + J1,2 s1 s2 + c
Using each row in the constraint satisfaction table, we can write an equation. Each pair of
variable values, the general BQM model, and the final column value together determine
an equation in which the BQM coefficients are the only unknowns. This results in four
different equations (one for each row in the table).
QUBO
a1 · 0 + a2 · 0 + b1,2 · 0 · 0 + c = 0
a1 · 0 + a2 · 1 + b1,2 · 0 · 1 + c = 1
a1 · 1 + a2 · 0 + b1,2 · 1 · 0 + c = 1
a1 · 1 + a2 · 1 + b1,2 · 1 · 1 + c = 0
Ising
QUBO Ising
a1 = 1 h1 = 0
a2 = 1 h2 = 0
b1,2 = −2 J1,2 = −0.5
c=0 c = 0.5
To help with solving these systems of equations there are many resources online that
are available. Some of these are WolframAlpha (wolframalpha.com) or Matrix Calculator
(matrixcalc.org).
Our final models are:
QUBO: x1 + x2 − 2x1 x2
3.3 Exercise
What do the QUBO and Ising models look like for the constraint v1 ≥ v2 ?
Enemies:
Suppose that we are asked to split this group of people into two sets. Maybe they’re being
divided into two teams, or being split into groups for a project. Our goal is to split the
people into two groups so that we have friends in the same group and enemies in different
groups. How can we map this to a BQM?
The first step is to think about how we can use binary variables to represent the answer to
our problem. When we consider our problem, the answer that we’re looking for is which
group each person should be assigned to. If we call these groups “A” and “B”, then an
answer should look something like:
• Katie in Group A
• Anthony in Group A
• Carlos in Group B
• Betty in Group B
Group A Group B
QUBO 0 1
Ising -1 +1
Now that we have figured out how to align our answers with binary valued variables,
we need to figure out how to write our minimization function. A good way to tackle this
problem is to think about individual relationships instead of the entire set of people as a
whole. For two friends with a given relationship, which team assignments are good and
which are bad?
A A Good
A B Bad
B A Bad
B B Good
This table should look familiar now — it’s similar to what we did for our two variable rela-
tionships in the beginning of this guide! In fact, this is exactly the same as the QUBO/Ising
truth tables we used to create a BQM that represents the constraint v1 = v2 .
QUBO: x1 + x2 − 2x1 x2
QUBO Ising
QUBO Ising
x1 x2 s1 s2 Different?
0 0 -1 -1 No
0 1 -1 +1 Yes
1 0 +1 -1 Yes
1 1 +1 +1 No
QUBO Ising
x1 x2 s1 s2 Different?
0 0 -1 -1 1
0 1 -1 +1 0
1 0 +1 -1 0
1 1 +1 +1 1
QUBO
a1 · 0 + a2 · 0 + b1,2 · 0 · 0 + c = 1
a1 · 0 + a2 · 1 + b1,2 · 0 · 1 + c = 0
a1 · 1 + a2 · 0 + b1,2 · 1 · 0 + c = 0
a1 · 1 + a2 · 1 + b1,2 · 1 · 1 + c = 1
Ising
QUBO Ising
a1 = −1 h1 = 0
a2 = −1 h2 = 0
b1,2 = 2 J1,2 = 0.5
c=1 c = 0.5
QUBO: − x1 − x2 + 2x1 x2 + 1
QUBO Ising
QUBO:
( x A + xK − 2x A xK ) + ( x B + xC − 2x B xC ) + (− x A − xC + 2x A xC + 1)
x B + xK + 2x A xC − 2x A xK − 2x B xC + 1
Ising:
(−0.5s A sK + 0.5) + (−0.5s B sC + 0.5) + (0.5s A sC + 0.5)
To double-check our work, we can evaluate our BQM values for all possible assignments
for these four people. The rows with the smallest value tell us the best assignment of people
to teams.
A A A A 1
A A A B 2
A A B A 1
A A B B 2
A B A A 2
A B A B 3
A B B A 0
A B B B 1
B A A A 1
B A A B 0
B A B A 3
B A B B 2
B B A A 2
B B A B 1
B B B A 2
B B B B 1
Objective: None
Note that there may be more than one way to interpret your problem as objectives and
constraints.
Squared Terms. Our QUBO and Ising models don’t have room for squared binary vari-
ables. It turns out that we don’t actually need them.
QUBO: Our binary variables in a QUBO are 0 and 1. Note that 02 = 0 and 12 = 1, so we
can replace any term ‘xi2 with xi .
Ising: Our binary variables in an Ising model are -1 and +1. Note that (−1)2 = 1 and
(+1)2 = 1, so we can replace any term s2i with the constant 1.
Example:
Suppose that we have two companies that can complete the same job, each for a different
price. Company 1 can complete the job for $12, while Company 2 can complete the job for
$8. We want to have the job completed for the smallest cost.
We can model this problem as a QUBO. The objective is to minimize cost and the constraint
is that we must choose exactly one company. The binary variables x1 and x2 can be used to
indicate whether we will hire Company 1 or Company 2 to complete the job. Using these
binary variables, we write the objective as 12x1 + 8x2 and the constraint as ( x1 + x2 − 1)2 .
These can be combined to make the following QUBO.
min (12x1 + 8x2 ) + γ( x1 + x2 − 1)2
x1 x2 Value
0 0 1
0 1 8
1 0 12
1 1 21
Note that the smallest value of 1 corresponds to not choosing either company to complete
the job! Clearly this is not the optimal solution to our original problem, so we need to
adjust the Lagrange parameter to ensure that our constraint (choose exactly one company)
is satisfied.
Setting a larger Lagrange parameter will enforce our constraint. The following table demon-
strates the QUBO values for γ = 20.
0 0 20
0 1 8
1 0 12
1 1 40
Now we see that the smallest value corresponds to the optimal solution of hiring Company
2 to complete the job.
Note that you may need to try a few different values to identify the best Lagrange parame-
ter value for your specific BQM. A good starting value is to set γ equal to your best estimate
of the value of your objective function. If you find that your constraints are not satisfied in
the solutions returned, you may need to increase γ. On the other hand, if your constraints
are all satisfied but your solutions are not close to optimal, you may need to decrease γ.
Weight 15 20 25
This is a simple problem – we know that the answer is to choose boxes 15 and 20. But how
do we phrase this problem as a BQM?
Constraint: We are allowed to choose two boxes, so our constraint is “choose exactly two
boxes”.
QUBO xi = 1 xi = 0
Ising s i = +1 s i = −1
Once we have defined our binary variables, we can convert our objective and constraint
into math expressions.
Objective. We consider our objective for both QUBO and Ising forms.
QUBO:
To figure out the sum of the boxes that are chosen, we can use a weighted sum: 15x1 +
20x2 + 25x3 . In this sum, the boxes that are chosen will have xi = 1 and the boxes that are
not chosen will have xi = 0. In other words, the value of boxes that are not chosen will be
multiplied by zero and so we will only be adding up the value of the boxes that are chosen.
Our objective function becomes:
Ising:
Using our binary variables, we can convert our +1/-1 to 1/0 using the Ising to QUBO
translation shown earlier, which maps +1 7→ 1 and −1 7→ 0. Our objective function can
then be written as:
s +1 s +1 s +1
min 15 1 + 20 2 + 25 3
2 2 2
Constraint. We consider our constraint for both QUBO and Ising forms.
QUBO:
Our constraint “choose exactly two boxes” means that we need exactly two of our binary
variables to have value 1, and the remaining binary variable will have value 0. In other
words, our constraint can be written as:
x1 + x2 + x3 = 2
Ising:
Our constraint “choose exactly two boxes” means that we need exactly two of our binary
variables to have value +1, and the remaining binary variable will have value -1. In other
words, our constraint can be written as:
s1 + s2 + s3 = 1
Ising:
Following the same method, we can rewrite our constraint as follows.
( s1 + s2 + s3 − 1)2
Ising:
s1 + 1 s2 + 1 s3 + 1 2
min 15 + 20 + 25 + γ ( s1 + s2 + s3 − 1)
2 2 2
4.4.5 Exercise
Write a BQM for the following problem.
A business is trying to figure out the best way to pack a box full of items. There are five
items, with values 1, 5, 3, 4, and 2 dollars. These items have weights 2, 4, 4, 1, and 3 lbs,
respectively. The contents of the box must weigh exactly 6 lbs. What is the best way to pack
the box so that the box has the highest total value?
5.1.1 Solution
This problem can be split into an objective and constraints as follows.
5.2 Definitions
5.2.1 QUBO
Put the following QUBO into matrix form.
x1 + x1 x2 − 3x3 + 5
Solution:
1 1 0
0 0 0
0 0 −3
5.2.2 Ising
Put the following Ising model into matrix form.
s1 + s1 s2 − 3s3 + 5
Solution:
Linear:
h= 1 0 −3
Quadratic
0 1 0
J= 0 0 0
0 0 0
5.3.2 Ising
What is the Ising model for the constraint s1 ≥ s2 ?
Solution:
1 1 1 1
− s1 + s2 − s1 s2 +
4 4 4 4
5.4.1 QUBO
Solution:
( x1 + 5x2 + 3x3 + 4x4 + 2x5 ) + γ(2x1 + 4x2 + 4x3 + x4 + 3x5 − 6)2
5.4.2 Ising
Solution:
2
1 5 3 15 1 3
s1 + s2 + s3 + 2s4 + s5 + + γ s1 + 2s2 + 2s3 + s4 + s5 + 1
2 2 2 2 2 2