Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
nonhermitian committed Oct 8, 2024
1 parent d5a3532 commit 1ca0aaf
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 97 deletions.
6 changes: 3 additions & 3 deletions benchmarks/iterative.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@


def main():
with open('data/eagle_large_counts.json') as json_file:
with open("data/eagle_large_counts.json") as json_file:
counts = json.load(json_file)

mit = mthree.M3Mitigation()
mit.cals_from_file('data/eagle_large_cals.json')
mit.cals_from_file("data/eagle_large_cals.json")

st = time.perf_counter()
quasi = mit.apply_correction(counts, range(127), distance=3)
fin = time.perf_counter()
print(fin-st)
print(fin - st)


if __name__ == "__main__":
Expand Down
58 changes: 30 additions & 28 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@

rst_prolog = """
.. |version| replace:: {0}
""".format(m3.version.short_version)
""".format(
m3.version.short_version
)

# -- Project information -----------------------------------------------------
project = 'Mthree {}'.format(version)
copyright = '2021, Mthree Team' # pylint: disable=redefined-builtin
author = 'Mthree Development Team'
project = "Mthree {}".format(version)
copyright = "2021, Mthree Team" # pylint: disable=redefined-builtin
author = "Mthree Development Team"
# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand All @@ -58,21 +60,21 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.extlinks',
'nbsphinx',
'jupyter_sphinx',
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.extlinks",
"nbsphinx",
"jupyter_sphinx",
"qiskit_sphinx_theme",
]
templates_path = ['_templates']
templates_path = ["_templates"]
nbsphinx_timeout = 300
nbsphinx_execute = 'always'
nbsphinx_execute = "always"

exclude_patterns = ['_build', '**.ipynb_checkpoints']
exclude_patterns = ["_build", "**.ipynb_checkpoints"]

jupyter_execute_kwargs = dict(allow_errors=False)

Expand All @@ -85,7 +87,7 @@
# Autodoc
# -----------------------------------------------------------------------------

autoclass_content = 'init'
autoclass_content = "init"

# If true, figures, tables and code-blocks are automatically numbered if they
# have a caption.
Expand All @@ -94,15 +96,13 @@
# A dictionary mapping 'figure', 'table', 'code-block' and 'section' to
# strings that are used for format of figure numbers. As a special character,
# %s will be replaced to figure number.
numfig_format = {
'table': 'Table %s'
}
numfig_format = {"table": "Table %s"}
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# A boolean that decides whether module names are prepended to all object names
# (for object types where a “module” of some kind is defined), e.g. for
Expand All @@ -113,7 +113,7 @@
# (e.g., if this is set to ['foo.'], then foo.bar is shown under B, not F).
# This can be handy if you document a project that consists of a single
# package. Works only for the HTML builder currently.
modindex_common_prefix = ['mthree.']
modindex_common_prefix = ["mthree."]

# -- Configuration for extlinks extension ------------------------------------
# Refer to https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
Expand All @@ -128,23 +128,25 @@
html_title = f"{project}"


#html_sidebars = {'**': ['globaltoc.html']}
html_last_updated_fmt = '%Y/%m/%d'
# html_sidebars = {'**': ['globaltoc.html']}
html_last_updated_fmt = "%Y/%m/%d"


def load_tutorials(app):
dest_dir = os.path.join(app.srcdir, 'tutorials')
source_dir = os.path.dirname(app.srcdir)+'/tutorials'
dest_dir = os.path.join(app.srcdir, "tutorials")
source_dir = os.path.dirname(app.srcdir) + "/tutorials"

try:
copy_tree(source_dir, dest_dir)
except FileNotFoundError:
warnings.warn('Copy tutorials failed.', RuntimeWarning)
warnings.warn("Copy tutorials failed.", RuntimeWarning)


def clean_tutorials(app, exc):
tutorials_dir = os.path.join(app.srcdir, 'tutorials')
tutorials_dir = os.path.join(app.srcdir, "tutorials")
shutil.rmtree(tutorials_dir)


def setup(app):
load_tutorials(app)
app.connect('build-finished', clean_tutorials)
app.connect("build-finished", clean_tutorials)
9 changes: 4 additions & 5 deletions mthree/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def reduced_cal_matrix(mitigator, counts, qubits, distance=None):
return A, counts



def direct_solver(mitigator, counts, qubits, distance=None, return_mitigation_overhead=False):
def direct_solver(
mitigator, counts, qubits, distance=None, return_mitigation_overhead=False
):
"""Apply the mitigation using direct LU factorization.
Parameters:
Expand All @@ -69,9 +70,7 @@ def direct_solver(mitigator, counts, qubits, distance=None, return_mitigation_ov
"""
cals = mitigator._form_cals(qubits)
num_bits = len(qubits)
A, sorted_counts, col_norms = _reduced_cal_matrix(
counts, cals, num_bits, distance
)
A, sorted_counts, col_norms = _reduced_cal_matrix(counts, cals, num_bits, distance)
vec = counts_to_vector(sorted_counts)
LU = la.lu_factor(A, check_finite=False)
x = la.lu_solve(LU, vec, check_finite=False)
Expand Down
2 changes: 1 addition & 1 deletion mthree/iterative.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy as np
import scipy.sparse.linalg as spla

from mthree.norms import ainv_onenorm_est_iter
from mthree.norms import ainv_onenorm_est_iter
from mthree.matvec import M3MatVec
from mthree.utils import counts_to_vector, vector_to_quasiprobs
from mthree.exceptions import M3Error
Expand Down
20 changes: 10 additions & 10 deletions mthree/mitigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _form_cals(self, qubits):

# Reverse index qubits for easier indexing later
for kk, qubit in enumerate(qubits[::-1]):
cals[4 * kk: 4 * kk + 4] = self.single_qubit_cals[qubit].ravel()
cals[4 * kk : 4 * kk + 4] = self.single_qubit_cals[qubit].ravel()
return cals

def tensored_cals_from_system(
Expand Down Expand Up @@ -415,9 +415,9 @@ def _grab_additional_cals(
# Get the slice length
circ_slice = ceil(num_circs / num_jobs)
circs_list = [
trans_qcs[kk * circ_slice: (kk + 1) * circ_slice]
trans_qcs[kk * circ_slice : (kk + 1) * circ_slice]
for kk in range(num_jobs - 1)
] + [trans_qcs[(num_jobs - 1) * circ_slice:]]
] + [trans_qcs[(num_jobs - 1) * circ_slice :]]
# Do job submission here
jobs = []
if self.rep_delay:
Expand Down Expand Up @@ -618,9 +618,9 @@ def _apply_correction(

if method == "direct":
st = perf_counter()
mit_counts, col_norms, gamma = direct_solve(self, counts,
qubits, distance,
return_mitigation_overhead)
mit_counts, col_norms, gamma = direct_solve(
self, counts, qubits, distance, return_mitigation_overhead
)
dur = perf_counter() - st
mit_counts.shots = shots
if gamma is not None:
Expand All @@ -639,7 +639,8 @@ def callback(_):

if details:
st = perf_counter()
mit_counts, col_norms, gamma = iterative_solver(self,
mit_counts, col_norms, gamma = iterative_solver(
self,
counts,
qubits,
distance,
Expand All @@ -658,7 +659,8 @@ def callback(_):
info["col_norms"] = col_norms
return mit_counts, info
# pylint: disable=unbalanced-tuple-unpacking
mit_counts, gamma = iterative_solver(self,
mit_counts, gamma = iterative_solver(
self,
counts,
qubits,
distance,
Expand All @@ -676,7 +678,6 @@ def callback(_):
else:
raise M3Error("Invalid method: {}".format(method))


def reduced_cal_matrix(self, counts, qubits, distance=None):
"""Return the reduced calibration matrix used in the solution.
Expand All @@ -695,7 +696,6 @@ def reduced_cal_matrix(self, counts, qubits, distance=None):
"""
return cal_matrix(self, counts, qubits, distance)


def readout_fidelity(self, qubits=None):
"""Compute readout fidelity for calibrated qubits.
Expand Down
Loading

0 comments on commit 1ca0aaf

Please sign in to comment.