Skip to content

Commit

Permalink
Deploying to gh-pages from @ 8090e7a 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
nektos/act committed Jul 2, 2024
1 parent 7add26e commit f70491c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 30 deletions.
74 changes: 48 additions & 26 deletions choosing_boxes_problem/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<link rel="stylesheet" href="styling.css" />
<script src="/usr/share/javascript/mathjax/tex-mml-chtml.js" type="text/javascript"></script>
</head>
<body>
<h1 id="choosing-boxes">Choosing Boxes</h1>
<h3 id="problem">Problem</h3>
<nav id="TOC" role="doc-toc">
<ul>
<li><a href="#choosing-boxes"><span class="toc-section-number">1</span> Choosing Boxes</a>
<ul>
<li><a href="#problem"><span class="toc-section-number">1.0.1</span> Problem</a></li>
<li><a href="#code"><span class="toc-section-number">1.0.2</span> Code</a></li>
<li><a href="#visualization"><span class="toc-section-number">1.0.3</span> Visualization</a></li>
<li><a href="#sitemap-markdowns"><span class="toc-section-number">1.1</span> Sitemap Markdowns</a></li>
<li><a href="#sitemap-htmls"><span class="toc-section-number">1.2</span> Sitemap HTMLs</a></li>
</ul></li>
</ul>
</nav>
<h1 data-number="1" id="choosing-boxes"><span class="header-section-number">1</span> Choosing Boxes</h1>
<h3 data-number="1.0.1" id="problem"><span class="header-section-number">1.0.1</span> Problem</h3>
<p>The problem “Choosing Boxes” is described in the <a href="https://www.dwavesys.com/media/bu0lh5ee/problem-formulation-guide-2022-01-10.pdf">D-Wave problem formulation guide</a> in chapt. 4.4.</p>
<details>
<p><summary> Choosing Boxes Problem </summary></p>
<h4 id="example-choosing-boxes">Example: Choosing Boxes</h4>
<h4 data-number="1.0.1.1" id="example-choosing-boxes"><span class="header-section-number">1.0.1.1</span> Example: Choosing Boxes</h4>
<p>We’re given three boxes with different weights. We want to choose the two boxes with the smallest sum.</p>
<table>
<thead>
Expand All @@ -41,10 +55,10 @@ <h4 id="example-choosing-boxes">Example: Choosing Boxes</h4>
</tbody>
</table>
<p>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?</p>
<h5 id="step-1-write-objective-and-constraints">Step 1: Write Objective and Constraints</h5>
<h5 data-number="1.0.1.1.1" id="step-1-write-objective-and-constraints"><span class="header-section-number">1.0.1.1.1</span> Step 1: Write Objective and Constraints</h5>
<p><strong>Objective</strong>: We are looking for the smallest sum, so our objective is “minimize the sum of the boxes chosen”.<br />
<strong>Constraint</strong>: We are allowed to choose two boxes, so our constraint is “choose exactly two boxes”.</p>
<h5 id="step-2-convert-objective-and-constraints-into-binary-math-expressions">Step 2: Convert Objective and Constraints into Binary Math Expressions</h5>
<h5 data-number="1.0.1.1.2" id="step-2-convert-objective-and-constraints-into-binary-math-expressions"><span class="header-section-number">1.0.1.1.2</span> Step 2: Convert Objective and Constraints into Binary Math Expressions</h5>
<p><strong>Binary Variables.</strong> First, we need to define our binary variables. The answer that we are looking for is which boxes we should choose. For each box, we can ask “do we choose this box?”. This points us to how we should define our binary variables.</p>
<table>
<thead>
Expand All @@ -57,54 +71,61 @@ <h5 id="step-2-convert-objective-and-constraints-into-binary-math-expressions">S
<tbody>
<tr class="odd">
<td>QUBO</td>
<td><span class="math inline"><em>x</em><sub><em>i</em></sub> = 1</span></td>
<td><span class="math inline"><em>x</em><sub><em>i</em></sub> = 0</span></td>
<td><span class="math inline">\(x_i = 1\)</span></td>
<td><span class="math inline">\(x_i = 0\)</span></td>
</tr>
<tr class="even">
<td>Ising</td>
<td><span class="math inline"><em>s</em><sub><em>i</em></sub> =  + 1</span></td>
<td><span class="math inline"><em>s</em><sub><em>i</em></sub> =  − 1</span></td>
<td><span class="math inline">\(s_i = +1\)</span></td>
<td><span class="math inline">\(s_i = −1\)</span></td>
</tr>
</tbody>
</table>
<p>Once we have defined our binary variables, we can convert our objective and constraint into math expressions.</p>
<p><strong>Objective.</strong> We consider our objective for both QUBO and Ising forms.</p>
<p><strong>QUBO:</strong> To figure out the sum of the boxes that are chosen, we can use a weighted sum: <span class="math inline">15<em>x</em><sub>1</sub> + 20<em>x</em><sub>2</sub> + 25<em>x</em><sub>3</sub></span>. In this sum, the boxes that are chosen will have <span class="math inline"><em>x</em><sub><em>i</em></sub> = 1</span> and the boxes that are not chosen will have <span class="math inline"><em>x</em><sub><em>i</em></sub> = 0</span>. 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:</p>
<p><br /><span class="math display"><em>m</em><em>i</em><em>n</em>(15<em>x</em><sub>1</sub> + 20<em>x</em><sub>2</sub> + 25<em>x</em><sub>3</sub>)</span><br /></p>
<p><strong>QUBO:</strong> To figure out the sum of the boxes that are chosen, we can use a weighted sum: <span class="math inline">\(15x_1 + 20x_2 + 25x_3\)</span>. In this sum, the boxes that are chosen will have <span class="math inline">\(x_i = 1\)</span> and the boxes that are not chosen will have <span class="math inline">\(x_i = 0\)</span>. 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:</p>
<p><span class="math display">\[
min(15x_1 + 20x_2 + 25x_3)
\]</span></p>
<p><strong>Ising:</strong> 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:</p>
<p><br /><span class="math display">$$
<p><span class="math display">\[
min \left (
15 \left ( \frac{s_1 + 1}{2} \right ) +
20 \left ( \frac{s_2 + 1}{2} \right ) +
25 \left ( \frac{s_3 + 1}{2} \right )
\right )
$$</span><br /></p>
\]</span></p>
<p><strong>Constraint.</strong> We consider our constraint for both QUBO and Ising forms.</p>
<p><strong>QUBO:</strong> 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:</p>
<p><br /><span class="math display"><em>x</em><sub>1</sub> + <em>x</em><sub>2</sub> + <em>x</em><sub>3</sub> = 2</span><br /></p>
<p><span class="math display">\[x_1 + x_2 + x_3 = 2\]</span></p>
<p><strong>Ising:</strong> 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:</p>
<p><br /><span class="math display"><em>s</em><sub>1</sub> + <em>s</em><sub>2</sub> + <em>s</em><sub>3</sub> = 1</span><br /></p>
<h5 id="step-3-transform-math-expressions-into-a-bqm">Step 3: Transform Math Expressions into a BQM</h5>
<p><span class="math display">\[s_1 + s_2 + s_3 = 1\]</span></p>
<h5 data-number="1.0.1.1.3" id="step-3-transform-math-expressions-into-a-bqm"><span class="header-section-number">1.0.1.1.3</span> Step 3: Transform Math Expressions into a BQM</h5>
<p>Our objective function is fine as written, so we only need to modify our constraint.</p>
<p><strong>QUBO:</strong> To modify our constraint, we need to use the method for equalities. Original constraint: <br /><span class="math display"><em>x</em><sub>1</sub> + <em>x</em><sub>2</sub> + <em>x</em><sub>3</sub> = 2</span><br /> Move everything to one side: <br /><span class="math display"><em>x</em><sub>1</sub> + <em>x</em><sub>2</sub> + <em>x</em><sub>3</sub> − 2 = 0</span><br /> Square the expression: <br /><span class="math display">(<em>x</em><sub>1</sub> + <em>x</em><sub>2</sub> + <em>x</em><sub>3</sub> − 2)<sup>2</sup></span><br /></p>
<p><strong>Ising:</strong> Following the same method, we can rewrite our constraint as follows. <br /><span class="math display">(<em>s</em><sub>1</sub> + <em>s</em><sub>2</sub> + <em>s</em><sub>3</sub> − 1)<sup>2</sup></span><br /></p>
<h5 id="step-4-combine-expressions">Step 4: Combine Expressions</h5>
<p><strong>QUBO:</strong> To modify our constraint, we need to use the method for equalities. Original constraint: <span class="math display">\[x_1 + x_2 + x_3 = 2\]</span> Move everything to one side: <span class="math display">\[x_1 + x_2 + x_3 − 2 = 0\]</span> Square the expression: <span class="math display">\[(x_1 + x_2 + x_3 − 2)^2\]</span></p>
<p><strong>Ising:</strong> Following the same method, we can rewrite our constraint as follows. <span class="math display">\[(s_1 + s_2 + s_3 − 1)^2\]</span></p>
<h5 data-number="1.0.1.1.4" id="step-4-combine-expressions"><span class="header-section-number">1.0.1.1.4</span> Step 4: Combine Expressions</h5>
<p>Now that we have written our objective and constraint in BQM form, we can combine them together to make our final model using addition and adding in a Lagrange parameter. Both of these can be expanded and simplified to prepare for input to an Ocean python program.</p>
<p><strong>QUBO:</strong> <br /><span class="math display"><em>m</em><em>i</em><em>n</em>((15<em>x</em><sub>1</sub>+20<em>x</em><sub>2</sub>+25<em>x</em><sub>3</sub>)+<em>γ</em>(<em>x</em><sub>1</sub>+<em>x</em><sub>2</sub>+<em>x</em><sub>3</sub>−2)<sup>2</sup>)</span><br /></p>
<p><strong>QUBO:</strong> <span class="math display">\[
min \left (
(15 x_1 + 20 x_2 + 25 x_3) +
γ (x_1 + x_2 + x_3 − 2)^2
\right )
\]</span></p>
<p><strong>Ising:</strong></p>
<p><br /><span class="math display">$$
<p><span class="math display">\[
min \left (
15 \left ( \frac{s_1 + 1}{2} \right ) +
20 \left ( \frac{s_2 + 1}{2} \right ) +
25 \left ( \frac{s_3 + 1}{2} \right ) +
γ (s_1 + s_2 + s_3 − 1)^2
\right )
$$</span><br /></p>
\]</span></p>
</details>
<p>Also see: <a href="https://github.com/dwave-training/choosing-boxes">https://github.com/dwave-training/choosing-boxes</a></p>
<h3 id="code">Code</h3>
<h3 data-number="1.0.2" id="code"><span class="header-section-number">1.0.2</span> Code</h3>
<p>The code for the problem is in <code>choosing_boxes.ipynb</code> <!-- [choosing_boxes.ipynb](choosing_boxes_problem/choosing_boxes.ipynb) --> which can be viewed at <a href="https://nbviewer.org/github/klezm/QuantumAnnealingPlayground/blob/main/choosing_boxes_problem/choosing_boxes.ipynb">nbviewer.org</a> or opened in the <a href="https://ide.dwavesys.io/#https://github.com/klezm/QuantumAnnealingPlayground">D-Wave Leap IDE</a></p>
<h3 id="visualization">Visualization</h3>
<h3 data-number="1.0.3" id="visualization"><span class="header-section-number">1.0.3</span> Visualization</h3>
<p>The eigenspectrum and eigenvector for this problem are visualized for different Lagrange multipliers γ:</p>
<table>
<colgroup>
Expand Down Expand Up @@ -253,15 +274,16 @@ <h3 id="visualization">Visualization</h3>
<li><a href="https://klezm.github.io/QuantumAnnealingPlayground/choosing_boxes_problem/results/choosing-boxes-4-eigenvectors-dt50.html">choosing-boxes-4-eigenvectors-dt50</a></li>
</ul></li>
</ul>
<h2 id="sitemap-markdowns">Sitemap Markdowns</h2>
<h2 data-number="1.1" id="sitemap-markdowns"><span class="header-section-number">1.1</span> Sitemap Markdowns</h2>
<ul>
<li><a href="README.md">README.md</a></li>
</ul>
<h2 id="sitemap-htmls">Sitemap HTMLs</h2>
<h2 data-number="1.2" id="sitemap-htmls"><span class="header-section-number">1.2</span> Sitemap HTMLs</h2>
<ul>
<li>.
<ul>
<li><a href="choosing_boxes.html">choosing_boxes.ipynb</a></li>
<li><a href="index.html">index</a></li>
</ul></li>
<li>results
<ul>
Expand Down
24 changes: 20 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<link rel="stylesheet" href="styling.css" />
</head>
<body>
<h1 id="quantumannealingplayground">QuantumAnnealingPlayground</h1>
<h2 id="contents">Contents</h2>
<nav id="TOC" role="doc-toc">
<ul>
<li><a href="#quantumannealingplayground"><span class="toc-section-number">1</span> QuantumAnnealingPlayground</a>
<ul>
<li><a href="#contents"><span class="toc-section-number">1.1</span> Contents</a></li>
<li><a href="#sitemap-markdowns"><span class="toc-section-number">1.2</span> Sitemap Markdowns</a></li>
<li><a href="#sitemap-htmls"><span class="toc-section-number">1.3</span> Sitemap HTMLs</a></li>
</ul></li>
</ul>
</nav>
<h1 data-number="1" id="quantumannealingplayground"><span class="header-section-number">1</span> QuantumAnnealingPlayground</h1>
<h2 data-number="1.1" id="contents"><span class="header-section-number">1.1</span> Contents</h2>
<ul>
<li><a href="choosing_boxes_problem">choosing_boxes_problem</a>
<ul>
Expand All @@ -27,16 +38,21 @@ <h2 id="contents">Contents</h2>
<li>Code for experimenting with the D-Wave system</li>
</ul></li>
</ul>
<h2 id="sitemap-markdowns">Sitemap Markdowns</h2>
<h2 data-number="1.2" id="sitemap-markdowns"><span class="header-section-number">1.2</span> Sitemap Markdowns</h2>
<ul>
<li><a href="README.md">README.md</a></li>
<li><a href="choosing_boxes_problem/README.md">choosing_boxes_problem/README.md</a></li>
</ul>
<h2 id="sitemap-htmls">Sitemap HTMLs</h2>
<h2 data-number="1.3" id="sitemap-htmls"><span class="header-section-number">1.3</span> Sitemap HTMLs</h2>
<ul>
<li>.
<ul>
<li><a href="index.html">index</a></li>
</ul></li>
<li>choosing_boxes_problem
<ul>
<li><a href="choosing_boxes_problem/choosing_boxes.html">choosing_boxes.ipynb</a></li>
<li><a href="choosing_boxes_problem/index.html">index</a></li>
</ul></li>
<li>choosing_boxes_problem/results
<ul>
Expand Down
7 changes: 7 additions & 0 deletions styling.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.18.0</center>
</body>
</html>

0 comments on commit f70491c

Please sign in to comment.