From 7be6c86ca04fbeb7e19e374d03195bce752f9754 Mon Sep 17 00:00:00 2001 From: a-matsuo Date: Fri, 16 Feb 2024 11:00:12 +0900 Subject: [PATCH] add a sample lp file. --- how_tos/data/maxcut.lp | 26 ++++++++++++++ how_tos/qiskit_patterns.ipynb | 68 ++++++++++++++++++++++++++++++++--- 2 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 how_tos/data/maxcut.lp diff --git a/how_tos/data/maxcut.lp b/how_tos/data/maxcut.lp new file mode 100644 index 0000000..4bc0610 --- /dev/null +++ b/how_tos/data/maxcut.lp @@ -0,0 +1,26 @@ +\ This file has been generated by DOcplex +\ ENCODING=ISO-8859-1 +\Problem name: Max-cut + +Maximize + obj: 3 x_0 + 3 x_1 + 3 x_2 + 3 x_3 + 3 x_4 + 3 x_5 + 3 x_6 + 3 x_7 + 3 x_8 + + 3 x_9 + [ - 4 x_0*x_3 - 4 x_0*x_5 - 4 x_0*x_7 - 4 x_1*x_2 - 4 x_1*x_4 + - 4 x_1*x_6 - 4 x_2*x_3 - 4 x_2*x_8 - 4 x_3*x_5 - 4 x_4*x_6 - 4 x_4*x_9 + - 4 x_5*x_8 - 4 x_6*x_9 - 4 x_7*x_8 - 4 x_7*x_9 ]/2 +Subject To + +Bounds + 0 <= x_0 <= 1 + 0 <= x_1 <= 1 + 0 <= x_2 <= 1 + 0 <= x_3 <= 1 + 0 <= x_4 <= 1 + 0 <= x_5 <= 1 + 0 <= x_6 <= 1 + 0 <= x_7 <= 1 + 0 <= x_8 <= 1 + 0 <= x_9 <= 1 + +Binaries + x_0 x_1 x_2 x_3 x_4 x_5 x_6 x_7 x_8 x_9 +End diff --git a/how_tos/qiskit_patterns.ipynb b/how_tos/qiskit_patterns.ipynb index 23521f4..eac99aa 100644 --- a/how_tos/qiskit_patterns.ipynb +++ b/how_tos/qiskit_patterns.ipynb @@ -66,9 +66,65 @@ "\\end{align}\n", "\n", "We refer to this Hamiltonian as the **cost function Hamiltonian**. It has the property that its gound state corresponds to the solution that **minimizes the cost function $f(x)$**.\n", - "Therefore, to solve our optimization problem we now need to prepare the ground state of $H_C$ (or a state with a high overlap with it) on the quantum computer. Then, sampling from this state will, with a high probability, yield the solution to $min f(x)$.\n", - "\n", - "**TODO** Load a file with the LP and convert to an Ising Hamiltonian to feed into step 2:" + "Therefore, to solve our optimization problem we now need to prepare the ground state of $H_C$ (or a state with a high overlap with it) on the quantum computer. Then, sampling from this state will, with a high probability, yield the solution to $min f(x)$." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "f10e9e18", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\\ This file has been generated by DOcplex\n", + "\\ ENCODING=ISO-8859-1\n", + "\\Problem name: Max-cut\n", + "\n", + "Maximize\n", + " obj: 3 x_0 + 3 x_1 + 3 x_2 + 3 x_3 + 3 x_4 + 3 x_5 + 3 x_6 + 3 x_7 + 3 x_8\n", + " + 3 x_9 + [ - 4 x_0*x_3 - 4 x_0*x_5 - 4 x_0*x_7 - 4 x_1*x_2 - 4 x_1*x_4\n", + " - 4 x_1*x_6 - 4 x_2*x_3 - 4 x_2*x_8 - 4 x_3*x_5 - 4 x_4*x_6 - 4 x_4*x_9\n", + " - 4 x_5*x_8 - 4 x_6*x_9 - 4 x_7*x_8 - 4 x_7*x_9 ]/2\n", + "Subject To\n", + "\n", + "Bounds\n", + " 0 <= x_0 <= 1\n", + " 0 <= x_1 <= 1\n", + " 0 <= x_2 <= 1\n", + " 0 <= x_3 <= 1\n", + " 0 <= x_4 <= 1\n", + " 0 <= x_5 <= 1\n", + " 0 <= x_6 <= 1\n", + " 0 <= x_7 <= 1\n", + " 0 <= x_8 <= 1\n", + " 0 <= x_9 <= 1\n", + "\n", + "Binaries\n", + " x_0 x_1 x_2 x_3 x_4 x_5 x_6 x_7 x_8 x_9\n", + "End\n", + "\n" + ] + } + ], + "source": [ + "# load a lp file\n", + "lp_file = \"data/maxcut.lp\"\n", + "with open(lp_file, \"r\") as file:\n", + " problem = file.read()\n", + "print(problem)" + ] + }, + { + "cell_type": "markdown", + "id": "5df5c152", + "metadata": {}, + "source": [ + "### TODO: \n", + "- [x] load LP file (use a dummy graph) and print it.\n", + "- [ ] load Ising hamiltonian and print first few terms." ] }, { @@ -94,7 +150,9 @@ "id": "293450a9", "metadata": {}, "source": [ - "**TODO**: Take the Ising Hamiltonian from Step 1. We are loading a dummy Hamiltonian in the meantime" + "**TODO**: Take the Ising Hamiltonian from Step 1. We are loading a dummy Hamiltonian in the meantime\n", + "\n", + "\n" ] }, { @@ -477,7 +535,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.2" + "version": "3.10.11" } }, "nbformat": 4,