Skip to content

Commit

Permalink
Merge pull request #216 from Qiskit-Extensions/use-runtime
Browse files Browse the repository at this point in the history
Use Runtime for calibrations
  • Loading branch information
nonhermitian authored Sep 23, 2024
2 parents 30d35d0 + d29330c commit 0522d38
Show file tree
Hide file tree
Showing 63 changed files with 1,236 additions and 1,159 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
uses: conda-incubator/setup-miniconda@v3
with:
python-version: '3.9.16'
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
25 changes: 13 additions & 12 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ jobs:
conda-test:
name: Conda tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -el {0}
strategy:
max-parallel: 5
matrix:
os: [ubuntu-20.04, macos-11]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
auto-update-conda: true
python-version: ${{ matrix.python-version }}
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install dependencies
run: |
conda config --set always_yes yes --set changeps1 no
conda info
pip install -U -r requirements.txt -c constraints.txt
- name: Lint with pylint and pycodestyle
run: |
Expand All @@ -36,8 +37,8 @@ jobs:
pycodestyle --max-line-length=100 mthree
- name: Run tests with pytest
run: |
conda install pytest
python setup.py install
pip install pytest
pip install .
pytest -p no:warnings --pyargs mthree/test
- name: Build docs
run: |
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ over direct LU factorization (selection also depends on free memory).

.. jupyter-execute::

from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

backend = FakeCasablanca()
backend = FakeCasablancaV2()
mit = mthree.M3Mitigation(backend, iter_threshold=4321)


Expand Down
4 changes: 2 additions & 2 deletions docs/balanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ consider the balanced calibration circuits for 5 qubits:

.. jupyter-execute::

from qiskit_ibm_runtime.fake_provider import FakeAthens
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
import mthree

mthree.circuits.balanced_cal_strings(5)
Expand All @@ -33,7 +33,7 @@ matches the precison of the other methods. That is to say that the following:

.. jupyter-execute::

backend = FakeAthens()
backend = FakeAthensV2()
mit = mthree.M3Mitigation(backend)
mit.cals_from_system(method='balanced')

Expand Down
8 changes: 4 additions & 4 deletions docs/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ needed modules, and construct a circuit of interest.

import numpy as np
from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

qc = QuantumCircuit(6)
Expand All @@ -40,7 +40,7 @@ Next we calibrate an M3 mitigator instance over qubits 0 -> 6 (Step #1):

.. jupyter-execute::

backend = FakeCasablanca()
backend = FakeCasablancaV2()
mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(6))

Expand All @@ -67,9 +67,9 @@ provided that we select the correct layout.

.. jupyter-execute::

from qiskit_ibm_runtime.fake_provider import FakeMontreal
from qiskit_ibm_runtime.fake_provider import FakeMontrealV2

backend = FakeMontreal()
backend = FakeMontrealV2()
mit2 = mthree.M3Mitigation(backend)

In our case, ``qubits = [10, 12, 15, 13, 11, 14]`` is an appropriate layout. Importantly, the
Expand Down
4 changes: 2 additions & 2 deletions docs/cal_io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Let us generate some calibration data and save it.

.. jupyter-execute::

from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

backend = FakeCasablanca()
backend = FakeCasablancaV2()

mit = mthree.M3Mitigation(backend)
mit.cals_from_system([1, 3, 5], cals_file='my_cals.json')
Expand Down
4 changes: 2 additions & 2 deletions docs/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When you mitigate over multiple circuits the return object is a :class:`mthree.c
.. jupyter-execute::

from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

qc = QuantumCircuit(6)
Expand All @@ -22,7 +22,7 @@ When you mitigate over multiple circuits the return object is a :class:`mthree.c
qc.cx(1,2)
qc.measure_all()

backend = FakeCasablanca()
backend = FakeCasablancaV2()
mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(6))

Expand Down
4 changes: 2 additions & 2 deletions docs/error.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Let us first calibrate the mitigator and get raw results:
.. jupyter-execute::

from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

qc = QuantumCircuit(6)
Expand All @@ -31,7 +31,7 @@ Let us first calibrate the mitigator and get raw results:

.. jupyter-execute::

backend = FakeCasablanca()
backend = FakeCasablancaV2()
mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(6))

Expand Down
4 changes: 2 additions & 2 deletions docs/expvals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ a noisy-simulator.

import numpy as np
from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeAthens
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
import mthree

backend = FakeAthens()
backend = FakeAthensV2()

ghz2 = QuantumCircuit(2)
ghz2.h(0)
Expand Down
4 changes: 2 additions & 2 deletions docs/grouped.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ this consider the following simple example:
.. jupyter-execute::

from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeAthens
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
import mthree

qc = QuantumCircuit(4)
Expand All @@ -26,7 +26,7 @@ and, because we have transpiled, find the final measurement mapping:

.. jupyter-execute::

backend = FakeAthens()
backend = FakeAthensV2()
trans_circs = transpile([qc]*2, backend, optimization_level=3, approximation_degree=0)
mappings = mthree.utils.final_measurement_mapping(trans_circs)

Expand Down
4 changes: 2 additions & 2 deletions docs/marginals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Consider the following circuit that we would like to evaluate:
.. jupyter-execute::

from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeGuadalupe
from qiskit_ibm_runtime.fake_provider import FakeGuadalupeV2
import mthree

N = 6
Expand All @@ -35,7 +35,7 @@ Let us first map this onto the target system and compute the final measurement m

.. jupyter-execute::

backend = FakeGuadalupe()
backend = FakeGuadalupeV2()

trans_qc = transpile(qc, backend, optimization_level=3, seed_transpiler=12345)
mapping = mthree.utils.final_measurement_mapping(trans_qc)
Expand Down
4 changes: 2 additions & 2 deletions docs/probs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ done in linear time.
.. jupyter-execute::

from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

qc = QuantumCircuit(6)
Expand All @@ -28,7 +28,7 @@ done in linear time.
qc.cx(1,2)
qc.measure_all()

backend = FakeCasablanca()
backend = FakeCasablancaV2()
mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(6))

Expand Down
4 changes: 2 additions & 2 deletions docs/sampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"outputs": [],
"source": [
"from qiskit import *\n",
"from qiskit_ibm_runtime.fake_provider import FakeKolkata\n",
"from qiskit_ibm_runtime.fake_provider import FakeKolkataV2\n",
"\n",
"import mthree\n",
"\n",
Expand All @@ -41,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"backend = FakeKolkata()"
"backend = FakeKolkataV2()"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/transpiled.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For example consider the Bernstein-Vazirani circuit
.. jupyter-execute::

from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

qc = QuantumCircuit(5, 4)
Expand All @@ -32,7 +32,7 @@ embed the circuit and we must SWAP map it:

.. jupyter-execute::

backend = FakeCasablanca()
backend = FakeCasablancaV2()
trans_qc = transpile(qc, backend, optimization_level=3, seed_transpiler=12345)
trans_qc.draw('mpl')

Expand Down
8 changes: 4 additions & 4 deletions docs/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bits they correspond to. Here we show another example of this usage. First we
.. jupyter-execute::

from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeCasablanca
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree

qc = QuantumCircuit(7)
Expand All @@ -32,7 +32,7 @@ and then transpile it:

.. jupyter-execute::

backend = FakeCasablanca()
backend = FakeCasablancaV2()
trans_qc = transpile(qc, backend, optimization_level=3, seed_transpiler=54321)
trans_qc.draw('mpl')

Expand Down Expand Up @@ -66,8 +66,8 @@ For example let us compare raw data verse the mitigated results in a simple case

.. jupyter-execute::

from qiskit_ibm_runtime.fake_provider import FakeAthens
backend = FakeAthens()
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
backend = FakeAthensV2()
qc = QuantumCircuit(4)
qc.h(2)
qc.cx(2, 1)
Expand Down
19 changes: 9 additions & 10 deletions mthree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
from .version import version as __version__
from .version import openmp
except ImportError:
__version__ = '0.0.0'
__version__ = "0.0.0"
openmp = False

from .mitigation import M3Mitigation


def about():
"""The M3 version info function.
"""
print('='*80)
print('# Matrix-free Measurement Mitigation (M3) version {}'.format(__version__))
print('# (C) Copyright IBM 2021.')
print('# Paul Nation, Hwajung Kang, Neereja Sundaresan')
print('# Jay Gambetta, and Matthew Treinish.')
print('# Compiled with OpenMP: {}'.format(openmp))
print('='*80)
"""The M3 version info function."""
print("=" * 80)
print("# Matrix-free Measurement Mitigation (M3) version {}".format(__version__))
print("# (C) Copyright IBM 2021.")
print("# Paul Nation, Hwajung Kang, Neereja Sundaresan")
print("# Jay Gambetta, and Matthew Treinish.")
print("# Compiled with OpenMP: {}".format(openmp))
print("=" * 80)
37 changes: 13 additions & 24 deletions mthree/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"""
Helper functions
"""
from qiskit.providers import BackendV1, BackendV2
from qiskit.providers import BackendV2
from qiskit_ibm_runtime import IBMBackend
from mthree.exceptions import M3Error


Expand All @@ -28,32 +29,20 @@ def system_info(backend):
"""
info_dict = {}
info_dict["inoperable_qubits"] = []
if isinstance(backend, BackendV1):
config = backend.configuration()
info_dict["name"] = backend.name()
info_dict["num_qubits"] = config.num_qubits
info_dict["max_shots"] = config.max_shots
info_dict["simulator"] = config.simulator
# A hack for Qiskit/Terra #9572
if "fake" in info_dict["name"]:
info_dict["simulator"] = True
config = backend.configuration()
info_dict["name"] = backend.name
info_dict["num_qubits"] = config.num_qubits
_max_shots = backend.configuration().max_shots
info_dict["max_shots"] = _max_shots if _max_shots else int(1e6)

if isinstance(backend, IBMBackend):
info_dict["simulator"] = False
elif isinstance(backend, BackendV2):
info_dict["name"] = backend.name
info_dict["num_qubits"] = backend.num_qubits
_max_shots = backend.options.validator.get("shots", (None, None))[1]
info_dict["max_shots"] = _max_shots if _max_shots else int(1e9)
# Default to simulator is True for safety
info_dict["simulator"] = True
# This is a V2 coming from IBM provider
# No other way to tell outside of configuration
# E.g. how to tell that ibmq_qasm_simulator is sim, but real devices not
# outside of configuration?
if hasattr(backend, 'configuration'):
info_dict["simulator"] = backend.configuration().simulator
else:
raise M3Error('Invalid backend passed.')
raise M3Error("Invalid backend passed.")
# Look for faulty qubits. Renaming to 'inoperable' here
if hasattr(backend, 'properties'):
if hasattr(backend.properties(), 'faulty_qubits'):
if hasattr(backend, "properties"):
if hasattr(backend.properties(), "faulty_qubits"):
info_dict["inoperable_qubits"] = backend.properties().faulty_qubits()
return info_dict
Loading

0 comments on commit 0522d38

Please sign in to comment.