Skip to content

Commit

Permalink
[QI2-1137] add jupyter notebook demo (#43)
Browse files Browse the repository at this point in the history
Co-authored-by: napocornejo <[email protected]>
  • Loading branch information
napocornejo and napocornejo authored Oct 22, 2024
1 parent ab98f91 commit 742f181
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions notebooks/sample_notebook_qiskit_qi2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "48c6731f-5188-41c1-afc4-123c6ed796ae",
"metadata": {},
"source": [
"# Sample Notebook to test the Quantum Inspire 2 Qiskit Interface\n",
"This notebooks illustrates how you can run your qiskit code in the Quantum Inspire 2 platform.\n",
"### This notebook makes the following assumptions:\n",
"- quantuminspire2 sdk installed\n",
"- account exists in the QI2 platform\n",
"- qiskit plugin installed (pip install qiskit-quantuminspire) in the sam environment as this notebook"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93fe4f56-4ced-41fc-b778-14d6c95e2434",
"metadata": {},
"outputs": [],
"source": [
"# Be sure to have logged in to the QI2 platform via the SDK. If you have installed it in the same environment as \n",
"# this notebook, you may run this cell.\n",
"\n",
"!qi login \"https://staging.qi2.quantum-inspire.com\""
]
},
{
"cell_type": "markdown",
"id": "0d8ba9f9-9b38-4a86-9252-0b9b9fcdc83f",
"metadata": {},
"source": [
"### The necessary imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3d4b3950-fe75-47cf-afb5-2286be7c01b4",
"metadata": {},
"outputs": [],
"source": [
"from qiskit import QuantumCircuit\n",
"\n",
"from qiskit_quantuminspire.qi_provider import QIProvider"
]
},
{
"cell_type": "markdown",
"id": "0b464f03-9573-4c3c-852c-3ea4477b59ec",
"metadata": {},
"source": [
"### What QI Backends are available?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df119aa6-6b48-43a5-aa68-ecf4f7c0dc38",
"metadata": {},
"outputs": [],
"source": [
"provider = QIProvider()\n",
"\n",
"backends = []\n",
"print('The following backends are available:')\n",
"for backend in provider.backends():\n",
" print(f\"ID: [{backend.id}] \\t{backend.name} \")\n",
" backends.append(backend)"
]
},
{
"cell_type": "markdown",
"id": "a9f9b123-9b11-4d62-a4ab-8af8f08f7153",
"metadata": {},
"source": [
"### Create your Qiskit Circuit\n",
"Let's create the circuit for the Quantum Approximate Optimization Algorithm (QAOA)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6bbe6af-9908-46cb-8638-8f29966fbf61",
"metadata": {},
"outputs": [],
"source": [
"circuit = QuantumCircuit(3, 10)\n",
"circuit.h(0)\n",
"circuit.cnot(0, 1)\n",
"circuit.measure(0, 0)\n",
"circuit.measure(1, 1)"
]
},
{
"cell_type": "markdown",
"id": "a638262c-c785-4a4f-9ba2-32cc534225f3",
"metadata": {},
"source": [
"### Create the Job in the Quantum Inspire Platform\n",
"On the appropriate backend, you run your circuit. Be aware that if your circuit contains gates that are not supported by the target, compilation errors may arise."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1f446ddc-7fe6-4731-9840-da1775e10e0f",
"metadata": {},
"outputs": [],
"source": [
"backend = backends[2]\n",
"job = backend.run(circuit)"
]
},
{
"cell_type": "markdown",
"id": "9645611e-bd42-4814-9266-243676877e8d",
"metadata": {},
"source": [
"### Obtain the result \n",
"After a while the result should be available. Depending on the current load the time for completion may vary."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4302f110-e5c1-47ea-8e48-994db317a74c",
"metadata": {},
"outputs": [],
"source": [
"result = job.result()\n",
"print(result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0810c385-5cc8-4881-9d98-320da0cfe70e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 742f181

Please sign in to comment.