{ "cells": [ { "cell_type": "markdown", "source": [ "For better rendering of the DataFrames [view this notebook on nbviewer.org](https://nbviewer.org/github/klezm/QuantumAnnealingPlayground/blob/main/choosing_boxes_problem/choosing_boxes.ipynb)\n", "or [open it on the D-Wave Leap IDE](https://ide.dwavesys.io/#https://github.com/klezm/QuantumAnnealingPlayground)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "import dimod\n", "\n", "try:\n", " dimod.ExactCQMSolver\n", "except:\n", " !pip install -U dwave-ocean-sdk dimod\n", " # !pip install pandas numpy sympy matplotlib tabulate\n", " import os\n", " os._exit(0) # restarts the ipython kernel" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Choosing Boxes Problem" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "as shown in the [problem formulation guide (chapt. 4.4)](https://www.dwavesys.com/media/bu0lh5ee/problem-formulation-guide-2022-01-10.pdf).\n", "\n", "\n", "- https://github.com/dwave-training/choosing-boxes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem\n", "\n", "Pick 2 Boxes and minimize the summed weight.\n", "\n", "| Box | Weight |\n", "| ----- | ------ |\n", "| $x_1$ | 15 |\n", "| $x_2$ | 20 |\n", "| $x_3$ | 25 |\n", "\n", "QUBO: \n", "\n", "$$\n", "\\begin{align*}\n", "\\text{Objective:}\\quad & min(15x_1 + 20x_2 + 25x_3) \\\\\n", "\\text{Constraint:}\\quad & x_1 + x_2 + x_3 = 2\n", "\\end{align*}\n", "$$\n", "\n", "## Mathematical formulation\n", "\n", "For $\\gamma = 1$ (Lagrange Multiplier)\n", "\n", "$$\n", "\\begin{align}\n", " & min\n", " (\n", " (15x_1 + 20x_2 + 25x_3)\n", "\n", " +\\gamma\n", " {\n", " \\underbrace{\n", " (x_1+x_2+x_3-2)^2\n", " }_{\n", " \\underbrace{\n", " x_1^2 \n", " - 4 x_1 \n", " + x_2^2 \n", " - 4 x_2 \n", " + x_3^2 \n", " - 4 x_3 \n", "\n", " + 2 x_1 x_2\n", " + 2 x_1 x_3 \n", " + 2 x_2 x_3 \n", "\n", " + 4\n", " }_{\n", " - 3x_1 - 3x_2 - 3x_3\n", " + 2x_1x_2 + 2x_1x_3 + 2x_2x_3\n", " + 4\n", " \\quad\n", " (x_i^2 = x_i \\ \\text{with} \\ x_i \\in \\{0,1\\})\n", " }\n", " }\n", " }\n", " ) \\\\\n", "\n", " & = min\n", " \\left(\n", " 15x_1\n", " - 3x_1\n", " + 20x_2\n", " - 3x_2\n", " + 25x_3\n", " - 3x_3\n", " + 2x_1x_2\n", " + 2x_1x_3\n", " + 2x_2x_3\n", " + 4\n", " \\right) \\\\ \n", "\n", " & = min\n", " \\left(\n", " \\underbrace{\n", " 12x_1\n", " + 17x_2\n", " + 22x_3\n", " }_{\\text{linear terms}}\n", " +\n", " \\underbrace{\n", " 2x_1x_2\n", " + 2x_1x_3\n", " + 2x_2x_3\n", " }_{\\text{quadratic terms}}\n", " + 4\n", " \\right) \\\\\n", "\n", " & \\Rightarrow\n", " Q = \n", " \\left(\n", " \\begin{matrix}\n", " 12 & 2 & 2 \\\\\n", " & 17 & 2 \\\\\n", " & & 22 \\\\\n", " \\end{matrix}\n", " \\right)\n", "\\end{align}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Content\n", "\n", "1. [BQM & CQM](#BQM-%26-CQM) - Just passing the QUBO to a solver and let it do the rest\n", " 1. [Lagrange Multiplier (γ) Comparison](#Lagrange-Multiplier-%28%CE%B3%29-Comparison) - How does γ effect the QUBO?\n", "2. [QUBO Matrix](#QUBO-Matrix) - Calculating the QUBO matrix from scratch and then passing it to a solver." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## BQM & CQM\n", "\n", "We can use equation (1) to build a BQM or the objective & constraint functions to build a CQM.\n", "Both can be used to solve the problem on a D-Wave QA.\n", "\n", "[D-Wave Docs: Quadratic Models](https://docs.dwavesys.com/docs/latest/c_gs_workflow.html#quadratic-models) \n", "[D-Wave Docs: Problem Parameters](https://docs.dwavesys.com/docs/latest/c_solver_problems.html#bqm)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "from IPython.display import Markdown\n", "from pprint import pprint\n", "from tabulate import tabulate\n", "\n", "# from collections import defaultdict\n", "import numpy as np\n", "import pandas as pd\n", "import sympy\n", "\n", "import dwave.system\n", "from dwave.system import DWaveSampler, EmbeddingComposite, LeapHybridCQMSampler\n", "import dimod\n", "# import dwave.inspector\n", "import networkx as nx\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "# print(\"DWAVE_API_TOKEN\" in os.environ)\n", "# print(os.environ.get(\"DWAVE_API_TOKEN\"))\n", "# # os.environ[\"DWAVE_API_TOKEN\"] = \"YOUR_API_TOKEN\"\n", "# print(os.environ.get(\"DWAVE_API_TOKEN\"))\n", "\n", "if \"DWAVE_API_TOKEN\" not in locals() or \"DWAVE_API_TOKEN\" not in os.environ:\n", " DWAVE_API_TOKEN = input(\"paste your D-Wave API token here:\")\n", " os.environ[\"DWAVE_API_TOKEN\"] = DWAVE_API_TOKEN" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def bqm2matrix(bqm: dimod.BinaryQuadraticModel) -> np.ndarray:\n", " bqm_np = bqm.to_numpy_vectors() # bqm.variables.to_serializable()\n", " bqm_m = np.diag(bqm_np.linear_biases)\n", " for ir, ic, b in zip(bqm_np.quadratic.row_indices, bqm_np.quadratic.col_indices, bqm_np.quadratic.biases):\n", " bqm_m[ir, ic] = b\n", " return bqm_m\n", "# bqm2matrix(bqm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### BQM" ] }, { "cell_type": "code", "execution_count": 283, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "BinaryQuadraticModel({'x1': -90.0, 'x2': -85.0, 'x3': -80.0}, {('x2', 'x1'): 70.0, ('x3', 'x1'): 70.0, ('x3', 'x2'): 70.0}, 140.0, 'BINARY') \n", "\n" ] } ], "source": [ "γ = 35\n", "x1 = dimod.Binary(\"x1\")\n", "x2 = dimod.Binary(\"x2\")\n", "x3 = dimod.Binary(\"x3\")\n", "\n", "bqm = 15 * x1 + 20 * x2 + 25 * x3 + γ * (x1 + x2 + x3 - 2)**2\n", "print(bqm, \"\\n\")" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAb4AAAE+CAYAAADyPXUxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABAlUlEQVR4nO3deVgV590+8PscdkRAVhEURATcEVFxBwVRWYQzmpjGJCZ5axqTNrHZaxvTNrEmJnmbX9RmN2qaaOIcQJBVFIPiEheMRgQVQUFAQBZR2c6Z3x++TkPBBQXOgXN/rit/cM7MPN+hvbh9Zub5jkKSJAlEREQGQqnrAoiIiLoTg4+IiAwKg4+IiAwKg4+IiAwKg4+IiAwKg4+IiAwKg49IBy5cuAArKytoNBpdl9KtlixZgj//+c+6LoMMHIOPut3XX3+NUaNGwdLSEv3798eyZctQW1srf9/eH8fCwkIoFAq0tLQAADw8PGBhYQErKyv069cP4eHhuHjx4h3HefbZZ1FTU3PbupYsWQKFQoH4+PhWny9fvhwKhQJff/31PZ2fh4cHdu7cecdtBg0ahPr6ehgZGd3TMbuCJElYu3YtRo8eLf+OgoKCsGXLFp3VRNQdGHzUrT744AO89tprWLNmDWpra3HgwAEUFhZi9uzZaG5u7tCxEhISUF9fj9LSUjg7O+P3v//9HccpKipCaGgompqabntMb29vbNq0Sf65paUF33//PYYMGdLxk72NW+Gta3/4wx/wz3/+Ex988AGqqqpQUlKCt99+G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2xevVqDBs27IGO19TUhE8++QTvvPMOXnrpJbzyyit689AQg4+I6AFUVlYiISEBoijixx9/xPTp06FSqTB//nzY29vrurx7snfvXixYsAB//etf8cwzz3TqsYuLixEZGYmxY8fi888/14v7fww+IqJOUltbix07dkCtViM9PR3jx4+XW6e5uLjourx2nT9/HoGBgdi0aRPCwsK6ZIxr164hMjISgYGBWLVqVZeM0REMPiKiLnD9+nWkpKRAFEUkJSVhxIgR8oJ5d3d3XZcH4Oai/sDAQDz++ON44YUXunSsiooKBAQEYP369QgPD+/Sse6GwUdE1MUaGxuxc+dOqNVqxMfHY/DgwXIIent766yuzZs344svvkBmZma33H9LSUnByy+/jJ9//lmn6yMZfERE3ailpQV79uyBKIqIjY2Fg4OD3DVm5MiR3fYAiCRJGDlyJP75z38iNDS028YcP3483nzzTURFRXXLmO1h8BER6YhWq8X+/fvltYImJiZyCAYEBHRpCJ47dw7Tp09HcXFxtz5tuXbtWhw/fhyff/55t43539iLh4hIR5RKJaZMmYIPP/wQ58+fx5YtW6BUKrF48WK4u7vjxRdfRFZWFjQaTaePnZ2djSlTpnT7EoPJkycjOzu7W8f8bww+IiI9oFAoMG7cOKxatQqnT59GUlIS+vXrh+effx6urq549tlnkZ6ejubm5k4Zr6SkBIMHD+6UY3WEp6cniouLu33cX2PwERHpGYVCgZEjR2LlypU4fvw4srKy4OHhgRUrVsDFxQVPPvkkEhMT0djY+MDjdDd9WMTO4CMi0nNDhw7Fa6+9hkOHDuHo0aPw8/PDe++9B2dnZzzyyCPYtm0brl271qFj2traory8vIsqvr3y8nL069ev28f9tR7xcEt+fn67j/zy4RYiMmRlZWWIj4+HKIo4ePAgZs2aBZVKhcjISNjY2Nxx3+PHj+Phhx/G6dOn73m8yvpGbDtSjNNldahraIG1uTF8+1tj4Tg32FvdWz/PjRs3IjU1Fd9+++09j9vZ9Cb4rl+/fttGr2PHjsWxY8fafM7gIyK66cqVK9i+fTtEUcSePXswdepUCIKAqKgoODo6ttleo9HA1dUV6enpd20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/fRuP4LBwWJubwNelLxb43/sb2ImIyHB1W/A9//zziIqKwoABA3D16lVs3boVSqUSJSUlGDhwoLydm5sbSkpK2uxfXl4OFxcXAMDL4X54Z3Ewvvz2re4qn4iIeoluu8eXmpoKPz8/XLp0CTk5OXj++edRV1d3X8dSKBTy29OJiIg6okuDb926dfDz84Ofnx/WrVsHlUoFhUIBLy8vDB48GKdPn4arqysuXrwo71NcXAxXV9c2x3J2dkZpaSmAm29Sd3Jy6srSiYiol+rS4HvuueeQk5ODnJwc+Pr6IiMjA8DNy5Z5eXnw9PREWFgY0tLSUF1djerqaqSlpSEsLKzNsaKiouQnPjdu3Ij58+d3ZelERNRLddtTnZcuXcKSJUtQWloKSZLw+uuvY/HixQCAr776CqtWrQIArFixAk8++SQA4H/+53/wu9/9DgEBAaiqqsJDDz2ECxcuwN3dHd9//738QAwREdG90ttenURERF1Brzu3EBERdTYGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGRQGHxERGZT/D3x1akbsOEhmAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "array([[-90., 70., 70.],\n", " [ 70., -85., 70.],\n", " [ 70., 70., -80.]])" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# G = bqm.to_networkx_graph()\n", "# nx.draw_networkx(G)\n", "\n", "# G = nx.from_numpy_matrix(bqm.to_numpy_matrix(bqm.variables.to_serializable()))\n", "G = nx.from_numpy_matrix(bqm2matrix(bqm))\n", "\n", "pos = nx.circular_layout(G)\n", "pos_labels = {k: v * 1.1 for k, v in pos.items()}\n", "\n", "nx.draw(G, pos, with_labels = True)\n", "nx.draw_networkx_edge_labels(\n", " G,\n", " pos_labels,\n", " # edge_labels = {e: G.edges[e][\"bias\"] for e in G.edges},\n", " edge_labels = {e: G.edges[e][\"weight\"] for e in G.edges},\n", ")\n", "plt.title(\"QUBO Matrix as Graph\")\n", "plt.show()\n", "\n", "nx.to_numpy_array(G)" ] }, { "cell_type": "code", "execution_count": 289, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
x1x2x3chain_break_fractionenergynum_occurrencesenergy_no_offset
01100.035.078-105.0
11010.040.015-100.0
20110.045.06-95.0
31000.050.01-90.0
\n", "
" ], "text/plain": [ " x1 x2 x3 chain_break_fraction energy num_occurrences energy_no_offset\n", "0 1 1 0 0.0 35.0 78 -105.0\n", "1 1 0 1 0.0 40.0 15 -100.0\n", "2 0 1 1 0.0 45.0 6 -95.0\n", "3 1 0 0 0.0 50.0 1 -90.0" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "['BINARY', 4 rows, 100 samples, 3 variables]\n" ] } ], "source": [ "sampler_bqm = EmbeddingComposite(DWaveSampler()) # token = DWAVE_API_TOKEN\n", "sampleset_bqm = sampler_bqm.sample(bqm, num_reads = 100, label = f'Choosing Boxes BQM (γ = {γ})')\n", "\n", "sampleset_bqm_df = sampleset_bqm.to_pandas_dataframe()\n", "# Reintroduce the offset to get the \"real\" energies (not the scaled ones)\n", "sampleset_bqm_df[\"energy_no_offset\"] = sampleset_bqm_df.energy - bqm.offset\n", "\n", "display(sampleset_bqm_df.sort_values(by = \"energy\"))\n", "print(str(sampleset_bqm).splitlines()[-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Exact Solver" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "γ = 60\n", "x1, x2, x3 = [dimod.Binary(f'x{i}') for i in range(1, 4)]\n", "bqm = 15 * x1 + 20 * x2 + 25 * x3 + γ * (x1 + x2 + x3 - 2)**2\n", "qvars = bqm.variables.to_serializable()\n", "\n", "sampleset_bqm_exact = dimod.ExactSolver().sample(bqm)\n", "# sampleset_bqm_exact = dimod.ExactDQMSolver().sample_dqm(bqm)\n", "# sampleset_bqm_exact = dimod.ExactPolySolver().sample(bqm)\n", "\n", "sampleset_bqm_exact_df = sampleset_bqm_exact.to_pandas_dataframe().assign(constraint_satisfied = lambda r: r.loc[:, qvars].sum(axis = 1) == 2)\n", "display(sampleset_bqm_exact_df.sort_values(by = \"energy\"))\n", "display(sampleset_bqm_exact_df.sort_values(by = qvars))\n", "print(str(sampleset_bqm_exact).splitlines()[-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Eigenvalues Visualization" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def scale_cmap_log(cmap = plt.cm.gist_ncar, plot = False) -> plt.matplotlib.colors.LinearSegmentedColormap:\n", " \"\"\"\n", " Scales a colormap logarithmically.\n", " \"\"\"\n", " n = 10000 # number of samples from original colormap\n", " logs = np.geomspace(1, 256 + 1, n, dtype = int) - 1\n", "\n", " log_colors = [cmap(i) for i in range(n)]\n", " log_colors = [log_colors[i] for i in logs]\n", "\n", " cmap_log = cmap.from_list(cmap.name + \"_log\", log_colors, len(log_colors))\n", "\n", " if plot:\n", " plt.imshow([np.linspace(0, 1, 256)] , aspect = \"auto\", cmap = cmap_log)\n", " plt.gcf().set_size_inches(8.5, .5)\n", " plt.title(\"Logarithmic Colormap\")\n", " plt.gca().yaxis.set_visible(False)\n", " plt.show()\n", " return cmap_log" ] }, { "cell_type": "code", "execution_count": 556, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAewAAABKCAYAAAB5GGcnAAAAOXRFWHRTb2Z0d2FyZQB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9eXt5RIzNQrer7FeB9wBPSNqQyz6Cx/hMahXzC3o5zv1NZ2ZmZhXgh87MzMwqwAnbzMysApywzczMKsAJ28zMrAKcsM3MzCrACdvMzKwCnLDNzMwqwAnbzMysAv4fKBPCnf2096gAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
γ262728293031323334
x1x2x3energynum_occurrencesconstraint_satisfiedenergyenergyenergyenergyenergyenergyenergyenergy
2110-6911-73-77-81-85-89-93-97-101
6101-6411-68-72-76-80-84-88-92-96
1100-6310-66-69-72-75-78-81-84-87
4011-5911-63-67-71-75-79-83-87-91
3010-5810-61-64-67-70-73-76-79-82
7001-5310-56-59-62-65-68-71-74-77
5111-1810-21-24-27-30-33-36-39-42
000001000000000
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "Here we can see ... TODO " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
energy @γ = 26γ = 27γ = 28γ = 29γ = 30γ = 31γ = 32γ = 33γ = 34
solution set         
2-69-73-77-81-85-89-93-97-101
6-64-68-72-76-80-84-88-92-96
1-63-66-69-72-75-78-81-84-87
4-59-63-67-71-75-79-83-87-91
3-58-61-64-67-70-73-76-79-82
7-53-56-59-62-65-68-71-74-77
5-18-21-24-27-30-33-36-39-42
0000000000
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dfs = []\n", "for γ in range(26, 35):\n", " x1, x2, x3 = [dimod.Binary(f'x{i}') for i in range(1, 4)]\n", " bqm = 15 * x1 + 20 * x2 + 25 * x3 + γ * (x1 + x2 + x3 - 2)**2\n", " qvars = bqm.variables.to_serializable()\n", "\n", " sampleset_bqm_exact = dimod.ExactSolver().sample(bqm)\n", "\n", " sampleset_bqm_exact_df = sampleset_bqm_exact.to_pandas_dataframe().assign(constraint_satisfied = lambda r: r.loc[:, qvars].sum(axis = 1) == 2)\n", "\n", " if True: # Reintroduce the offset to get the \"real\" energies (not the scaled ones)\n", " sampleset_bqm_exact_df.energy -= bqm.offset\n", " # print(bqm.energies((dimod.reference.samplers.exact_solver._graycode(bqm), list(bqm.variables))) - bqm.offset)\n", "\n", " dfs.append([γ, sampleset_bqm_exact_df.sort_values(by = \"energy\")])\n", "\n", "# display(pd.concat([x[1] for x in dfs], axis = 1, ).T.reset_index().set_index(\"index\", append = True).T.style.background_gradient(subset = [(i, \"energy\") for i in [3, 9, 15]], cmap = \"RdBu_r\"))\n", "# pprint(df.columns.get_locs([slice(None), \"energy\"]))\n", "# pprint(df.columns.get_loc_level(\"energy\", 1, drop_level = False)[1])\n", "display(\n", " pd.concat(\n", " [x[1] for x in dfs],\n", " keys = [x[0] for x in dfs],\n", " axis = 1\n", " ).T.drop_duplicates(\n", " ).T.astype(\n", " int\n", " ).rename_axis(\n", " columns = [\"γ\", \"\"],\n", " ).style.background_gradient(\n", " subset = pd.IndexSlice[:, pd.IndexSlice[:, \"energy\"]],\n", " cmap = scale_cmap_log(plt.cm.gist_ncar, True).reversed(),\n", " )\n", ")\n", "\n", "display(Markdown(\"Here we can see ... TODO \"))\n", "\n", "display(pd.concat(\n", " [x.energy.rename(index = f'γ = {γ}') for γ, x in dfs],\n", " axis = 1\n", " ).rename_axis(\n", " index = \"solution set\",\n", " columns = \"energy @\",\n", " ).astype(\n", " int\n", " ).style.background_gradient(\n", " axis = None,\n", " cmap = scale_cmap_log(plt.cm.gist_ncar).reversed(),\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": 558, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
energy @γ = 26γ = 27γ = 28γ = 29γ = 30γ = 31γ = 32γ = 33γ = 34
solution set         
2353535353535353535
6404040404040404040
1414243444546474849
4454545454545454545
3464748495051525354
7515253545556575859
5868788899091929394
0104108112116120124128132136
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Here: with added offset\n", "\n", " # Reintroduce the offset to get the \"real\" energies (not the scaled ones)\n", " # sampleset_bqm_exact_df.energy -= bqm.offset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### CQM\n", "\n", "CQM can be used with the `LeapHybridCQMSampler()`.\n", "With the `ExactCQMSolver()` the problem can be solved without a QPU." ] }, { "cell_type": "code", "execution_count": 158, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
 x1x2x3energyis_feasibleis_satisfiednum_occurrences
1310015FalseFalse1
011035TrueTrue1
2111035TrueTrue1
2211035TrueTrue1
2311035TrueTrue1
2411035TrueTrue1
2511035TrueTrue1
2611035TrueTrue1
2011035TrueTrue1
2711035TrueTrue1
2911035TrueTrue1
3011035TrueTrue1
3111035TrueTrue1
3211035TrueTrue1
3311035TrueTrue1
3411035TrueTrue1
3511035TrueTrue1
2811035TrueTrue1
1911035TrueTrue1
1811035TrueTrue1
1711035TrueTrue1
111035TrueTrue1
211035TrueTrue1
311035TrueTrue1
511035TrueTrue1
711035TrueTrue1
3611035TrueTrue1
811035TrueTrue1
1011035TrueTrue1
1111035TrueTrue1
1411035TrueTrue1
1511035TrueTrue1
1611035TrueTrue1
911035TrueTrue1
3711035TrueTrue1
610140TrueTrue1
1210140TrueTrue1
401145TrueTrue1
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "['INTEGER', 38 rows, 38 samples, 3 variables]\n" ] } ], "source": [ "x1, x2, x3 = [dimod.Binary(f'x{i}') for i in range(1, 4)]\n", "\n", "cqm = dimod.ConstrainedQuadraticModel()\n", "cqm.set_objective(15 * x1 + 20 * x2 + 25 * x3)\n", "cqm.add_constraint(x1 + x2 + x3 == 2, label = \"pick exactly 2 boxes\")\n", "\n", "# pprint(vars(cqm)); print()\n", "# pprint(vars(dimod.cqm_to_bqm(cqm)[0])); print()\n", "\n", "sampler_cqm = LeapHybridCQMSampler()\n", "# print(sampler_cqm.parameters, \"\\n\")\n", "sampleset_cqm = sampler_cqm.sample_cqm(cqm, label = f'Choosing Boxes CQM (γ = {γ})')\n", "\n", "display(sampleset_cqm.to_pandas_dataframe().sort_values(by = \"energy\").convert_dtypes().style.background_gradient(subset = \"energy\"))\n", "print(str(sampleset_cqm).splitlines()[-1])" ] }, { "cell_type": "code", "execution_count": 279, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'_constraints': {'pick exactly 2 boxes': BinaryQuadraticModel({'x1': 1.0, 'x2': 1.0, 'x3': 1.0}, {}, 0.0, 'BINARY') == 2},\n", " '_discrete': set(),\n", " '_objective': QuadraticModel({'x1': 15.0, 'x2': 20.0, 'x3': 25.0}, {}, 0.0, {'x1': 'BINARY', 'x2': 'BINARY', 'x3': 'BINARY'}, dtype='float64'),\n", " '_variables': Variables(['x1', 'x2', 'x3']),\n", " 'discrete': set()}\n", "cqm.check_feasible(sampleset_cqm.first.sample) = False\n", "[ConstraintData(label='pick exactly 2 boxes', lhs_energy=1.0, rhs_energy=2, sense=, activity=-1.0, violation=1.0)]\n", "[('pick exactly 2 boxes', 1.0)]\n", "cqm.num_biases() = 6\n", "cqm.num_quadratic_variables() = 0\n", "{'pick exactly 2 boxes': 1.0}\n", "{'charge_time': 4991796,\n", " 'constraint_labels': ['pick exactly 2 boxes'],\n", " 'problem_id': 'b5c2fa2a-123c-4427-ab7d-ab890408d414',\n", " 'qpu_access_time': 8529,\n", " 'run_time': 4991796}\n", "(BinaryQuadraticModel({'x1': -735.0, 'x2': -730.0, 'x3': -725.0}, {('x2', 'x1'): 500.0, ('x3', 'x1'): 500.0, ('x3', 'x2'): 500.0}, 1000.0, 'BINARY'),\n", " )\n" ] } ], "source": [ "# pprint(vars(cqm)) # pprint(cqm.objective); print(cqm.constraints); pprint(cqm.discrete); pprint(cqm.variables)\n", "# print(f'{cqm.check_feasible(sampleset_cqm.first.sample) = }')\n", "# # for sample in sampleset_cqm.samples(): print(f'{cqm.check_feasible(sample) = }')\n", "# pprint(list(cqm.iter_constraint_data(sampleset_cqm.first.sample)))\n", "# # for sample in sampleset_cqm.samples(): pprint(list(cqm.iter_constraint_data(sample)))\n", "# pprint(list(cqm.iter_violations(sampleset_cqm.first.sample)))\n", "# # for sample in sampleset_cqm.samples(): pprint(list(cqm.iter_violations(sample)))\n", "# print(f'{cqm.num_biases() = }')\n", "# print(f'{cqm.num_quadratic_variables() = }')\n", "# pprint(cqm.violations(sampleset_cqm.first.sample))\n", "# # for sample in sampleset_cqm.samples(): pprint(cqm.violations(sample))\n", "\n", "# pprint(sampleset_cqm.info)\n", "# sampleset_cqm.record\n", "# list(sampleset_cqm.samples())\n", "# dimod.as_samples(sampleset_cqm)\n", "# pprint(dimod.cqm_to_bqm(cqm))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Exact CQM Solver" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'_linear': {'x1': -735.0, 'x2': -730.0, 'x3': -725.0},\n", " 'data': ,\n", " 'get_linear': ,\n", " 'reduce_linear': }\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
x1x2x3energyis_feasibleis_satisfiednum_occurrences
00000.0FalseFalse1
210015.0FalseFalse1
101020.0FalseFalse1
400125.0FalseFalse1
311035.0TrueTrue1
610140.0TrueTrue1
501145.0TrueTrue1
711160.0FalseFalse1
\n", "
" ], "text/plain": [ " x1 x2 x3 energy is_feasible is_satisfied num_occurrences\n", "0 0 0 0 0.0 False False 1\n", "2 1 0 0 15.0 False False 1\n", "1 0 1 0 20.0 False False 1\n", "4 0 0 1 25.0 False False 1\n", "3 1 1 0 35.0 True True 1\n", "6 1 0 1 40.0 True True 1\n", "5 0 1 1 45.0 True True 1\n", "7 1 1 1 60.0 False False 1" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
x1x2x3energyis_feasibleis_satisfiednum_occurrences
00000.0FalseFalse1
400125.0FalseFalse1
101020.0FalseFalse1
501145.0TrueTrue1
210015.0FalseFalse1
610140.0TrueTrue1
311035.0TrueTrue1
711160.0FalseFalse1
\n", "
" ], "text/plain": [ " x1 x2 x3 energy is_feasible is_satisfied num_occurrences\n", "0 0 0 0 0.0 False False 1\n", "4 0 0 1 25.0 False False 1\n", "1 0 1 0 20.0 False False 1\n", "5 0 1 1 45.0 True True 1\n", "2 1 0 0 15.0 False False 1\n", "6 1 0 1 40.0 True True 1\n", "3 1 1 0 35.0 True True 1\n", "7 1 1 1 60.0 False False 1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "['INTEGER', 8 rows, 8 samples, 3 variables]\n" ] } ], "source": [ "x1, x2, x3 = [dimod.Binary(f'x{i}') for i in range(1, 4)]\n", "# symbols = [x1, x2, x3]\n", "\n", "cqm = dimod.ConstrainedQuadraticModel()\n", "cqm.set_objective(15 * x1 + 20 * x2 + 25 * x3)\n", "cqm.add_constraint(x1 + x2 + x3 == 2, label = \"pick exactly 2 boxes\")\n", "qvars = cqm.variables.to_serializable()\n", "\n", "# pprint(vars(cqm)); print()\n", "pprint(vars(dimod.cqm_to_bqm(cqm)[0])); print()\n", "\n", "sampleset_cqm = dimod.ExactCQMSolver().sample_cqm(cqm)\n", "\n", "# print(sampleset_cqm)\n", "# print(sampleset_cqm.to_pandas_dataframe().to_string())\n", "display(sampleset_cqm.to_pandas_dataframe().sort_values(by = \"energy\"))\n", "display(sampleset_cqm.to_pandas_dataframe().sort_values(by = qvars))\n", "print(str(sampleset_cqm).splitlines()[-1])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'_constraints': {'pick exactly 2 boxes': BinaryQuadraticModel({'x1': 1.0, 'x2': 1.0, 'x3': 1.0}, {}, 0.0, 'BINARY') == 2},\n", " '_discrete': set(),\n", " '_objective': QuadraticModel({'x1': 15.0, 'x2': 20.0, 'x3': 25.0}, {}, 0.0, {'x1': 'BINARY', 'x2': 'BINARY', 'x3': 'BINARY'}, dtype='float64'),\n", " '_variables': Variables(['x1', 'x2', 'x3']),\n", " 'discrete': set()}\n", "\n", "{'_linear': {'x1': -735.0, 'x2': -730.0, 'x3': -725.0},\n", " 'data': ,\n", " 'get_linear': ,\n", " 'reduce_linear': }\n", "\n", " x1 x2 x3 energy num_oc. is_sat. is_fea.\n", "0 0 0 0 0.0 1 arra... False\n", "2 1 0 0 15.0 1 arra... False\n", "1 0 1 0 20.0 1 arra... False\n", "4 0 0 1 25.0 1 arra... False\n", "3 1 1 0 35.0 1 arra... True\n", "6 1 0 1 40.0 1 arra... True\n", "5 0 1 1 45.0 1 arra... True\n", "7 1 1 1 60.0 1 arra... False\n", "['INTEGER', 8 rows, 8 samples, 3 variables]\n" ] } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Lagrange Multiplier (γ) Comparison\n", "\n", "Comparison of different values for the Lagrange Multiplier.\n", "\n", "The [D-Wave \"Problem Formulation Guide\"](https://www.dwavesys.com/media/bu0lh5ee/problem-formulation-guide-2022-01-10.pdf) suggests in chapter 4.3.4:\n", "> Note that you may need to try a few different values to identify the best Lagrange parameter value for your specific BQM.\n", "> **A good starting value is to set γ equal to your best estimate of the value of your objective function.**\n", "> If you find that your constraints are not satisfied in the solutions returned, you may need to increase γ. \n", "> On the other hand, if your constraints are all satisfied but your solutions are not close to optimal, you may need to decrease γ.\n", "\n", "In our problem we see that the optimal solution would be to pick box 1 & 2 with a weight of 35, which we can pick as the \"best estimate\" for γ." ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ">>> γ = 1 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 0 0 0 4.0 100 0.0\n", "['BINARY', 1 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 10 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 0 0 25.0 94 0.0\n", "1 0 1 0 30.0 6 0.0\n", "['BINARY', 2 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 20 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 0 0 35.0 51 0.0\n", "1 1 1 0 35.0 42 0.0\n", "2 0 1 0 40.0 1 0.0\n", "3 1 0 1 40.0 6 0.0\n", "['BINARY', 4 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 30 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 72 0.0\n", "1 1 0 1 40.0 17 0.0\n", "2 1 0 0 45.0 6 0.0\n", "3 0 1 1 45.0 3 0.0\n", "4 0 1 0 50.0 2 0.0\n", "['BINARY', 5 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 35 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 59 0.0\n", "1 1 0 1 40.0 24 0.0\n", "2 0 1 1 45.0 12 0.0\n", "3 1 0 0 50.0 4 0.0\n", "4 0 1 0 55.0 1 0.0\n", "['BINARY', 5 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 40 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 55 0.0\n", "1 1 0 1 40.0 40 0.0\n", "2 0 1 1 45.0 4 0.0\n", "3 1 0 0 55.0 1 0.0\n", "['BINARY', 4 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 60 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 51 0.0\n", "1 1 0 1 40.0 31 0.0\n", "2 0 1 1 45.0 18 0.0\n", "['BINARY', 3 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 80 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 56 0.0\n", "1 1 0 1 40.0 30 0.0\n", "2 0 1 1 45.0 14 0.0\n", "['BINARY', 3 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 100 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 48 0.0\n", "1 1 0 1 40.0 29 0.0\n", "2 0 1 1 45.0 23 0.0\n", "['BINARY', 3 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 120 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 36 0.0\n", "1 1 0 1 40.0 39 0.0\n", "2 0 1 1 45.0 25 0.0\n", "['BINARY', 3 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 150 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 37 0.0\n", "1 1 0 1 40.0 31 0.0\n", "2 0 1 1 45.0 32 0.0\n", "['BINARY', 3 rows, 100 samples, 3 variables]\n", "\n", ">>> γ = 200 <<<\n", " x1 x2 x3 energy num_oc. chain_.\n", "0 1 1 0 35.0 41 0.0\n", "1 1 0 1 40.0 19 0.0\n", "2 0 1 1 45.0 40 0.0\n", "['BINARY', 3 rows, 100 samples, 3 variables]\n", "\n" ] } ], "source": [ "samplesets = {}\n", "for γ in [1, 10, 20, 30, 35, 40, 60, 80, 100, 120, 150, 200]:\n", " sampler = EmbeddingComposite(DWaveSampler())\n", "\n", " x1, x2, x3 = [dimod.Binary(f'x{i}') for i in range(1, 4)]\n", " bqm = 15 * x1 + 20 * x2 + 25 * x3 + γ * (x1 + x2 + x3 - 2)**2\n", " # Q = make_Q_dict(make_qubo(γ = γ))\n", "\n", " sampleset = sampler.sample(bqm, num_reads = 100, label = f'Choosing Boxes (γ = {γ})')\n", " # sampleset = sampler.sample_qubo(Q, num_reads = 100)\n", "\n", " print(f'{sampleset}\\t\\twith\\tγ = {γ}\\n')\n", " samplesets[γ] = sampleset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following DataFrame the results of the sampleset with differen $\\gamma$ are shown.\n", "\n", "We see that for $\\gamma = 1$ and $\\gamma = 10$ no satisfying solution were found.\n", "We should have picked 2 boxes (not just 1 or even 0).\n", "Therefore we should pick a higher Lagrange Multiplier to give the constraint more weight.\n", "\n", "For $\\gamma = 35$ we find combinations for picking 1 or 2 Boxes.\n", "First all solutions where 2 boxes were picked with the weight in descending order and then the same for cases where only one box was picked.\n", "\n", "For very high $\\gamma$ we see that the constraint has \"enough\" weight, so no solutions violating the constraint have been found." ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
  x1x2x3chain_break_fractionenergynum_occurrencesresult#picked
γ#        
100000410000
10010002594151
10100306201
20010003551151
111003542352
20100401201
31010406402
30011003572352
110104017402
21000456151
30110453452
40100502201
35011003559352
110104024402
201104512452
31000504151
40100551201
40011003555352
110104040402
20110454452
31000551151
60011003551352
110104031402
201104518452
80011003556352
110104030402
201104514452
100011003548352
110104029402
201104523452
120011003536352
110104039402
201104525452
150011003537352
110104031402
201104532452
200011003541352
110104019402
201104540452
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = pd.concat({γ: s.to_pandas_dataframe() for γ, s in samplesets.items()}).rename_axis(index = [\"γ\", \"#\"])\n", "df = df.convert_dtypes()\n", "df = df.rename(columns = {0: \"x1\", 1: \"x2\", 2: \"x3\"})\n", "\n", "# df[\"result\"] = (df[0].astype(str) + df[1].astype(str) + df[2].astype(str)).apply(lambda x: int(f'0b{x}', 2))\n", "df[\"result\"] = df[\"x1\"] * 15 + df[\"x2\"] * 20 + df[\"x3\"] * 25 # summed weight\n", "df[\"#picked\"] = df[\"x1\"] + df[\"x2\"] + df[\"x3\"] # number of picked boxes (constraint)\n", "\n", "# display(df.style.bar(subset = [\"energy\", \"num_occurrences\"]).background_gradient(subset = \"result\", cmap = \"Blues_r\").background_gradient(subset = \"#picked\"))\n", "display(\n", " df.style.bar(\n", " subset = [\"chain_break_fraction\", \"energy\", \"num_occurrences\"],\n", " color = \"#ff92a585\",\n", " ).set_properties(\n", " **{\"background-color\": \"#adadad69\"}, # #004ba752\n", " subset = pd.IndexSlice[pd.IndexSlice[df.index.unique(level = 0)[::2], :], :]\n", " ).background_gradient(\n", " subset = \"result\",\n", " cmap = \"Blues_r\"\n", " ).set_properties(\n", " subset = \"#picked\",\n", " **{\"font-weight\": \"bold\"}\n", " ).text_gradient(\n", " subset = \"#picked\",\n", " cmap = \"tab10\"\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Some not very helpful plots :D\n", "\n", "\n", "df2 = df.T.stack()\n", "\n", "# df2.drop(columns = [0, 1, 2, \"#\"]).groupby(by = \"γ\").plot()\n", "# df2.loc[[\"energy\", \"num_occurrences\"]].plot()\n", "df2.loc[[\"num_occurrences\"]].plot();\n", "df2.loc[[\"energy\", ]].plot();\n", "# df2.loc[[\"chain_break_fraction\", ]].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## QUBO Matrix\n", "\n", "Here we repeat the calculation from above, but we use `sympy` to create the QUBO matrix ourselves." ] }, { "cell_type": "code", "execution_count": 256, "metadata": {}, "outputs": [], "source": [ "# σx = np.array([[0, 1],\n", "# [1, 0]])\n", "# σy = np.array([[0, -1j],\n", "# [1j, 0]])\n", "# σz = np.array([[1, 0],\n", "# [0, -1]])" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [], "source": [ "def make_Q(qubo: sympy.Expr) -> np.ndarray:\n", " \"\"\"\n", " takes a QUBO sympy expression and returns the QUBO matrix.\n", " \"\"\"\n", " qubo = sympy.cancel(qubo) # simplified\n", " symbols = qubo.free_symbols\n", " qubo = qubo.subs({x ** 2: x for x in symbols}) # x_i^2 = x_i with x_i ∈ {0,1}\n", " qubo = qubo.as_poly()\n", " qubo_dict = qubo.as_dict()\n", " qubo_dict = sorted(tuple(qubo_dict.items()), reverse = True)\n", " num_vars = len(symbols)\n", " Q = np.zeros((num_vars, num_vars), dtype = int)\n", "\n", " def group_rows(qubo: dict):\n", " rows = {}\n", " for i in range(num_vars):\n", " row = [(coord, coef) for ix, (coord, coef) in enumerate(qubo) if coord[i] == 1]\n", " rows[i] = row\n", " for elem in row:\n", " qubo.remove(elem)\n", " rows = {k: {\"linear\": [e for e in v if sum(e[0]) == 1], \"quadratic\": [e for e in v if sum(e[0]) > 1]} for k, v in rows.items()}\n", " return rows\n", " rows = group_rows(qubo_dict)\n", "\n", " def fill_Q(rows, Q):\n", " for ir, row in rows.items():\n", " for (ic, col) in row[\"quadratic\"]:\n", " Q[(ir, ic.index(1, ir + 1))] = col\n", " for (ic, col) in row[\"linear\"]:\n", " Q[(ir, ir)] = col\n", " return Q\n", " Q = fill_Q(rows, Q)\n", "\n", " return Q\n", "\n", "\n", "# make_Q(sympy.cancel(15 * sympy.Symbol(\"x1\") + 20 * sympy.Symbol(\"x2\") + 25 * sympy.Symbol(\"x3\") + 1 * (sympy.Symbol(\"x1\") + sympy.Symbol(\"x2\") + sympy.Symbol(\"x3\") - 2)**2))" ] }, { "cell_type": "code", "execution_count": 95, "metadata": {}, "outputs": [], "source": [ "def make_qubo(γ = 35, verbose = False) -> np.ndarray:\n", " \"\"\"\n", " make QUBO for the choosing boxes problem:\n", " min(15a + 20b + 25c + γ * (a + b + c - 2)^2)\n", "\n", " Args:\n", " γ: int or list of ints ( in the latter case the outputs for all will be printed and the last one returned)\n", " \"\"\"\n", " γs = γ if isinstance(γ, list) else [γ]\n", " γ = γs[-1]\n", "\n", " symbols = sympy.symbols(\"x1 x2 x3\")\n", " x1, x2, x3 = symbols\n", "\n", " if verbose:\n", " print(\"QUBO:\")\n", " γ_sym = sympy.Symbol(\"γ\")\n", " display(15 * x1 + 20 * x2 + 25 * x3 + γ_sym * (x1 + x2 + x3 - 2)**2)\n", "\n", " for γ in γs:\n", " qubo = sympy.cancel(15 * x1 + 20 * x2 + 25 * x3 + γ * (x1 + x2 + x3 - 2)**2) # simplified\n", " qubo = qubo.subs({x ** 2: x for x in symbols}) # x_i^2 = x_i with x_i ∈ {0,1}\n", "\n", " Q = make_Q(qubo)\n", " if verbose:\n", " display(Markdown(f'#### Simplified QUBO with $γ = {γ}$'))\n", " display(qubo)\n", "\n", " print(tabulate(pd.DataFrame([np.array2string(m) for m in [Q, *np.linalg.eig(Q)]]).T, [\"QUBO Matrix\", \"Eigenvalues\", \"Eigenvectors\"], showindex = False))\n", "\n", " if verbose > 1:\n", " plt.imshow(Q, cmap = \"turbo\", interpolation = \"none\") #, vmin = Q[np.triu_indices_from(Q)].min())\n", " plt.axis(\"off\")\n", " plt.colorbar()\n", " plt.gcf().set_size_inches(2, 1)\n", " plt.show()\n", " return Q\n", "\n", "# Q = make_qubo(γ = [1, 35], verbose = 2)" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "QUBO:\n" ] }, { "data": { "text/latex": [ "$\\displaystyle 15 x_{1} + 20 x_{2} + 25 x_{3} + γ \\left(x_{1} + x_{2} + x_{3} - 2\\right)^{2}$" ], "text/plain": [ "15*x1 + 20*x2 + 25*x3 + γ*(x1 + x2 + x3 - 2)**2" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 1$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 2 x_{1} x_{2} + 2 x_{1} x_{3} + 12 x_{1} + 2 x_{2} x_{3} + 17 x_{2} + 22 x_{3} + 4$" ], "text/plain": [ "2*x1*x2 + 2*x1*x3 + 12*x1 + 2*x2*x3 + 17*x2 + 22*x3 + 4" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "------------- ------------- ------------------------------------\n", "[[12 2 2] [12. 17. 22.] [[1. 0.37139068 0.2516098 ]\n", " [ 0 17 2] [0. 0.92847669 0.35944258]\n", " [ 0 0 22]] [0. 0. 0.89860644]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAABKCAYAAABEr1FoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEPElEQVR4nO2dT2gcVRzHP9836WaTJk2UQim10CK99CYU/yCCIEIRQU/Sg1LEo4IBL+LViyc9eSkoFBSKqGBvQYMIBZFKFaQtYhXE1FRtxGSTmD8z8/OwG3xEO7uJ47zS/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6VtJVyRVTspUhfeAmHKDfPnnvs0kZcCbwKPALHBe0lkzu7TdlC4gwoo1Nha+H6TpvcAVM/sBQNIZujNl1Svgq/lzzX5hKjEreWf6wm8zm7MltitmzDoA/BTVzQL37SSn94CIJuYJ3YrvhHfGVeBg9PyuXtm2cQE74zxwRNJhSS3gBN2ZsraND0E7wMxySS8A00AGvG1mF3cSS/4LGmnxISgxLiAxLiAxLiAxLiAxLiAxLiAxfwFJjiPBFhaP7gAAAABJRU5ErkJggg==", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 35$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 70 x_{1} x_{2} + 70 x_{1} x_{3} - 90 x_{1} + 70 x_{2} x_{3} - 85 x_{2} - 80 x_{3} + 140$" ], "text/plain": [ "70*x1*x2 + 70*x1*x3 - 90*x1 + 70*x2*x3 - 85*x2 - 80*x3 + 140" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "--------------- ---------------- ------------------------------------\n", "[[-90 70 70] [-90. -85. -80.] [[1. 0.9974587 0.99118374]\n", " [ 0 -85 70] [0. 0.07124705 0.13215783]\n", " [ 0 0 -80]] [0. 0. 0.00943985]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAABECAYAAACCsBvSAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFNklEQVR4nO2dT4wTVRzHP98367bb7QIqERVNNAYPeBATohdiQjSKXNCDBA+GRBM9yIHEi8aLCeFiNHrQmGDEcDHIhWgMAYULFxPBxBgxEhExgiBh1d3tLvunMz8PHZYnXdvCtJ0W3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0R22LdSWWOKrT5Y7Fv1bCtJCHLEIXR9DFkWxxpNclnZH0bbqs99peTQuFxyU93kq8kO58Ekc0PdyuaG+b2Zv+jrQwuAm4D7gdOCjpXjOLGwUKI8nDJRGFqTKFqY6lvA3AbjObMbNfgBPUCoiNdXVKTT+ixDFUKTNUKUNrT/o1Youk7yTtlHTpun6hYuHyZoFCuvNwsWOoMj8L3rDoJ+kgcOsCTa8B7wPbqD2uuQ14C3juWnUFkzyUiMHJlh99ebSlmNIHwOfp5jUVC0O683AxFCqOQiXbYbn0OGbKU9SeAIRaYXCTpIKku4EVwNfN4oWR5KHEGJiotiPUG5JWUUt3p4AXAczsmKQ9wA9AFXip2ZUdBJP+TWIwlf3v383s2QZt24HtVxMvmOQTJ6gymbeKOoJJPkmMTYzlraKOYJKHxVWS8dG8ZdQRTPJJqiSTf+atoo5gkofFc8QTZ5t37DLBJA+LZ6mOnc5bRh3BJJ9kjurk73mrqCOY5GHxDHNjP+ctow6FfyhyGUn7ufwtxhd65Sung0l9QJhg7QOCSX1AMKkPCCb1AcGkPuAfdQd5HK2Kh4MAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 80$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 160 x_{1} x_{2} + 160 x_{1} x_{3} - 225 x_{1} + 160 x_{2} x_{3} - 220 x_{2} - 215 x_{3} + 320$" ], "text/plain": [ "160*x1*x2 + 160*x1*x3 - 225*x1 + 160*x2*x3 - 220*x2 - 215*x3 + 320" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "------------------ ------------------- ------------------------------------\n", "[[-225 160 160] [-225. -220. -215.] [[1. 0.99951208 0.99816671]\n", " [ 0 -220 160] [0. 0.03123475 0.06049495]\n", " [ 0 0 -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XR6suo7S+hPfp1O2ejfX6M2/1ZJzLO6yzIrC64lebSTIL2IpP0pOkIiMs+wVLklRk1JoeXpJUBAaX/bCZpFAEhhaPV11GaR5eJOSi3vAuoSSpELWldD506+FFlENtseoqyvPwIiqM0OhNf0Y/eHixvECLS933OyL802OxIseaTazZPNAwkj6Q9IukHyV9LulUtO1iu7/hlqQXovV77n3w8CJW5FhjHmvMH3Sor4BHzewx4FfgIkC7n2ECeAQYBz6WlO2398EPm7G8hTVmDzyMmX0ZLU4Br7QfnwcmzWwF+E3SNOt9D9DufQCQtNH78HOn5/FXXqxokTfnyJtzvRz1TeBG+/FuPQ776n3wV17E8jXyhbufWu/YqyDpa+CBHYa5ZGZX2/tcAlrAZ4dRr4cXsXyVtYXfNxY79SpgZs91GkvSG8BLwLO2+Zs/nXoc9tz74IfNiOUrrN2ZYe3OzIHGkTQOvA+8bGbx3OMaMCFpUNIZYAz4ln32Psh/CGqTpC+AjS8Gn93vt7u3L0QGgY2T55SZvd3edon182ALeM/MbrTXnwM+ZLP3Yac3++99Hg8vXX7YTJiHlzAPL2EeXsI8vIR5eAnz8BLm4SXsP8CBPnQOU0roAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 200$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 400 x_{1} x_{2} + 400 x_{1} x_{3} - 585 x_{1} + 400 x_{2} x_{3} - 580 x_{2} - 575 x_{3} + 800$" ], "text/plain": [ "400*x1*x2 + 400*x1*x3 - 585*x1 + 400*x2*x3 - 580*x2 - 575*x3 + 800" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "------------------ ------------------- ------------------------------------------------\n", "[[-585 400 400] [-585. -580. -575.] [[1.00000000e+00 9.99921884e-01 9.99695260e-01]\n", " [ 0 -580 400] [0.00000000e+00 1.24990236e-02 2.46838336e-02]\n", " [ 0 0 -575]] [0.00000000e+00 0.00000000e+00 3.08547920e-04]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAABGCAYAAADCZsqeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEYElEQVR4nO3dv4scZRzH8ffnmdyvvctFMY2/iqCxiE0EURALC8UkTVCb+A9oYSpB0M4mjShWQYiQOlgoBAkGUtiJJoVIIgSCkWgIwVw0t3cb7nbn+VrsXny8u+xOLns79+j3BQM3P3j2y36Y2Z3Z+c7JzHB5CnUX4DbOw8uYh5cxDy9jHl7GPLyMbeu38pmHXhzKecSB+e+GMcxQHWmXWr3sySBr9f6+Zpw2s30jLuue9A3v/2ZJ8N5kN9N3W7az5nIG8vASheCB8d5Mq++mW4KHlygE0+ODt9sqPLxEIZidWPko3PqXDT28RAgwM7nme8yW5eElgmBq3MPLUgii0cjn1NfDS4QAUx5enhTEZCOftySfSkdAQYw1irrLqMzDS4RCjG8fq7uMyjy8hAoxtiOfs3QPLxVEMeN7XpZUiGLHRN1lVObhpQohP2xmqggw+x8J76tz7aG8yOvPvzSUcQD2//nt0MZaI0DM6Dwvn8sJI2CFKKcLyunB53qS9km6KOmSpPdHUN4aHl7CArSnRXu6/8VpSQVwFNgP7AHelLRnBCX+i4eXMMHyZHca4Dngkpn9YmbLwAng4GbXt5qHl4gBbjcitxtx0KaPAr8l87/3lo1UPp/OIxCD0Zq6E9xOSeeS1cfM7FgNZd2Vh5eIARYn74R3w8yevcumV4HHk/nHestGyg+biShojXenAc4CuyXtkjQOHAJObnZ9q/melygFzQq3QZhZR9Jh4DRQAMfN7MJm17eah5coJZpj1X7PM7NTwKnNrag/Dy8RJRaD/6qQpZLArdCou4zKPLxEh8BNZuouozIPL1FSMGc76i6jMg8v0aHgr7i97jIq8/ASHSuY6zxYdxmVeXiJ0rZx08PLU2mBhY4fNrMUrWBhebbuMiobSXhffr8wtLHeeGE4beJH1llmsWBpyfe8LJkFbHmq7jIq8/ASigXhth82s6QYGFv0w2aWFAsmF/3yWJZCDEy0/DMvSyGKqYXBt45tFR5eQqWYaObzluRT6QgowlgGTz5a4eElVBrFQqfuMirzu8dSMaJmCzXvb/eT9KGkq5J+7E0HknUf9PobLkp6NVl+z70PvuelyhJrNoc12qdm9nG6oNfPcAh4GngEOCPpqd7qo8ArdO++PivppJn93O8FPLxUjNAaWnjrOQicMLMl4LKkS3T7HqDX+wAgaaX3oW94fthMWOwQm3PE5twwhjss6SdJxyWt/Eh4tx6HDfU+eHipsk05f51y/jr0ehWS6a10U0lnJJ1fZzoIfAY8AewFrgGfbEa5fthMWNkhLv6xMtuvVwEze7nKmJI+B77uzfbrcbjn3gff8xIWl2nPX6E9f+W+xpH0cDL7GnC+9/dJ4JCkCUm7gN3AD2yw98H3vISVS7RvXR7GUB9J2kv3iau/Am8DmNkFSV/Q/SLSAd4xsxJgI70P8n8E9Q9J3wArDwa/sdWf7u7hZcw/8zLm4WXMw8uYh5cxDy9jHl7GPLyM/Q00HTZ25sE9uQAAAABJRU5ErkJggg==", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "Q = make_qubo(γ = [1, 35, 80, 200], verbose = 1)\n", "# for i in [1,4,40]: make_qubo(γ = i, verbose = True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "QUBO:\n" ] }, { "data": { "text/latex": [ "$\\displaystyle 15 x_{1} + 20 x_{2} + 25 x_{3} + γ \\left(x_{1} + x_{2} + x_{3} - 2\\right)^{2}$" ], "text/plain": [ "15*x1 + 20*x2 + 25*x3 + γ*(x1 + x2 + x3 - 2)**2" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 23$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 46 x_{1} x_{2} + 46 x_{1} x_{3} - 54 x_{1} + 46 x_{2} x_{3} - 49 x_{2} - 44 x_{3} + 92$" ], "text/plain": [ "46*x1*x2 + 46*x1*x3 - 54*x1 + 46*x2*x3 - 49*x2 - 44*x3 + 92" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "--------------- ---------------- ------------------------------------\n", "[[-54 46 46] [-54. -49. -44.] [[1. 0.99414446 0.9810992 ]\n", " [ 0 -49 46] [0. 0.10805918 0.19237239]\n", " [ 0 0 -44]] [0. 0. 0.02091004]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAABICAYAAAD1ctupAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAES0lEQVR4nO2dz2scZRjHP9930s1mkyaKvVj1IFKF9lJB9CIeRLD2kmv8A9RDe/Hkj4OIoKD44yRChR6lehQpFqpXEQVFrFAIGjGhPcSG7qbpJrszj4fdpC+Zmg3pbmaGPh8YyMy8PPtNPvvuvPvuuxOZGU65CUUHcAbjkiqAS6oALqkCuKQK4JIqwNhOJx+/7+mhjM9PNn8YRpmh8m4n1fZjjyWyG/3feMm4YGYn9jvX7dhR0t1GG3hzqufuVMsOFZvmFi4pIhHM1IpOkcclRSQBpseLTpHHJUUEwdT45qWqPNNlLikiBGiM58YTheOSIoJEY2LzXUlaaJYYlxQRAjQa5Xvr6JIiFEStnhQdI4dLiggB6pMuqdQoEbWDB4qOkcMlRSiIsUmXVGqUiAMlnHJwSRFKAolLKjmJCDPlmxdySTFB4NekkpMIm66YpI//Xh/Kg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image/svg+xml\n \n \n Matplotlib v3.4.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 24$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 48 x_{1} x_{2} + 48 x_{1} x_{3} - 57 x_{1} + 48 x_{2} x_{3} - 52 x_{2} - 47 x_{3} + 96$" ], "text/plain": [ "48*x1*x2 + 48*x1*x3 - 57*x1 + 48*x2*x3 - 52*x2 - 47*x3 + 96" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "--------------- ---------------- ------------------------------------\n", "[[-57 48 48] [-57. -52. -47.] [[1. 0.99461841 0.98247844]\n", " [ 0 -52 48] [0. 0.10360608 0.18537329]\n", " [ 0 0 -47]] [0. 0. 0.01930972]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAABHCAYAAAAEJGl8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEOUlEQVR4nO2dTWhcVRiGn/fcJDP5sa3YjX+LInFRNwriSlyIYO0muKtbBd10ISKoCCKCguDPSoQK3bip2yLVQnEnggqK1EWhGEVjLcSSZJppxpl7PxeZ1ENvnQnJTO659Hvgwpx7D9+83Idz7k8OE5kZTtqEqgM4w3FJNcAl1QCXVANcUg1wSTVgYtDBh+54dCT350fX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d3tPLVR1KE5R26q4t0Vxd3VUfSnVHzaeB8//Np4JikhqRDwDzw7dB6/g9F/kPSl8DWD+Qu7/TXjCV9yuZUZ8CvwAtmdql/7HXgWaAHvGhmXwyt55LSx6e7GuCSaoBLqgEuqQa4pBrgkmqAS6oBLqkG/At3sSg5/gCrUgAAAABJRU5ErkJggg==", "image/svg+xml": "\n\n\n \n \n \n \n 2022-02-11T10:43:24.931116\n image/svg+xml\n \n \n Matplotlib v3.4.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 25$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 50 x_{1} x_{2} + 50 x_{1} x_{3} - 60 x_{1} + 50 x_{2} x_{3} - 55 x_{2} - 50 x_{3} + 100$" ], "text/plain": [ "50*x1*x2 + 50*x1*x3 - 60*x1 + 50*x2*x3 - 55*x2 - 50*x3 + 100" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "--------------- ---------------- ------------------------------------\n", "[[-60 50 50] [-60. -55. -50.] [[1. 0.99503719 0.98371253]\n", " [ 0 -55 50] [0. 0.09950372 0.17885682]\n", " [ 0 0 -50]] [0. 0. 0.01788568]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAABJCAYAAAA+LggMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkT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IClSJ+bu2KLUpM6tK2gd8C8TAATM706u6PKRAQsSsjbZ1rpkdBY72tqIaDylQJeZiuj7vMhp4SIGqDTCT3JR3GQ08pEBiEbNJ62vSavOQAokNcHnZR1KhJRZTrqzLu4wGHlLALGLp6tq8y2iwKiG9c/LLrvU1/tzJrvV1LUsj0spIz/pfKR9JAVmMFv3GodCUxgwueEiFpjRicMmnu0JTGlGav0FvHPpFlESU5ou3XMhDCkSJGC77WvBCUwqDC744stCUGgPlat5lNPCQQomh+cW8q2jgb5+H0hQWFmtbByS9LWlK0k/ZtjM49nq2oPKspCfb6c9HUihNsPJst3r70MzeD3dkCyj3AA8AdwLHJd1vZkmzjnwkBSypks7NkM7N9OpH7AIOmdlVM5sAzlFbaNmUhxRKlknL06TlaWi+OLId+ySdlnRAUv1NqhUtqvTpLmBpleTKX/Vm08WRko4Dt1/n0BvAJ8A4tY/6Ggc+AJ5faV0eUsCSCtXZC+2da/Z4O+dJ+gz4JmuuaFGlT3cBSyosz02wPDfRUT/1j/fMPEPtEyWhtoByj6QhSRuBTcAPrfrzkRRKK1Tn2xtJLbwnaQu16W4SeAnAzM5IOgz8AlSBl1vd2UGLj5y+0Ug6BmzImhfNbEee9dR5SH3Ar0l9wEPqAx5SH/CQ+oCH1Ac8pD7wD0hFhLn1ET3CAAAAAElFTkSuQmCC", "image/svg+xml": "\n\n\n \n \n \n \n 2022-02-11T10:43:25.129184\n image/svg+xml\n \n \n Matplotlib v3.4.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 26$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 52 x_{1} x_{2} + 52 x_{1} x_{3} - 63 x_{1} + 52 x_{2} x_{3} - 58 x_{2} - 53 x_{3} + 104$" ], "text/plain": [ "52*x1*x2 + 52*x1*x3 - 63*x1 + 52*x2*x3 - 58*x2 - 53*x3 + 104" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "--------------- ---------------- ------------------------------------\n", "[[-63 52 52] [-63. -58. -53.] [[1. 0.99540903 0.98482109]\n", " [ 0 -58 52] [0. 0.09571241 0.17277563]\n", " [ 0 0 -53]] [0. 0. 0.01661304]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAABHCAYAAAAEJGl8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFHUlEQVR4nO2cX4hUVRzHP99zt91x3VUrSfoHiVhhDxmITxJJUeaL9CL2ED4E9ZAPPuZDIIQEUfQQ0UPgY5gPSRGipdRbkAUhGgmmRtqauNXu7Nr+mXt/PczdODk2Mzkze+/g7wOHmXPund/97nznnHvuub+9MjOcchOKFuC0xk3qA9ykPsBN6gPcpD7ATeoDBooW0M9IugBUgRSomdkGSXcAHwEPABeA7Wb2RyfH8Z7UOZvNbL2ZbcjrrwLHzWwtcDyvd4SaXcw+duemrlzpbp38uhthusq++VTXt60Jsmv5X3wZjprZlmYx8p60wcyuRm1ngCfMbEzS3cBXZvZQJ1q9J0XMArsrgd2VAPCwpG+j8tINPmLA55K+i7avMrOx/P1lYFWnuvycFJEIVgzmXWmGq9EQ9l9sMrNLku4CvpD0Y7zRzExSx6OR96SIJMDywXppBzO7lL9eAQ4BG4Hf8mGO/PVKp7rc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DetrXDklDklYDa4FvWsXznhRh6Ry1iYvdCPWmpPXUn8d2AXgZwMxOSzoI/ADUgFdazezATfo32Ty16V87DmNmLzTZtg/Y93/iuUkRls4yP/FT0TIaaPrI6VsNSUeAlXn1aqtHTi8WblIf4LO7PsBN6gPcpD7ATeoD3KQ+4G8sMZPgNhclUAAAAABJRU5ErkJggg==", "image/svg+xml": "\n\n\n \n \n \n \n 2022-02-11T10:43:25.636174\n image/svg+xml\n \n \n Matplotlib v3.4.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" }, { "data": { "text/markdown": [ "#### Simplified QUBO with $γ = 27$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle 54 x_{1} x_{2} + 54 x_{1} x_{3} - 66 x_{1} + 54 x_{2} x_{3} - 61 x_{2} - 56 x_{3} + 108$" ], "text/plain": [ "54*x1*x2 + 54*x1*x3 - 66*x1 + 54*x2*x3 - 61*x2 - 56*x3 + 108" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "QUBO Matrix Eigenvalues Eigenvectors\n", "--------------- ---------------- ------------------------------------\n", "[[-66 54 54] [-66. -61. -56.] [[1. 0.99574067 0.98582056]\n", " [ 0 -61 54] [0. 0.09219821 0.16708823]\n", " [ 0 0 -56]] [0. 0. 0.01547113]]\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAABGCAYAAADPeLrZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuM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rATqqpXF3BW1JESmBazZ9mzawiaQ9wCkiAw2Z2rlu63KSICgmTtrKlumZ2AjjRXUVV3KSICgkT2VjeMupwkyJSS5jKWmtJy4mbFFGxhMnKWN4y6nCTIlIb4K+F1XnLqMNNikgtYWZ+Vd4y6nCTIswC8wu990JpWUw6+PUXHYu1f9fJjsW6E8sCldmRrsVfKt6SImQJ+ns0bxl1uEkxWSCZXZG3ijrcpIiQJQze9O6up1EWGCq5ST1NSANDpaYj4MuOmxShTBTKvZfB6u+TIkIKg6XAYKm9wyJpv6RxST/UyrZo31u1DKPzkl5oJZ63pAhlxsBMpVPh3jezd2+LX80o2gk8ATwInJb0uJmljQJ5S4rJDG7OVUt32A4cNbM5M7sEXKCaedQQNykmzVCpjErlTkTbI+lHSYclLY7aLinLyE2KyVJsZgqbmYIms3RJOi3p7F3KduAj4DFgI3AVeK8dWX5NirC0QjY9ubjaMKXLzJ5rJaakj4HFwcslZRl5S4rJKmTlG2TlG22FWZylq8bLVCeGgmpG0U5Jg5LWAeuBb5vF85YUYekC6czV5hWbc0jSRqqTFl4GXgcws3OSjgE/ARXgjWZ3duAm3Yal81SmrrQfx2xXg30HgAP/JZ6bFJMtUCn/nreKOtykCEvnWJj6JW8ZdTSccvr/hqST/DuL8USzKaeXCzepD/Bb8D7ATeoD3KQ+wE3qA9ykPuAfv3aG1l/XmtYAAAAASUVORK5CYII=", "image/svg+xml": "\n\n\n \n \n \n \n 2022-02-11T10:43:25.845263\n image/svg+xml\n \n \n Matplotlib v3.4.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "Q = make_qubo(γ = [23, 24, 25, 26, 27], verbose = 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate all possible solutions for the choosing boxes problem with 3 variables for different $γ$ :" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "All possible solution values for $γ = 1$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " x1 x2 x3 γ x1 x2 x3\n", "15 * 0 + 20 * 0 + 25 * 0 + 1 * (0 + 0 + 0 - 2)**2 \t= 4\n", "15 * 0 + 20 * 0 + 25 * 1 + 1 * (0 + 0 + 1 - 2)**2 \t= 26\n", "15 * 0 + 20 * 1 + 25 * 0 + 1 * (0 + 1 + 0 - 2)**2 \t= 21\n", "15 * 0 + 20 * 1 + 25 * 1 + 1 * (0 + 1 + 1 - 2)**2 \t= 45\n", "15 * 1 + 20 * 0 + 25 * 0 + 1 * (1 + 0 + 0 - 2)**2 \t= 16\n", "15 * 1 + 20 * 0 + 25 * 1 + 1 * (1 + 0 + 1 - 2)**2 \t= 40\n", "15 * 1 + 20 * 1 + 25 * 0 + 1 * (1 + 1 + 0 - 2)**2 \t= 35\n", "15 * 1 + 20 * 1 + 25 * 1 + 1 * (1 + 1 + 1 - 2)**2 \t= 61\n" ] }, { "data": { "text/markdown": [ "All possible solution values for $γ = 35$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " x1 x2 x3 γ x1 x2 x3\n", "15 * 0 + 20 * 0 + 25 * 0 + 35 * (0 + 0 + 0 - 2)**2 \t= 140\n", "15 * 0 + 20 * 0 + 25 * 1 + 35 * (0 + 0 + 1 - 2)**2 \t= 60\n", "15 * 0 + 20 * 1 + 25 * 0 + 35 * (0 + 1 + 0 - 2)**2 \t= 55\n", "15 * 0 + 20 * 1 + 25 * 1 + 35 * (0 + 1 + 1 - 2)**2 \t= 45\n", "15 * 1 + 20 * 0 + 25 * 0 + 35 * (1 + 0 + 0 - 2)**2 \t= 50\n", "15 * 1 + 20 * 0 + 25 * 1 + 35 * (1 + 0 + 1 - 2)**2 \t= 40\n", "15 * 1 + 20 * 1 + 25 * 0 + 35 * (1 + 1 + 0 - 2)**2 \t= 35\n", "15 * 1 + 20 * 1 + 25 * 1 + 35 * (1 + 1 + 1 - 2)**2 \t= 95\n" ] }, { "data": { "text/markdown": [ "All possible solution values for $γ = 50$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " x1 x2 x3 γ x1 x2 x3\n", "15 * 0 + 20 * 0 + 25 * 0 + 50 * (0 + 0 + 0 - 2)**2 \t= 200\n", "15 * 0 + 20 * 0 + 25 * 1 + 50 * (0 + 0 + 1 - 2)**2 \t= 75\n", "15 * 0 + 20 * 1 + 25 * 0 + 50 * (0 + 1 + 0 - 2)**2 \t= 70\n", "15 * 0 + 20 * 1 + 25 * 1 + 50 * (0 + 1 + 1 - 2)**2 \t= 45\n", "15 * 1 + 20 * 0 + 25 * 0 + 50 * (1 + 0 + 0 - 2)**2 \t= 65\n", "15 * 1 + 20 * 0 + 25 * 1 + 50 * (1 + 0 + 1 - 2)**2 \t= 40\n", "15 * 1 + 20 * 1 + 25 * 0 + 50 * (1 + 1 + 0 - 2)**2 \t= 35\n", "15 * 1 + 20 * 1 + 25 * 1 + 50 * (1 + 1 + 1 - 2)**2 \t= 110\n" ] }, { "data": { "text/markdown": [ "All possible solution values for $γ = 200$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " x1 x2 x3 γ x1 x2 x3\n", "15 * 0 + 20 * 0 + 25 * 0 + 200 * (0 + 0 + 0 - 2)**2 \t= 800\n", "15 * 0 + 20 * 0 + 25 * 1 + 200 * (0 + 0 + 1 - 2)**2 \t= 225\n", "15 * 0 + 20 * 1 + 25 * 0 + 200 * (0 + 1 + 0 - 2)**2 \t= 220\n", "15 * 0 + 20 * 1 + 25 * 1 + 200 * (0 + 1 + 1 - 2)**2 \t= 45\n", "15 * 1 + 20 * 0 + 25 * 0 + 200 * (1 + 0 + 0 - 2)**2 \t= 215\n", "15 * 1 + 20 * 0 + 25 * 1 + 200 * (1 + 0 + 1 - 2)**2 \t= 40\n", "15 * 1 + 20 * 1 + 25 * 0 + 200 * (1 + 1 + 0 - 2)**2 \t= 35\n", "15 * 1 + 20 * 1 + 25 * 1 + 200 * (1 + 1 + 1 - 2)**2 \t= 260\n" ] } ], "source": [ "# Calcuate the QUBO for various γ\n", "# For high γ (200) the dynamic of the hardware is not utilized\n", "\n", "for γ in [1, 35, 50, 200]:\n", "# for γ in [23, 24, 25, 26, 27]:\n", " display(Markdown(f'All possible solution values for $γ = {γ}$'))\n", " print(f' x1 x2 x3 γ {\" \" * len(str(γ))} x1 x2 x3')\n", " for x1 in [0, 1]:\n", " for x2 in [0, 1]:\n", " for x3 in [0, 1]:\n", " print(f'15 * {x1} + 20 * {x2} + 25 * {x3} + {γ} * ({x1} + {x2} + {x3} - 2)**2 \\t= ',\n", " 15 * x1 + 20 * x2 + 25 * x3 + γ * (x1 + x2 + x3 - 2)**2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here again all possible solutions are shown, including the duplicate counts of the results per $γ$ :" ] }, { "cell_type": "code", "execution_count": 96, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Duplicate_count
γ
104
208
254
\n", "
" ], "text/plain": [ " Duplicate_count\n", "γ \n", "10 4\n", "20 8\n", "25 4" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
  x1x2x3|15* x1+ 20* x2+ 25* x3+ γ(x1+ x2+ x3- 2)^2=resultduplicates
γ                    
10000|000100040
1001|0011001260
2010|0101010210
3011|0111011450
4100|1001100160
5101|1011101400
6110|1101110350
7111|1111111610
100000|00010000401
1001|00110001351
2010|01010010300
3011|01110011450
4100|10010100250
5101|10110101401
6110|11010110351
7111|11110111700
200000|00020000801
1001|00120001451
2010|01020010401
3011|01120011451
4100|10020100351
5101|10120101401
6110|11020110351
7111|11120111801
210000|00021000840
1001|00121001460
2010|01021010410
3011|01121011450
4100|10021100360
5101|10121101400
6110|11021110350
7111|11121111810
220000|00022000880
1001|00122001470
2010|01022010420
3011|01122011450
4100|10022100370
5101|10122101400
6110|11022110350
7111|11122111820
230000|00023000920
1001|00123001480
2010|01023010430
3011|01123011450
4100|10023100380
5101|10123101400
6110|11023110350
7111|11123111830
240000|00024000960
1001|00124001490
2010|01024010440
3011|01124011450
4100|10024100390
5101|10124101400
6110|11024110350
7111|11124111840
250000|000250001000
1001|00125001500
2010|01025010451
3011|01125011451
4100|10025100401
5101|10125101401
6110|11025110350
7111|11125111850
260000|000260001040
1001|00126001510
2010|01026010460
3011|01126011450
4100|10026100410
5101|10126101400
6110|11026110350
7111|11126111860
270000|000270001080
1001|00127001520
2010|01027010470
3011|01127011450
4100|10027100420
5101|10127101400
6110|11027110350
7111|11127111870
350000|000350001400
1001|00135001600
2010|01035010550
3011|01135011450
4100|10035100500
5101|10135101400
6110|11035110350
7111|11135111950
400000|000400001600
1001|00140001650
2010|01040010600
3011|01140011450
4100|10040100550
5101|10140101400
6110|11040110350
7111|111401111000
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Calcuate the QUBO for various γ\n", "# Note: for γ in [5, 10, 15, 20, 25, 30] there are duplicate solutions\n", "\n", "num_vars = 3\n", "γs = [22, 23, 24, 25, 26, 27]\n", "γs = [1, 10, 20, 21, 22, 23, 24, 25, 26, 27, 35, 40, 80, 200][:-2]\n", "# γs = [5, 10, 15, 20, 25, 30] # duplicates\n", "# γs = range(2100)\n", "\n", "# vars_combs = np.array(sorted(np.array(np.meshgrid(*([[0, 1]] * num_vars))).reshape(-1, num_vars).tolist()))\n", "vars_combs = np.array([[int(b) for b in (\"0\" * num_vars + bin(x)[2:])[-num_vars:]] for x in range(2 ** num_vars)])\n", "vars_combs = {f'x{k}': v for k, v in zip(range(1, num_vars + 1), vars_combs.T)}\n", "\n", "df = pd.DataFrame(vars_combs)\n", "df2 = pd.Series([γs] * len(df), name = \"γ\", index = df.index)\n", "df = df.join(df2.explode()).set_index(\"γ\", append = True).swaplevel(0, 1, axis = 0).sort_index()\n", "\n", "df[\"|\"] = \"|\"\n", "df[\"15\"] = \"\"\n", "df[\"* x1\"] = df.x1\n", "df[\"+ 20\"] = \"\"\n", "df[\"* x2\"] = df.x2\n", "df[\"+ 25\"] = \"\"\n", "df[\"* x3\"] = df.x3\n", "df[\"+ γ\"] = df.index.get_level_values(0)\n", "df[\"(x1\"] = df.x1\n", "df[\"+ x2\"] = df.x2\n", "df[\"+ x3\"] = df.x3\n", "df[\"- 2\"] = \"\" #2\n", "df[\")^2\"] = \"\"\n", "df[\"=\"] = \"\"\n", "df[\"result\"] = 15 * df.x1 + 20 * df.x2 + 25 * df.x3 + df.index.get_level_values(0) * (df.x1 + df.x2 + df.x3 - 2)**2\n", "# df[\"Equation\"] = \"15 * \" + df.x1.astype(str) + \" + 20 * {df.x2} + 25 * {df.x3} + {γ} * ({df.x1} + {df.x2} + {df.x3} - 2)**2\"\n", "df[\"duplicates\"] = df.groupby(level = \"γ\", axis = 0).apply(lambda x: x.duplicated(subset = \"result\", keep = False)).values\n", "\n", "# df_dups = df.duplicates.groupby(level = 0).sum()\n", "df_dups = df.duplicates.groupby(level = \"γ\").sum()\n", "display(df_dups[df_dups != 0].to_frame().rename(columns = {\"duplicates\": \"Duplicate_count\"}))\n", "# display(df.result.groupby(level = \"γ\").agg([\"min\", \"max\", \"var\", \"std\", \"mean\", \"median\", \"sem\", \"sum\", \"skew\", np.ptp]).style.bar())\n", "\n", "display(\n", " df.style.bar(\n", " subset = [\"result\"],\n", " color = \"#ff92a585\",\n", " ).set_properties(\n", " **{\"background-color\": \"#adadad69\"},\n", " subset = pd.IndexSlice[pd.IndexSlice[df.index.unique(level = 0)[::2], :], :]\n", " ).text_gradient(\n", " subset = [c for c in df.columns if any([x in c for x in [\"x1\", \"x2\", \"x3\"]]) and c not in [\"x1\", \"x2\", \"x3\"]],\n", " cmap = \"bwr_r\", # tab10 PiYG\n", " ).text_gradient(\n", " subset = \"duplicates\",\n", " cmap = \"bwr\",\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "array([[-105., 80., 80.],\n", " [ 0., -100., 80.],\n", " [ 0., 0., -95.]])\n", "{(0, 0): -105.0,\n", " (0, 1): 80.0,\n", " (0, 2): 80.0,\n", " (1, 1): -100.0,\n", " (1, 2): 80.0,\n", " (2, 2): -95.0}\n" ] } ], "source": [ "def make_Q_dict(Q: np.ndarray, verbose = False) -> dict:\n", " \"\"\"\n", " Prepare the Q matrix for DWaveSampler()\n", " \"\"\"\n", " Q = Q.astype(float) # for nan masking\n", " if verbose:\n", " pprint(Q)\n", "\n", " triu_indices = np.triu_indices(Q.shape[0])\n", " # triu_indices = np.dstack(triu_indices)[0]\n", "\n", " mask = np.ones_like(Q).astype(bool)\n", " mask[triu_indices] = False\n", "\n", " assert np.isnan(Q[mask]).all() or (Q[mask] == 0).all(), \"Lower triangle should not contain any values\"\n", "\n", " # set lower triangle to np.nan\n", " Q[mask] = np.nan\n", "\n", " Q_dict = {k: v for (k, v) in np.ndenumerate(Q) if not np.isnan(v)}\n", "\n", " if verbose:\n", " pprint(Q_dict)\n", " return Q_dict\n", "\n", "\n", "Q = make_Q_dict(make_qubo(γ = 40, verbose = False), verbose = True)\n", "# for i in [1,4,40]: make_Q_dict(make_qubo(γ = i, verbose = False), verbose = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Run Problem on D-Wave QA" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [], "source": [ "Q = make_Q_dict(make_qubo(γ = 35))\n", "\n", "sampler = EmbeddingComposite(DWaveSampler())\n", "\n", "# Create a bqm object...\n", "bqm = dimod.BQM.from_qubo(Q)\n", "sampleset = sampler.sample(bqm, num_reads = 10, label = f'Choosing Boxes QUBO (γ = {γ})')\n", "\n", "# ...or use sample_qubo() directly.\n", "# sampleset = sampler.sample_qubo(Q, num_reads = 10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the energies returned by the QA are negative here, unlike in the solutions above." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0 1 2 energy num_oc. chain_.\n", "0 1 1 0 -105.0 6 0.0\n", "1 1 0 1 -100.0 2 0.0\n", "2 0 1 1 -95.0 1 0.0\n", "3 1 0 0 -90.0 1 0.0\n", "['BINARY', 4 rows, 10 samples, 3 variables]\n", "\n", "{'_info': {'problem_id': 'ae49c94b-c722-43a9-8bda-cc538266031e',\n", " 'timing': {'post_processing_overhead_time': 764.0,\n", " 'qpu_access_overhead_time': 20109.2,\n", " 'qpu_access_time': 9285.8,\n", " 'qpu_anneal_time_per_sample': 20.0,\n", " 'qpu_delay_time_per_sample': 20.54,\n", " 'qpu_programming_time': 8448.6,\n", " 'qpu_readout_time_per_sample': 43.18,\n", " 'qpu_sampling_time': 837.2,\n", " 'total_post_processing_time': 764.0}},\n", " '_record': rec.array([([1, 1, 0], -105., 6, 0.), ([1, 0, 1], -100., 2, 0.),\n", " ([0, 1, 1], -95., 1, 0.), ([1, 0, 0], -90., 1, 0.)],\n", " dtype=[('sample', 'i1', (3,)), ('energy', '}\n" ] } ], "source": [ "print(sampleset, end = \"\\n\\n\")\n", "pprint(vars(sampleset)); print()\n", "# sampleset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Lagrange Multiplier (γ) Comparison\n", "\n", "Note that the energies are not scaled here." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "samplesets = {}\n", "\n", "# for γ in [23, 24, 25, 26, 27]:\n", "# for γ in reversed([23, 24, 25, 26, 27]):\n", "for γ in [1, 10, 20, 30, 35, 40, 60, 80, 100, 120, 150, 200]:\n", "\n", " sampler = EmbeddingComposite(DWaveSampler())\n", "\n", " # x1, x2, x3 = [dimod.Binary(f'x{i}') for i in range(1, 4)]\n", " # bqm = 15 * x1 + 20 * x2 + 25 * x3 + γ * (x1 + x2 + x3 - 2)**2\n", " # sampleset = sampler.sample(bqm, num_reads = 100)\n", "\n", " Q = make_Q_dict(make_qubo(γ = γ))\n", " sampleset = sampler.sample_qubo(Q, num_reads = 100, label = f'Choosing Boxes (γ = {γ})')\n", "\n", " # print(f'>>> γ = {γ} <<<\\n{sampleset}\\n')\n", " samplesets[γ] = sampleset" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
  x1x2x3chain_break_fractionenergynum_occurrencesresult#picked
γ#        
100000010000
1001000-1592151
10100-108201
2001000-4560151
11100-4527352
20100-404201
31010-409402
3001100-8574352
11010-8014402
20110-756452
31000-755151
40100-701201
3501100-10573352
11010-10022402
20110-954452
30100-851201
4001100-12571352
11010-12022402
20110-1157452
6001100-20553352
11010-20025402
20110-19521452
31000-1651151
8001100-28533352
11010-28040402
20110-27525452
31000-2251151
40010-2151251
10001100-36554352
11010-36031402
20110-35515452
12001100-44551352
11010-44031402
20110-43518452
15001100-56545352
11010-56035402
20110-55520452
20001100-76537352
11010-76040402
20110-75523452
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = pd.concat({γ: s.to_pandas_dataframe() for γ, s in samplesets.items()}).rename_axis(index = [\"γ\", \"#\"])\n", "df = df.convert_dtypes()\n", "df = df.rename(columns = {0: \"x1\", 1: \"x2\", 2: \"x3\"})\n", "\n", "df[\"result\"] = df[\"x1\"] * 15 + df[\"x2\"] * 20 + df[\"x3\"] * 25 # summed weight\n", "df[\"#picked\"] = df[\"x1\"] + df[\"x2\"] + df[\"x3\"] # number of picked boxes (constraint)\n", "\n", "display(\n", " df.style.bar(\n", " subset = [\"chain_break_fraction\", \"energy\", \"num_occurrences\"],\n", " color = \"#ff92a585\",\n", " ).set_properties(\n", " **{\"background-color\": \"#adadad69\"}, # #004ba752\n", " subset = pd.IndexSlice[pd.IndexSlice[df.index.unique(level = 0)[::2], :], :]\n", " ).background_gradient(\n", " subset = \"result\",\n", " cmap = \"Blues_r\"\n", " ).set_properties(\n", " subset = \"#picked\",\n", " **{\"font-weight\": \"bold\"}\n", " ).text_gradient(\n", " subset = \"#picked\",\n", " cmap = \"tab10\"\n", " )\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note: Changing the order of the γ's or inserting a pause in between seems to have quite an impact on the outcome. Maybe `num_reads = 100` is also not sufficient." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
  x1x2x3chain_break_fractionenergynum_occurrencesresult#picked
γ#        
2301100-5777352
11000-5418151
21010-523402
30100-491201
40110-471452
2401100-6177352
11000-5715151
21010-566402
30110-512452
2501100-6562352
11000-6014151
21010-6023402
30110-551452
2601100-6953352
11010-6427402
21000-6312151
30110-595452
40010-533251
2701100-7373352
11010-6813402
21000-669151
30110-632452
40100-613201
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Single Qubit Problem" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here it should be shown if the Quantum Annealer by D-Wave exclusively finds the correct solution for all trials." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": "BinaryQuadraticModel({'x1': 1.0}, {}, 0.0, 'BINARY')" }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "γ = 1\n", "x1 = dimod.Binary(\"x1\")\n", "\n", "bqm = x1 #+ γ * (x1 - 1)**2\n", "bqm" ] }, { "cell_type": "code", "execution_count": 5, "outputs": [ { "data": { "text/plain": " x1 chain_break_fraction energy num_occurrences\n0 0 0.0 0.0 10000", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
x1chain_break_fractionenergynum_occurrences
000.00.010000
\n
" }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "['BINARY', 1 rows, 10000 samples, 1 variables]\n" ] } ], "source": [ "sampler_bqm = EmbeddingComposite(DWaveSampler())\n", "sampleset_bqm = sampler_bqm.sample(bqm, num_reads = 10_000, label = \"Trivial 1-Qubit Problem\")\n", "\n", "display(sampleset_bqm.to_pandas_dataframe())\n", "print(str(sampleset_bqm).splitlines()[-1])" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "code", "execution_count": 32, "outputs": [ { "data": { "text/plain": " time [μs]\nqpu_sampling_time 716000.00\nqpu_anneal_time_per_sample 20.00\nqpu_readout_time_per_sample 31.06\nqpu_access_time 724447.40\nqpu_access_overhead_time 9581.60\nqpu_programming_time 8447.40\nqpu_delay_time_per_sample 20.54\ntotal_post_processing_time 548.00\npost_processing_overhead_time 548.00", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
time [μs]
qpu_sampling_time716000.00
qpu_anneal_time_per_sample20.00
qpu_readout_time_per_sample31.06
qpu_access_time724447.40
qpu_access_overhead_time9581.60
qpu_programming_time8447.40
qpu_delay_time_per_sample20.54
total_post_processing_time548.00
post_processing_overhead_time548.00
\n
" }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.DataFrame.from_dict(sampleset_bqm.info[\"timing\"], orient = \"index\", columns = [\"time [μs]\"])" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "The Exact Solver shows all possible solutions:" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 108, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
x1energynum_occurrences
000.01
111.01
\n", "
" ], "text/plain": [ " x1 energy num_occurrences\n", "0 0 0.0 1\n", "1 1 1.0 1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "['BINARY', 2 rows, 2 samples, 1 variables]\n" ] } ], "source": [ "sampleset_bqm_exact = dimod.ExactSolver().sample(bqm)\n", "# sampleset_bqm_exact = dimod.ExactDQMSolver().sample_dqm(bqm)\n", "# sampleset_bqm_exact = dimod.ExactPolySolver().sample(bqm)\n", "\n", "qvars = bqm.variables.to_serializable()\n", "sampleset_bqm_exact_df = sampleset_bqm_exact.to_pandas_dataframe()\n", "# sampleset_bqm_exact_df[\"constraint_satisfied\"] = sampleset_bqm_exact_df.loc[:, qvars].sum(axis = 1) == 0\n", "display(sampleset_bqm_exact_df.sort_values(by = \"energy\"))\n", "# display(sampleset_bqm_exact_df.sort_values(by = qvars))\n", "print(str(sampleset_bqm_exact).splitlines()[-1])" ] } ], "metadata": { "interpreter": { "hash": "ddc813e355b63b19f1af14a019a3201799d7a9ce0b92523df60f28eba2663f85" }, "kernelspec": { "display_name": "Python 3.9.7 ('py39')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }