Skip to content

Commit

Permalink
add a sample lp file.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-matsuo committed Feb 16, 2024
1 parent 33c5942 commit 7be6c86
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 5 deletions.
26 changes: 26 additions & 0 deletions how_tos/data/maxcut.lp
Original file line number Diff line number Diff line change
@@ -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
68 changes: 63 additions & 5 deletions how_tos/qiskit_patterns.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -477,7 +535,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
"version": "3.10.11"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 7be6c86

Please sign in to comment.