Skip to content

Commit

Permalink
Qiskit Patterns (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: a-matsuo <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
4 people authored Feb 27, 2024
1 parent 211a41b commit e97d744
Show file tree
Hide file tree
Showing 23 changed files with 2,021 additions and 0 deletions.
18 changes: 18 additions & 0 deletions demos/qiskit_patterns/0_setup_instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Qiskit Patterns Lab Prep Work

## Requirements

- Laptop (Windows, MacOS or Linux), access to a terminal

## Instructions

1. Follow the instructions on https://docs.quantum.ibm.com/start/install#install-and-set-up-qiskit-with-the-qiskit-runtime-client
to install and set up a Python environment with Qiskit. Activate your environment.
2. Follow the instructions on https://docs.quantum.ibm.com/start/setup-channel#iqp to set up your access credentials to use
IBM Quantum systems. Only focus on the IBM Quantum Platform instructions, no need to worry about the IBM Cloud setup.
3. Clone this repository running `git clone https://github.com/qiskit-community/qopt-best-practices.git`
4. Navigate to the `demos/qiskit_patterns` directory using the terminal
5. Run `pip install -r requirements.txt`
6. Activate your jupyter environment running `jupyter notebook` in your environment, this should open a browser window
that shows the contents of the `qiskit_patterns` directory
7. Open `1_test_installation.ipynb` and follow the instructions to test that the installation was successful
121 changes: 121 additions & 0 deletions demos/qiskit_patterns/1_test_installation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"# Installation Test\n",
"\n",
"Run the cell below (press `Shift` + `Enter`) to check that all the imports work correctly. If you see the 🎉 emoji as the cell output, your installation was successful."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"import matplotlib.pyplot\n",
"import networkx as nx\n",
"from qiskit_ibm_runtime.fake_provider import FakeVigoV2\n",
"from qiskit import qpy\n",
"from qiskit_aer import Aer\n",
"from qiskit_optimization.applications import Maxcut\n",
"print(\"Your installation works 🎉!\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you have followed the installation instructions (i.e. you have run `pip install -r requirements.txt`) and you get a `module not found` error, your jupyter environment might not be using the right Python kernel. You can try following the following instructions to register your kernel: https://saturncloud.io/blog/how-to-add-a-python-3-kernel-to-jupyter-ipython/."
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"source": [
"If you have not done so yet, you can use the cell below to check that your IBM Quantum Platform account registration has been successful. The backend retrieval step may take a couple of seconds."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"service = QiskitRuntimeService()\n",
"print(\"Your available backends are: \", service.backends())"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"If your service authentication fails (you get an `IBMNotAuthorizedError`), you can try saving your account again. Make sure to replace `\"<MY_IBM_QUANTUM_TOKEN>\"` with your token in string format (example: `service = QiskitRuntimeService(channel=\"ibm_quantum\", token=\"1234abcd\")`)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"# Save an IBM Quantum account and set it as your default account.\n",
"QiskitRuntimeService.save_account(channel=\"ibm_quantum\", token=\"<MY_IBM_QUANTUM_TOKEN>\", overwrite=True, set_as_default=True)\n",
"\n",
"# Load saved credentials\n",
"service = QiskitRuntimeService()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ibm_tech_clean",
"language": "python",
"name": "ibm_tech_clean"
},
"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.10.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
1,346 changes: 1,346 additions & 0 deletions demos/qiskit_patterns/2_qiskit_patterns.ipynb

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
181 changes: 181 additions & 0 deletions demos/qiskit_patterns/data/125node_example.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
\ This file has been generated by DOcplex
\ ENCODING=ISO-8859-1
\Problem name: CPLEX

Minimize
obj: [ - 8 x0^2 + 8 x0*x1 + 8 x0*x13 - 8 x1^2 + 8 x1*x2 - 8 x2*x3 + 8 x3*x4
- 4 x4^2 - 8 x4*x5 + 8 x4*x14 + 8 x5*x6 - 8 x6^2 + 8 x6*x7 - 8 x7^2
+ 8 x7*x8 - 12 x8^2 + 8 x8*x9 + 8 x8*x15 - 8 x9*x10 + 8 x10^2 - 8 x10*x11
+ 8 x11*x12 - 8 x12*x16 - 8 x13*x17 - 8 x14*x21 - 8 x15*x25 + 8 x16^2
- 8 x16*x29 + 8 x17*x18 - 8 x18^2 + 8 x18*x19 + 4 x19^2 - 8 x19*x20
- 8 x19*x32 + 8 x20*x21 - 4 x21^2 + 8 x21*x22 - 8 x22^2 + 8 x22*x23
- 12 x23^2 + 8 x23*x24 + 8 x23*x33 - 8 x24^2 + 8 x24*x25 + 4 x25^2
- 8 x25*x26 + 8 x26*x27 - 4 x27^2 + 8 x27*x28 - 8 x27*x34 - 8 x28*x29
+ 12 x29^2 - 8 x29*x30 + 8 x30^2 - 8 x30*x31 + 8 x31^2 - 8 x31*x35
+ 8 x32*x38 - 8 x33*x42 + 8 x34^2 - 8 x34*x46 + 8 x35^2 - 8 x35*x50
- 8 x36^2 + 8 x36*x37 + 8 x36*x51 - 8 x37*x38 - 4 x38^2 + 8 x38*x39
- 8 x39*x40 + 12 x40^2 - 8 x40*x41 - 8 x40*x52 + 8 x41^2 - 8 x41*x42
+ 12 x42^2 - 8 x42*x43 + 8 x43*x44 - 4 x44^2 + 8 x44*x45 - 8 x44*x53
- 8 x45*x46 + 12 x46^2 - 8 x46*x47 + 8 x47*x48 + 4 x48^2 - 8 x48*x49
- 8 x48*x54 + 8 x49^2 - 8 x49*x50 + 8 x50^2 - 8 x51^2 + 8 x51*x55
+ 8 x52*x59 + 8 x53^2 - 8 x53*x63 + 8 x54*x67 - 8 x55^2 + 8 x55*x56
- 8 x56^2 + 8 x56*x57 - 4 x57^2 - 8 x57*x58 + 8 x57*x70 + 8 x58^2
- 8 x58*x59 - 4 x59^2 + 8 x59*x60 - 8 x60^2 + 8 x60*x61 - 4 x61^2
- 8 x61*x62 + 8 x61*x71 + 8 x62^2 - 8 x62*x63 + 4 x63^2 + 8 x63*x64
- 8 x64^2 + 8 x64*x65 + 4 x65^2 - 8 x65*x66 - 8 x65*x72 + 8 x66*x67
- 12 x67^2 + 8 x67*x68 - 8 x68^2 + 8 x68*x69 - 8 x69^2 + 8 x69*x73
- 8 x70^2 + 8 x70*x76 - 8 x71^2 + 8 x71*x80 + 8 x72*x84 - 8 x73*x88
- 8 x74*x75 + 8 x74*x89 + 8 x75*x76 - 12 x76^2 + 8 x76*x77 - 8 x77*x78
+ 4 x78^2 + 8 x78*x79 - 8 x78*x90 - 8 x79^2 + 8 x79*x80 - 4 x80^2
- 8 x80*x81 + 8 x81^2 - 8 x81*x82 - 4 x82^2 + 8 x82*x83 + 8 x82*x91
- 8 x83^2 + 8 x83*x84 - 12 x84^2 + 8 x84*x85 - 8 x85^2 + 8 x85*x86
- 4 x86^2 + 8 x86*x87 - 8 x86*x92 - 8 x87^2 + 8 x87*x88 - 8 x89*x93
+ 8 x90^2 - 8 x90*x97 - 8 x91*x101 + 8 x92^2 - 8 x92*x105 + 8 x93^2
- 8 x93*x94 + 8 x94*x95 - 12 x95^2 + 8 x95*x96 + 8 x95*x108 - 8 x96*x97
+ 4 x97^2 + 8 x97*x98 - 8 x98*x99 + 12 x99^2 - 8 x99*x100 - 8 x99*x109
+ 8 x100*x101 - 4 x101^2 + 8 x101*x102 - 8 x102^2 + 8 x102*x103 + 4 x103^2
- 8 x103*x104 - 8 x103*x110 + 8 x104*x105 + 4 x105^2 - 8 x105*x106
+ 8 x106^2 - 8 x106*x107 + 8 x107^2 - 8 x107*x111 - 8 x108*x112
+ 8 x109*x116 + 8 x110^2 - 8 x110*x120 + 8 x111*x124 + 8 x112^2
- 8 x112*x113 + 8 x113*x114 - 8 x114*x115 + 8 x115^2 - 8 x115*x116
- 4 x116^2 + 8 x116*x117 - 8 x117^2 + 8 x117*x118 - 8 x118*x119
+ 8 x119*x120 + 4 x120^2 - 8 x120*x121 + 8 x121^2 - 8 x121*x122 + 8 x122^2
- 8 x122*x123 + 8 x123*x124 - 8 x124^2 ]/2 + 4
Subject To

Bounds
0 <= x0 <= 1
0 <= x1 <= 1
0 <= x2 <= 1
0 <= x3 <= 1
0 <= x4 <= 1
0 <= x5 <= 1
0 <= x6 <= 1
0 <= x7 <= 1
0 <= x8 <= 1
0 <= x9 <= 1
0 <= x10 <= 1
0 <= x11 <= 1
0 <= x12 <= 1
0 <= x13 <= 1
0 <= x14 <= 1
0 <= x15 <= 1
0 <= x16 <= 1
0 <= x17 <= 1
0 <= x18 <= 1
0 <= x19 <= 1
0 <= x20 <= 1
0 <= x21 <= 1
0 <= x22 <= 1
0 <= x23 <= 1
0 <= x24 <= 1
0 <= x25 <= 1
0 <= x26 <= 1
0 <= x27 <= 1
0 <= x28 <= 1
0 <= x29 <= 1
0 <= x30 <= 1
0 <= x31 <= 1
0 <= x32 <= 1
0 <= x33 <= 1
0 <= x34 <= 1
0 <= x35 <= 1
0 <= x36 <= 1
0 <= x37 <= 1
0 <= x38 <= 1
0 <= x39 <= 1
0 <= x40 <= 1
0 <= x41 <= 1
0 <= x42 <= 1
0 <= x43 <= 1
0 <= x44 <= 1
0 <= x45 <= 1
0 <= x46 <= 1
0 <= x47 <= 1
0 <= x48 <= 1
0 <= x49 <= 1
0 <= x50 <= 1
0 <= x51 <= 1
0 <= x52 <= 1
0 <= x53 <= 1
0 <= x54 <= 1
0 <= x55 <= 1
0 <= x56 <= 1
0 <= x57 <= 1
0 <= x58 <= 1
0 <= x59 <= 1
0 <= x60 <= 1
0 <= x61 <= 1
0 <= x62 <= 1
0 <= x63 <= 1
0 <= x64 <= 1
0 <= x65 <= 1
0 <= x66 <= 1
0 <= x67 <= 1
0 <= x68 <= 1
0 <= x69 <= 1
0 <= x70 <= 1
0 <= x71 <= 1
0 <= x72 <= 1
0 <= x73 <= 1
0 <= x74 <= 1
0 <= x75 <= 1
0 <= x76 <= 1
0 <= x77 <= 1
0 <= x78 <= 1
0 <= x79 <= 1
0 <= x80 <= 1
0 <= x81 <= 1
0 <= x82 <= 1
0 <= x83 <= 1
0 <= x84 <= 1
0 <= x85 <= 1
0 <= x86 <= 1
0 <= x87 <= 1
0 <= x88 <= 1
0 <= x89 <= 1
0 <= x90 <= 1
0 <= x91 <= 1
0 <= x92 <= 1
0 <= x93 <= 1
0 <= x94 <= 1
0 <= x95 <= 1
0 <= x96 <= 1
0 <= x97 <= 1
0 <= x98 <= 1
0 <= x99 <= 1
0 <= x100 <= 1
0 <= x101 <= 1
0 <= x102 <= 1
0 <= x103 <= 1
0 <= x104 <= 1
0 <= x105 <= 1
0 <= x106 <= 1
0 <= x107 <= 1
0 <= x108 <= 1
0 <= x109 <= 1
0 <= x110 <= 1
0 <= x111 <= 1
0 <= x112 <= 1
0 <= x113 <= 1
0 <= x114 <= 1
0 <= x115 <= 1
0 <= x116 <= 1
0 <= x117 <= 1
0 <= x118 <= 1
0 <= x119 <= 1
0 <= x120 <= 1
0 <= x121 <= 1
0 <= x122 <= 1
0 <= x123 <= 1
0 <= x124 <= 1

Binaries
x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21
x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41
x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61
x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81
x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 x100
x101 x102 x103 x104 x105 x106 x107 x108 x109 x110 x111 x112 x113 x114 x115 x116
x117 x118 x119 x120 x121 x122 x123 x124
End
Binary file added demos/qiskit_patterns/data/125node_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e97d744

Please sign in to comment.