Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
5743454
Mitigation experiment initial commit
gadial Oct 4, 2021
9274c65
Added mitigation analysis
gadial Oct 5, 2021
d18da24
Merge branch 'main' into readout_mitigation_experiment
gadial Oct 5, 2021
7105122
Small fixes to ensure figures are generated
gadial Oct 6, 2021
ca1f05f
Linting
gadial Oct 6, 2021
ef04532
Adding tensored mitigation as parallel experiment
gadial Oct 10, 2021
b9f7315
Changing method into class
gadial Oct 10, 2021
96f298e
Bug fixes
gadial Oct 10, 2021
f11ebec
Restructuring to avoid reliance on composite experiment, and simplify…
gadial Oct 12, 2021
71e2447
Refactor mitigation experiment to have two experiment classes
gadial Oct 13, 2021
3542bee
RB Interleaved element fix (#399)
gadial Oct 5, 2021
e02dced
Allow splitting of jobs for all backends (#402)
chriseclectic Oct 8, 2021
93e01a8
FineAmp without schedules (#420)
eggerdj Oct 10, 2021
791e7b1
Fix bug in curve_fit for sigma=None (#422)
chriseclectic Oct 11, 2021
84b4884
Fix bug in DbExperimentData._retrieve_data (#421)
chriseclectic Oct 11, 2021
48964a4
Add analysis callback to ExperimentData (#407)
chriseclectic Oct 11, 2021
759423e
Add default pre-processing to curve analysis (#409)
Oct 14, 2021
51883d8
Improve calibration experiments (#251)
eggerdj Oct 14, 2021
b4ca5ac
english (#429)
yaelbh Oct 18, 2021
4a9cd33
PR for saving and loading composite experiments (#364)
yaelbh Oct 19, 2021
307f8ac
Bump terra to the most recent master (#426)
eggerdj Oct 19, 2021
82237ed
Make verify_headers verify files in the test folder (#433)
yaelbh Oct 20, 2021
f4d333f
Fix bug with ExperimentData.load (#423)
chriseclectic Oct 20, 2021
0c2540a
* Fix issue 430 (#434)
eggerdj Oct 21, 2021
b36d829
* Added loading bug fix and corresponding test. (#444)
eggerdj Oct 21, 2021
15703ba
* Added tearDown. (#449)
eggerdj Oct 21, 2021
e1f3baf
Adjust tomography doc strings to automatic template (#375)
dekelmeirom Oct 21, 2021
99c30e3
Drag fit instability (#450)
eggerdj Oct 22, 2021
3fd67b9
Amp cal refactor (#439)
eggerdj Oct 22, 2021
c61dd72
Fix DB display for non-float values (#301)
chriseclectic Oct 24, 2021
6691790
remove double test (#454)
dekelmeirom Oct 24, 2021
e26f79a
Update computation of probability (#424)
Oct 25, 2021
10f7ee5
Documentation patch for PR424 (#458)
Oct 25, 2021
4a3a6bd
Cleaned up composite_analysis.py (#443)
yaelbh Oct 26, 2021
4e583d0
Hack for non-existing parent id (#461)
yaelbh Oct 26, 2021
d1f7102
Remove ``experiment_data`` from ``BaseExperiment.run`` (#463)
chriseclectic Oct 27, 2021
6e4a088
Add backend property to experiments (#462)
chriseclectic Oct 27, 2021
6a53904
Add ExperimentConfig dataclass (#469)
chriseclectic Oct 28, 2021
ed4a649
Half angle (#418)
eggerdj Nov 1, 2021
9afe49a
Rabi refactor (#466)
eggerdj Nov 2, 2021
49d2fc5
Add ``replace_results`` kwarg to ``BaseAnalysis.run`` (#464)
chriseclectic Nov 2, 2021
7408bd4
Fix typos in t1/t2 experiments (#480)
wshanks Nov 2, 2021
d77027c
T1 T2 analysis migration (#427)
Nov 3, 2021
132ec22
Added 0/1 cals for fine sx amp (#483)
eggerdj Nov 3, 2021
a4e1724
Fix output array shape of SVD data processing node (#476)
Nov 3, 2021
2bf4080
Edge-case: fitting constant y values with decay analysis (#487)
Nov 3, 2021
e445179
Small fixes from recent PRs (#489)
chriseclectic Nov 3, 2021
0ad3a8b
Drag cal refactor (#473)
eggerdj Nov 4, 2021
c88d1b8
Ramsey refactor. (#485)
eggerdj Nov 4, 2021
1ab5526
Fix some typos in warnings (#493)
wshanks Nov 4, 2021
a8073f1
Add child data support to ExperimentData (#451)
chriseclectic Nov 4, 2021
d615116
BaseExperiment to accept only a list of qubits (#431)
yaelbh Nov 5, 2021
5bf6cb3
Replace `str(uuid4())` with `uuid4().hex` (#492)
chriseclectic Nov 5, 2021
4c33074
Revert "Replace `str(uuid4())` with `uuid4().hex` (#492)" (#501)
chriseclectic Nov 5, 2021
6127b99
Fine drag cal refactor (#519)
eggerdj Nov 10, 2021
19c4687
Fix storing of component metadata in composite experiment (#510)
chriseclectic Nov 11, 2021
aeb7002
Consolidate the analysis classes in characterization. (#523)
eggerdj Nov 11, 2021
796d961
Add ``Settings`` mixin class (#520)
chriseclectic Nov 11, 2021
6ffec24
Refactor where the calibration metadata is stored. (#524)
eggerdj Nov 12, 2021
3baeba4
Improve JSON encoder and decoder (#470)
chriseclectic Nov 12, 2021
2e4ce47
Move error about less than three points from T1 to DecayAnalysis (#490)
yaelbh Nov 15, 2021
034af81
Save-load test and bug fixes (#467)
yaelbh Nov 16, 2021
86caa84
Test counts in composite experiments (#506)
yaelbh Nov 17, 2021
5722020
Bug fix: T1 and T2Ramsey don't run correctly on devices (#529)
yaelbh Nov 19, 2021
2fdc091
Recursive methods for adding and removing tags (#522)
yaelbh Nov 21, 2021
bef39f3
Readout angle experiment (#525)
yaelbh Nov 22, 2021
6a07cef
Update ``ExperimentData.analysis_results`` to be blocking by default …
chriseclectic Nov 24, 2021
a4f1730
Serialize the basis gate library (#539)
eggerdj Nov 30, 2021
4323a13
Data processor with uncertainties package (#481)
Dec 1, 2021
6cc59d9
ignore assigning-non-slot (#553)
Dec 3, 2021
c40399d
Clean-up of Base calibration experiments (#547)
eggerdj Dec 3, 2021
a76a9ab
Change config from property to method (#555)
chriseclectic Dec 6, 2021
c6bfd69
Add StoreInitArgs mixin (#554)
chriseclectic Dec 6, 2021
bbc6fab
Start of BaseAnalysis refactor (#517)
chriseclectic Dec 6, 2021
06de788
Analysis refactor part 2 (#556)
chriseclectic Dec 6, 2021
fea0b8b
small fixes
gadial Oct 18, 2021
d2afad0
Merge branch 'main' into readout_mitigation_experiment
gadial Dec 7, 2021
061d7d5
Change to deprecated analysis class usage
gadial Dec 7, 2021
2d428c6
Analysis returns mitigator object instead of matrices
gadial Dec 7, 2021
c5cf27c
Refactoring mitigation experiment
gadial Dec 7, 2021
ad79c58
Refactoring mitigation analysis
gadial Dec 7, 2021
c01f8b4
Linting
gadial Dec 7, 2021
5e1694d
Linting
gadial Dec 7, 2021
c1f6715
Linting
gadial Dec 7, 2021
a980cf0
Linting
gadial Dec 7, 2021
4e53fb3
Mitigation tutorial notebook
gadial Jan 2, 2022
bb2b401
Mitigation tutorial notebook update
gadial Jan 3, 2022
c63d2dc
Mitigation experiment tests
gadial Jan 4, 2022
8db2f87
Linting
gadial Jan 4, 2022
9881b7a
Merge branch 'main' into readout_mitigation_experiment
gadial Jan 4, 2022
ab18872
Changes to visualization
gadial Jan 4, 2022
d000227
Bugfix
gadial Jan 5, 2022
f5c2b26
Linting
gadial Jan 5, 2022
9dcc71e
Avoiding failing test due to small bug in Terra
gadial Jan 5, 2022
f16e344
Linting
gadial Jan 5, 2022
d06d6ce
Linting
gadial Jan 5, 2022
b103443
Refactoring
gadial Jan 10, 2022
29b9765
Tutorial texts
gadial Jan 10, 2022
15a9a20
Merge branch 'main' into readout_mitigation_experiment
gadial Jan 10, 2022
a220d25
Merge branch 'main' into readout_mitigation_experiment
gadial Jan 10, 2022
f4627e3
Plot fix
gadial Jan 12, 2022
bb2d459
Release note
gadial Jan 13, 2022
86bdc95
Merge branch 'main' into readout_mitigation_experiment
gadial Jan 13, 2022
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
419 changes: 419 additions & 0 deletions docs/tutorials/readout_mitigation.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions qiskit_experiments/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class instance to manage parameters and pulse schedules.
from .randomized_benchmarking import StandardRB, InterleavedRB
from .tomography import StateTomography, ProcessTomography
from .quantum_volume import QuantumVolume
from .mitigation import ReadoutMitigationExperiment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readout error experiments needsto be added to the doc string of this init file to show up in the API docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do they fit in? Characterization experiments?


# Experiment Sub-modules
from . import calibration
Expand Down
41 changes: 41 additions & 0 deletions qiskit_experiments/library/mitigation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
===============================================================================================
Readout Mitigation Experiments (:mod:`qiskit_experiments.library.mitigation`)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this show up anywhere in the build docs because its not included in any other init files. The library section is where users see a list of experiments in the API docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

===============================================================================================

.. currentmodule:: qiskit_experiments.library.mitigation

Experiment
===========
.. autosummary::
:toctree: ../stubs/
:template: autosummary/experiment.rst

ReadoutMitigationExperiment


Analysis
========

.. autosummary::
:toctree: ../stubs/
:template: autosummary/analysis.rst

CorrelatedMitigationAnalysis
LocalMitigationAnalysis
"""
from .mitigation_experiment import ReadoutMitigationExperiment
from .mitigation_analysis import CorrelatedMitigationAnalysis
from .mitigation_analysis import LocalMitigationAnalysis
161 changes: 161 additions & 0 deletions qiskit_experiments/library/mitigation/mitigation_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""
Measurement calibration analysis classes
"""
from typing import List, Tuple
import numpy as np
import matplotlib.pyplot as plt
from qiskit.result import CorrelatedReadoutMitigator
from qiskit.result import LocalReadoutMitigator
from qiskit.result import marginal_counts
from qiskit_experiments.framework import ExperimentData
from qiskit_experiments.framework.matplotlib import get_non_gui_ax
from qiskit_experiments.framework import BaseAnalysis, AnalysisResultData, Options


class CorrelatedMitigationAnalysis(BaseAnalysis):
"""
Measurement correction analysis for a full calibration
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should be more descriptive. On what the analysis is so someone not familiar with the experiment can read it and know what it does.

In this case it constructs a readout error assignment matrix for possibly correlated N-qubit measurment outcomes (and you can put in an equation). It should also mention what hte analysis results returned are (in this case the CorrelatedMitigator class and include a link to the terra API docs for that class).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""

def _run_analysis(
self, experiment_data: ExperimentData, **options
) -> Tuple[List[AnalysisResultData], List["matplotlib.figure.Figure"]]:
data = experiment_data.data()
qubits = experiment_data.metadata["physical_qubits"]
labels = [datum["metadata"]["label"] for datum in data]
matrix = self._generate_matrix(data, labels)
result_mitigator = CorrelatedReadoutMitigator(matrix, qubits=qubits)
analysis_results = [AnalysisResultData("Correlated Readout Mitigator", result_mitigator)]
ax = options.get("ax", None)
figures = [self._plot_calibration(matrix, labels, ax)]
return analysis_results, figures

def _generate_matrix(self, data, labels) -> np.array:
list_size = len(labels)
matrix = np.zeros([list_size, list_size], dtype=float)
# matrix[i][j] is the probability of counting i for expected j
for datum in data:
expected_outcome = datum["metadata"]["label"]
j = labels.index(expected_outcome)
total_counts = sum(datum["counts"].values())
for measured_outcome, count in datum["counts"].items():
i = labels.index(measured_outcome)
matrix[i][j] = count / total_counts
return matrix

def _plot_calibration(self, matrix, labels, ax=None) -> "matplotlib.figure.Figure":
"""
Plot the calibration matrix (2D color grid plot).

Args:
matrix: calibration matrix to plot
ax (matplotlib.axes): settings for the graph

Returns:
The generated plot of the calibration matrix

Raises:
QiskitError: if _cal_matrices was not set.

ImportError: if matplotlib was not installed.

"""

if ax is None:
ax = get_non_gui_ax()
figure = ax.get_figure()
ax.matshow(matrix, cmap=plt.cm.binary, clim=[0, 1])
ax.set_xlabel("Prepared State")
ax.xaxis.set_label_position("top")
ax.set_ylabel("Measured State")
ax.set_xticks(np.arange(len(labels)))
ax.set_yticks(np.arange(len(labels)))
ax.set_xticklabels(labels)
ax.set_yticklabels(labels)
return figure


class LocalMitigationAnalysis(BaseAnalysis):
"""
Measurement correction analysis for a full calibration
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. This is missing proper API docs explaining what it does, what it returns, and link to the mitigator class returns.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""

@classmethod
def _default_options(cls) -> Options:
"""Return default analysis options.

Analysis Options:
plot (bool): Set ``True`` to create figure for fit result.
ax(AxesSubplot): Optional. A matplotlib axis object to draw.
"""
options = super()._default_options()
options.plot = True
options.ax = None
return options

def _run_analysis(
self, experiment_data: ExperimentData
) -> Tuple[List[AnalysisResultData], List["matplotlib.figure.Figure"]]:
data = experiment_data.data()
qubits = experiment_data.metadata["physical_qubits"]
matrices = self._generate_matrices(data)
result_mitigator = LocalReadoutMitigator(matrices, qubits=qubits)
analysis_results = [AnalysisResultData("Local Readout Mitigator", result_mitigator)]
if self.options.plot:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these classes produce a figure that should also be mentioned in the API docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

figure = assignment_matrix_visualization(
result_mitigator.assignment_matrix(), ax=self.options.ax
)
figures = [figure]
else:
figures = None
return analysis_results, figures

def _generate_matrices(self, data) -> List[np.array]:
num_qubits = len(data[0]["metadata"]["label"])
counts = [None, None]
for result in data:
for i in range(2):
if result["metadata"]["label"] == str(i) * num_qubits:
counts[i] = result["counts"]
matrices = []
for k in range(num_qubits):
matrix = np.zeros([2, 2], dtype=float)
marginalized_counts = []
for i in range(2):
marginalized_counts.append(marginal_counts(counts[i], [k]))
# matrix[i][j] is the probability of counting i for expected j
for i in range(2):
for j in range(2):
matrix[i][j] = marginalized_counts[j][str(i)] / sum(
marginalized_counts[j].values()
)
matrices.append(matrix)
return matrices


def assignment_matrix_visualization(assignment_matrix, ax=None):
"""Displays a visualization of the assignment matrix compared to the identity"""
if ax is None:
ax = get_non_gui_ax()
figure = ax.get_figure()
n = len(assignment_matrix)
diff = np.abs(assignment_matrix - np.eye(n))
im2 = ax.matshow(diff, cmap=plt.cm.Reds, vmin=0, vmax=0.2)
ax.set_yticks(np.arange(n))
ax.set_xticks(np.arange(n))
ax.set_yticklabels(n * [""])
ax.set_xticklabels(n * [""])
ax.set_xlabel(r"$|A - I|$", fontsize=16)
figure.colorbar(im2, ax=ax)
return figure
114 changes: 114 additions & 0 deletions qiskit_experiments/library/mitigation/mitigation_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""
Measurement calibration experiment classes.
"""
from typing import Iterable, List

from qiskit import QuantumCircuit
from qiskit.exceptions import QiskitError
from qiskit_experiments.framework import BaseExperiment
from .mitigation_analysis import CorrelatedMitigationAnalysis, LocalMitigationAnalysis


class ReadoutMitigationExperiment(BaseExperiment):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really think this is a good name for the experiment because it sounds like you are applying mitigation, when in fact you are characterizing readout error so you can use that to apply mitigation later. It should be ReadoutErrorExperiment.

I would also have two separate experiment classes for the user LocalReadoutErrorExperiment and CorrelatedReadoutErrorExperiment since in the current code the only option is the method, you might as well just make them separate experiments so you can have clearer API documentation for each case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Class for readout mitigation experiments"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is missing API documentation. It should have some description of what the experiment is and a reference to relevant paper and analysis class ie like this


METHOD_LOCAL = "local"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these need to be stored as a class variable? You can just put the value in the method and allowed values should be listed in the API docs. If you make two separate experiment classes you also dont need it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that making two separate experiments makes things much simpler; this is also addressed in #611

METHOD_CORRELATED = "correlated"
ALL_METHODS = [METHOD_LOCAL, METHOD_CORRELATED]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ALL_METHODS = [METHOD_LOCAL, METHOD_CORRELATED]
_ALL_METHODS

This doesn't need to be public attribute, also unneeded with separate experiments


def __init__(self, qubits: Iterable[int], method=METHOD_LOCAL):
"""Initialize a mitigation experiment.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a mitigation experiment, its a characterization experiment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it should be moved to the characterization subdirectory?


Args:
qubits: The qubits being mitigated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not being mitigated. This should be something like The qubit measurements to characterize readout error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

method: A string denoting mitigation method

Raises:
QiskitError: if the given mitigation method is not recoginzed

Additional info:
The currently supported mitigation methods are:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The currently supported mitigation methods are:
Supported mitigation methods are:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though you can just remove this by making two experiments and putting all the relevent info into the experiments API docs

* "local": each qubit is mitigated by itself; this is the default method,
and assumes readout errors are independent for each qubits
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not indented correctly

Suggested change
and assumes readout errors are independent for each qubits
and assumes readout errors are independent for each qubits

* "correlated": All the qubits are mitigated together; this results in an exponentially
large mitigation matrix and so is useable only for a small number of qubits,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

but might be more accurate than local mitigation.
"""
super().__init__(qubits)
if method not in self.ALL_METHODS:
raise QiskitError("Method {} not recognized".format(method))
if method == self.METHOD_LOCAL:
self.helper = LocalMitigationHelper(self.num_qubits)
if method == self.METHOD_CORRELATED:
self.helper = CorrelatedMitigationHelper(self.num_qubits)

self.analysis = self.helper.analysis()

def circuits(self) -> List[QuantumCircuit]:
"""Returns the experiment's circuits"""
return [self._calibration_circuit(self.num_qubits, label) for label in self.helper.labels()]

@staticmethod
def _calibration_circuit(num_qubits: int, label: str) -> QuantumCircuit:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With separate experiments, this could just be a function use in both, rather than a method, since it doesn't access self at all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Return a calibration circuit.

This is an N-qubit circuit where N is the length of the label.
The circuit consists of X-gates on qubits with label bits equal to 1,
and measurements of all qubits.
"""
circ = QuantumCircuit(num_qubits, name="meas_mit_cal_" + label)
for i, val in enumerate(reversed(label)):
if val == "1":
circ.x(i)
circ.measure_all()
circ.metadata = {"label": label}
return circ


class CorrelatedMitigationHelper:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These classes aren't necessary. The analysis classes should be set directly in the experiment, there is no need to wrap it in a trivial method. Similarly for the labels function (which with separate experiments can just be put as a function).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Helper class for correlated mitigation experiment data"""

def __init__(self, num_qubits: int):
"""Creates the helper class
Args:
num_qubits: The number of qubits being mitigated
"""
self.num_qubits = num_qubits

def analysis(self):
"""Returns the analysis class for the mitigation"""
return CorrelatedMitigationAnalysis()

def labels(self) -> List[str]:
"""Returns the labels dictating the generation of the mitigation circuits"""
return [bin(j)[2:].zfill(self.num_qubits) for j in range(2 ** self.num_qubits)]


class LocalMitigationHelper:
"""Helper class for local mitigation experiment data"""

def __init__(self, num_qubits: int):
"""Creates the helper class
Args:
num_qubits: The number of qubits being mitigated
"""
self.num_qubits = num_qubits

def analysis(self):
"""Returns the analysis class for the mitigation"""
return LocalMitigationAnalysis()

def labels(self) -> List[str]:
"""Returns the labels dictating the generation of the mitigation circuits"""
return ["0" * self.num_qubits, "1" * self.num_qubits]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
Added a new experiment (`qiskit_experiments.library import ReadoutMitigationExperiment`)
for calibrating readout mitigators.
Loading