Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Runtime for calibrations #216

Merged
merged 41 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1d59d78
Use Runtime for calibrations
nonhermitian Sep 20, 2024
8b5f38a
move timestamp
nonhermitian Sep 20, 2024
83ffd68
lint
nonhermitian Sep 20, 2024
80eefb7
update fake backends to V2
nonhermitian Sep 20, 2024
1593eb1
correct for sims
nonhermitian Sep 21, 2024
5bd7b17
update tests
nonhermitian Sep 21, 2024
2951695
fix tests
nonhermitian Sep 21, 2024
d131401
fix test
nonhermitian Sep 21, 2024
8128676
fix test
nonhermitian Sep 21, 2024
f2fb4a5
try fixing props
nonhermitian Sep 21, 2024
6127dfd
allow for None
nonhermitian Sep 21, 2024
34cd9f0
fix
nonhermitian Sep 21, 2024
58b451b
fixes
nonhermitian Sep 23, 2024
2beef47
mark tests
nonhermitian Sep 23, 2024
b0cc9e1
lint
nonhermitian Sep 23, 2024
3943304
update docs
nonhermitian Sep 23, 2024
483f0d6
update tutorials
nonhermitian Sep 23, 2024
c680033
update system to newer one
nonhermitian Sep 23, 2024
5328c60
update to new runners
nonhermitian Sep 23, 2024
3a3d4d3
use latest
nonhermitian Sep 23, 2024
57c83a6
update workflow
nonhermitian Sep 23, 2024
2a45f20
try pip
nonhermitian Sep 23, 2024
648ae31
add numpy 2 to dev requirements
nonhermitian Sep 23, 2024
e6b4ae9
updates
nonhermitian Sep 23, 2024
102ebe7
attempt fix
nonhermitian Sep 23, 2024
5e5b069
try fixes
nonhermitian Sep 23, 2024
aaf0027
validate build is correct
nonhermitian Sep 23, 2024
a72e21a
force numpy upgrade
nonhermitian Sep 23, 2024
a3eb0de
fix pytest
nonhermitian Sep 23, 2024
25f7a8d
find
nonhermitian Sep 23, 2024
c5838e0
try new conda env
nonhermitian Sep 23, 2024
eebdf10
change order
nonhermitian Sep 23, 2024
2a269e4
add init
nonhermitian Sep 23, 2024
a3e9173
bash
nonhermitian Sep 23, 2024
d62e24b
try this
nonhermitian Sep 23, 2024
7bf863c
force conda numpy
nonhermitian Sep 23, 2024
d66bb67
remove check
nonhermitian Sep 23, 2024
2f7d6f2
pip numpy < 2
nonhermitian Sep 23, 2024
ce2a2af
updates
nonhermitian Sep 23, 2024
e5d8aa9
unpin numpy
nonhermitian Sep 23, 2024
d29330c
repin and be done with it
nonhermitian Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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