Skip to content

Commit

Permalink
Added IBM Eagle Access to QiskitQAOA
Browse files Browse the repository at this point in the history
* Added IBM Eagle Access to QiskitQAOA
* Adjusted range of iterations for QiskitQAOA in order to fit for IBM Eagle, since here a low number of iterations is necessary
* Added instructions to tutorial.rst on how to add IBM API Token
  • Loading branch information
chsowinski authored Mar 26, 2024
1 parent 0c3af12 commit 4eef3de
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
16 changes: 13 additions & 3 deletions .settings/module_db.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"build_number": 6,
"build_date": "22-11-2023 13:47:42",
"git_revision_number": "5ea1fcf56c438df4b32fcc318dcb6e2c8e58447b",
"build_number": 7,
"build_date": "20-03-2024 12:51:58",
"git_revision_number": "3be6f3847150d4bb8debee2451522b0b19fa205f",
"modules": [
{
"name": "PVC",
Expand Down Expand Up @@ -1863,6 +1863,16 @@
"module": "modules.devices.HelperClass",
"requirements": [],
"submodules": []
},
{
"name": "ibm_eagle",
"class": "HelperClass",
"args": {
"device_name": "ibm_eagle"
},
"module": "modules.devices.HelperClass",
"requirements": [],
"submodules": []
}
]
}
Expand Down
14 changes: 14 additions & 0 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ Example run (You need to check at least one option with an ``X`` for the checkbo
All used config files, logs and results are stored in a folder in the
``benchmark_runs`` directory.

Access to IBM Eagle
^^^^^^^^^^^^^^^^^^^

In order to use the IBM Eagle device in QUARK you have to first save your API token.
This can be done similar to accessing AWS:

.. code:: bash
export ibm_quantum_token='Your Token'
python src/main.py
::


Non-Interactive Mode
^^^^^^^^^^^^^^^^^^^^

Expand Down
26 changes: 18 additions & 8 deletions src/modules/solvers/QiskitQAOA.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
from typing import Tuple
from typing import TypedDict

import os
import numpy as np
from qiskit import Aer
from qiskit.algorithms import VQE, QAOA, NumPyMinimumEigensolver
from qiskit.algorithms.optimizers import POWELL, SPSA, COBYLA
from qiskit.circuit.library import TwoLocal
from qiskit.opflow import PauliSumOp
from qiskit_optimization.applications import OptimizationApplication
from qiskit_ibm_runtime import QiskitRuntimeService

from modules.solvers.Solver import *
from utils import start_time_measurement, end_time_measurement
Expand All @@ -37,7 +39,7 @@ def __init__(self):
Constructor method
"""
super().__init__()
self.submodule_options = ["qasm_simulator", "qasm_simulator_gpu"]
self.submodule_options = ["qasm_simulator", "qasm_simulator_gpu", "ibm_eagle"]

@staticmethod
def get_requirements() -> list[dict]:
Expand Down Expand Up @@ -69,6 +71,9 @@ def get_default_submodule(self, option: str) -> Core:
elif option == "qasm_simulator_gpu":
from modules.devices.HelperClass import HelperClass # pylint: disable=C0415
return HelperClass("qasm_simulator_gpu")
elif option == "ibm_eagle":
from modules.devices.HelperClass import HelperClass # pylint: disable=C0415
return HelperClass("ibm_eagle")
else:
raise NotImplementedError(f"Device Option {option} not implemented")

Expand All @@ -85,8 +90,8 @@ def get_parameter_options(self) -> dict:
"description": "How many shots do you need?"
},
"iterations": { # number measurements to make on circuit
"values": [10, 20, 50, 75],
"description": "How many iterations do you need?"
"values": [1, 5, 10, 20, 50, 75],
"description": "How many iterations do you need? Warning: When using the IBM Eagle Device you should only choose a lower number of iterations, since a high number would lead to a waiting time that could take up to mulitple days!"

Check failure on line 94 in src/modules/solvers/QiskitQAOA.py

View workflow job for this annotation

GitHub Actions / Pylint

src/modules/solvers/QiskitQAOA.py#L94

Line too long (273/120) (line-too-long, C0301)
},
"depth": {
"values": [2, 3, 4, 5, 10, 20],
Expand All @@ -98,7 +103,7 @@ def get_parameter_options(self) -> dict:
},
"optimizer": {
"values": ["POWELL", "SPSA", "COBYLA"],
"description": "Which Qiskit solver should be used?"
"description": "Which Qiskit solver should be used? Warning: When using the IBM Eagle Device you should not use the SPSA optimizer, since it is not suited for only one evaluation!"

Check failure on line 106 in src/modules/solvers/QiskitQAOA.py

View workflow job for this annotation

GitHub Actions / Pylint

src/modules/solvers/QiskitQAOA.py#L106

Line too long (224/120) (line-too-long, C0301)
}
}
Expand All @@ -109,8 +114,8 @@ def get_parameter_options(self) -> dict:
"description": "How many shots do you need?"
},
"iterations": { # number measurements to make on circuit
"values": [10, 20, 50, 75],
"description": "How many iterations do you need?"
"values": [1, 5, 10, 20, 50, 75],
"description": "How many iterations do you need? Warning: When using the IBM Eagle Device you should only choose a lower number of iterations, since a high number would lead to a waiting time that could take up to mulitple days!"

Check failure on line 118 in src/modules/solvers/QiskitQAOA.py

View workflow job for this annotation

GitHub Actions / Pylint

src/modules/solvers/QiskitQAOA.py#L118

Line too long (245/120) (line-too-long, C0301)
},
"depth": {
"values": [2, 3, 4, 5, 10, 20],
Expand All @@ -122,7 +127,7 @@ def get_parameter_options(self) -> dict:
},
"optimizer": {
"values": ["POWELL", "SPSA", "COBYLA"],
"description": "Which Qiskit solver should be used?"
"description": "Which Qiskit solver should be used? Warning: When using the IBM Eagle Device you should not use the SPSA optimizer for a low number of iterations!"

Check failure on line 130 in src/modules/solvers/QiskitQAOA.py

View workflow job for this annotation

GitHub Actions / Pylint

src/modules/solvers/QiskitQAOA.py#L130

Line too long (179/120) (line-too-long, C0301)
}
}

Expand Down Expand Up @@ -186,7 +191,7 @@ def run(self, mapped_problem: any, device_wrapper: any, config: Config, **kwargs
if config["optimizer"] == "COBYLA":
optimizer = COBYLA(maxiter=config["iterations"])
elif config["optimizer"] == "POWELL":
optimizer = POWELL(maxiter=config["iterations"])
optimizer = POWELL(maxiter=config["iterations"], maxfev=config["iterations"] if device_wrapper.device == 'ibm_eagle' else None)

Check failure on line 194 in src/modules/solvers/QiskitQAOA.py

View workflow job for this annotation

GitHub Actions / Pylint

src/modules/solvers/QiskitQAOA.py#L194

Line too long (143/120) (line-too-long, C0301)
elif config["optimizer"] == "SPSA":
optimizer = SPSA(maxiter=config["iterations"])
if config["method"] == "vqe":
Expand All @@ -208,6 +213,11 @@ def _get_quantum_instance(device_wrapper: any) -> any:
logging.info("Using GPU simulator")
backend.set_options(device='GPU')
backend.set_options(method='statevector_gpu')
elif device_wrapper.device == 'ibm_eagle':
logging.info("Using IBM Eagle")
ibm_quantum_token = os.environ.get('ibm_quantum_token')
service = QiskitRuntimeService(channel="ibm_quantum", token=ibm_quantum_token)
backend = service.least_busy(operational=True, simulator=False, min_num_qubits=127)
else:
logging.info("Using CPU simulator")
backend.set_options(device='CPU')
Expand Down

0 comments on commit 4eef3de

Please sign in to comment.