-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0737b86
commit 3d50c77
Showing
5 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import Optional | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def plot_line_threshold( | ||
ax: plt.Axes, | ||
phys_prob: np.ndarray, | ||
log_prob: np.ndarray, | ||
log_prob_lower: Optional[np.ndarray] = None, | ||
log_prob_upper: Optional[np.ndarray] = None, | ||
label: Optional[str] = None, | ||
color: Optional[str] = "blue", | ||
) -> plt.Axes: | ||
"""Plots the logical error probability as a function of the physiscal | ||
error probability, including its upper and lower error bars (if given). | ||
Parameters | ||
---------- | ||
ax | ||
Matplotlib axis in which to plot. | ||
phys_prob | ||
Physical error probabilities. | ||
log_prob | ||
Logical error probability. | ||
log_prob_lower | ||
Lower bound on the logical error probability uncertainty. | ||
log_prob_upper | ||
Upper bound on the logical error probability uncertainty. | ||
label | ||
Label for the data. By default, no label. | ||
color | ||
Color for the data. By default, blue. | ||
Returns | ||
------- | ||
ax | ||
Matplotlib axis. | ||
""" | ||
ax.plot(phys_prob, log_prob, ".", color=color, label=label) | ||
if (log_prob_lower is not None) and (log_prob_upper is not None): | ||
ax.fill_between( | ||
phys_prob, log_prob_lower, log_prob_upper, color=color, alpha=0.1 | ||
) | ||
|
||
ax.set_xscale("log") | ||
ax.set_yscale("log") | ||
ax.set_xlabel("physical error probability, $p$") | ||
ax.set_ylabel("logical error probability, $p_L$") | ||
if label is not None: | ||
ax.legend(loc="best") | ||
|
||
return ax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def pytest_addoption(parser): | ||
parser.addoption("--show-figures", action="store_true") | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
# This is called for every test. Only get/set command line arguments | ||
# if the argument is specified in the list of test "fixturenames". | ||
# The hyphens in the arguments are substutited by underscores. | ||
option_value = metafunc.config.option.show_figures | ||
if "show_figures" in metafunc.fixturenames and option_value is not None: | ||
metafunc.parametrize("show_figures", [bool(option_value)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from qec_util.performance.plots import plot_line_threshold | ||
|
||
|
||
def test_plot_line_threshold(show_figures): | ||
phys_prob = np.linspace(1, 4, 10) | ||
log_prob = np.linspace(1, 6, 10) | ||
log_prob_lower = log_prob - 1 | ||
log_prob_upper = log_prob + 2 | ||
|
||
_, ax = plt.subplots() | ||
ax = plot_line_threshold( | ||
ax, | ||
phys_prob, | ||
log_prob, | ||
log_prob_lower, | ||
log_prob_upper, | ||
color="red", | ||
label="example", | ||
) | ||
|
||
if show_figures: | ||
plt.show() | ||
plt.close() | ||
|
||
assert isinstance(ax, plt.Axes) |