Skip to content

Commit 3e57636

Browse files
committed
Fix rebase / doc errors
1 parent 22f9f75 commit 3e57636

File tree

5 files changed

+57
-45
lines changed

5 files changed

+57
-45
lines changed

qiskit_experiments/base_analysis.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515

1616
from abc import ABC, abstractmethod
1717
from typing import List, Tuple
18-
import copy
1918

2019
from qiskit.providers.options import Options
2120
from qiskit.exceptions import QiskitError
2221

23-
from .experiment_data import ExperimentData, AnalysisResult
22+
from qiskit_experiments.experiment_data import ExperimentData, AnalysisResult
23+
24+
# pylint: disable = unused-import
25+
from qiskit_experiments.matplotlib import pyplot
2426

2527

2628
class BaseAnalysis(ABC):
@@ -40,25 +42,29 @@ class BaseAnalysis(ABC):
4042
def _default_options(cls) -> Options:
4143
return Options()
4244

43-
def run(self, experiment_data, save=True, return_figures=False, **options):
45+
def run(
46+
self,
47+
experiment_data: ExperimentData,
48+
save: bool = True,
49+
return_figures: bool = False,
50+
**options,
51+
):
4452
"""Run analysis and update ExperimentData with analysis result.
4553
4654
Args:
47-
experiment_data (ExperimentData): the experiment data to analyze.
48-
save (bool): if True save analysis results and figures to the
49-
:class:`ExperimentData`.
50-
return_figures (bool): if true return a pair of
51-
``(analysis_results, figures)``,
52-
otherwise return only analysis_results.
55+
experiment_data: the experiment data to analyze.
56+
save: if True save analysis results and figures to the
57+
:class:`ExperimentData`.
58+
return_figures: if true return a pair of
59+
``(analysis_results, figures)``,
60+
otherwise return only analysis_results.
5361
options: additional analysis options. See class documentation for
5462
supported options.
5563
5664
Returns:
57-
AnalysisResult: the output of the analysis that produces a
58-
single result.
5965
List[AnalysisResult]: the output for analysis that produces
6066
multiple results.
61-
tuple: If ``return_figures=True`` the output is a pair
67+
Tuple: If ``return_figures=True`` the output is a pair
6268
``(analysis_results, figures)`` where ``analysis_results``
6369
may be a single or list of :class:`AnalysisResult` objects, and
6470
``figures`` may be None, a single figure, or a list of figures.
@@ -102,7 +108,7 @@ def run(self, experiment_data, save=True, return_figures=False, **options):
102108
@abstractmethod
103109
def _run_analysis(
104110
self, experiment_data: ExperimentData, **options
105-
) -> Tuple[List[AnalysisResult], List["Figure"]]:
111+
) -> Tuple[List[AnalysisResult], List["pyplot.Figure"]]:
106112
"""Run analysis on circuit data.
107113
108114
Args:

qiskit_experiments/base_experiment.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
from typing import Union, Iterable, Optional, Tuple, List
1818
import copy
1919
from numbers import Integral
20-
from typing import List, Optional, Iterable, Tuple, Union
2120

2221
from qiskit import transpile, assemble, QuantumCircuit
2322
from qiskit.providers.options import Options
2423
from qiskit.providers.backend import Backend
2524
from qiskit.providers.basebackend import BaseBackend as LegacyBackend
2625
from qiskit.exceptions import QiskitError
27-
from qiskit.providers.backend import Backend
28-
from qiskit.providers.basebackend import BaseBackend as LegacyBackend
2926

3027
from .experiment_data import ExperimentData
3128

@@ -172,7 +169,7 @@ def physical_qubits(self) -> Tuple[int]:
172169
return self._physical_qubits
173170

174171
@classmethod
175-
def analysis(cls, **kwargs) -> "BaseAnalysis":
172+
def analysis(cls, **kwargs):
176173
"""Return the default Analysis class for the experiment."""
177174
if cls.__analysis_class__ is None:
178175
raise QiskitError(f"Experiment {cls.__name__} does not have a default Analysis class")
@@ -187,7 +184,7 @@ def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
187184
backend: Optional, a backend object.
188185
189186
Returns:
190-
A list of :class:`QuantumCircuit`s.
187+
A list of :class:`QuantumCircuit`.
191188
192189
.. note::
193190
These circuits should be on qubits ``[0, .., N-1]`` for an

qiskit_experiments/characterization/t1_experiment.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ class T1Analysis(BaseAnalysis):
3333
"""T1 Experiment result analysis class.
3434
3535
Analysis Options:
36-
t1_guess (float): Optional, an initial guess of T1
37-
amplitude_guess (float): Optional, an initial guess of the coefficient of the exponent
38-
offset_guess (float): Optional, an initial guess of the offset
39-
t1_bounds (list of two floats): Optional, lower bound and upper bound to T1
40-
amplitude_bounds (list of two floats): Optional, lower bound and upper bound to the amplitude
41-
offset_bounds (list of two floats): Optional, lower bound and upper bound to the offset
36+
37+
* t1_guess (float): Optional, an initial guess of T1.
38+
* amplitude_guess (float): Optional, an initial guess of the
39+
coefficient of the exponent.
40+
* offset_guess (float): Optional, an initial guess of the offset.
41+
* t1_bounds (list of two floats): Optional, lower bound and upper
42+
bound to T1.
43+
* amplitude_bounds (list of two floats): Optional, lower bound and upper
44+
bound to the amplitude.
45+
* offset_bounds (list of two floats): Optional, lower bound and
46+
upper bound to the offset.
4247
"""
4348

4449
@classmethod
@@ -62,6 +67,7 @@ def _run_analysis(
6267
t1_bounds=None,
6368
amplitude_bounds=None,
6469
offset_bounds=None,
70+
plot=True,
6571
) -> Tuple[AnalysisResult, None]:
6672
"""
6773
Calculate T1
@@ -70,17 +76,23 @@ def _run_analysis(
7076
experiment_data (ExperimentData): the experiment data to analyze
7177
t1_guess (float): Optional, an initial guess of T1
7278
amplitude_guess (float): Optional, an initial guess of the coefficient
73-
of the exponent
79+
of the exponent
7480
offset_guess (float): Optional, an initial guess of the offset
7581
t1_bounds (list of two floats): Optional, lower bound and upper bound to T1
76-
amplitude_bounds (list of two floats): Optional, lower bound and upper bound to the amplitude
77-
offset_bounds (list of two floats): Optional, lower bound and upper bound to the offset
82+
amplitude_bounds (list of two floats): Optional, lower bound and upper
83+
bound to the amplitude
84+
offset_bounds (list of two floats): Optional, lower bound and upper
85+
bound to the offset
86+
plot (bool): Generator plot of exponential fit.
7887
7988
Returns:
8089
The analysis result with the estimated T1
8190
"""
82-
unit = experiment_data._data[0]["metadata"]["unit"]
83-
conversion_factor = experiment_data._data[0]["metadata"].get("dt_factor", None)
91+
data = experiment_data.data()
92+
unit = data[0]["metadata"]["unit"]
93+
conversion_factor = data[0]["metadata"].get("dt_factor", None)
94+
qubit = data[0]["metadata"]["qubit"]
95+
8496
if conversion_factor is None:
8597
conversion_factor = 1 if unit == "s" else apply_prefix(1, unit)
8698

@@ -199,9 +211,9 @@ class T1Experiment(BaseExperiment):
199211
"""T1 experiment class.
200212
201213
Experiment Options:
202-
delays: delay times of the experiments
203-
unit: Optional, unit of the delay times. Supported units are
204-
's', 'ms', 'us', 'ns', 'ps', 'dt'.
214+
* delays: delay times of the experiments
215+
* unit: Optional, unit of the delay times. Supported units are
216+
's', 'ms', 'us', 'ns', 'ps', 'dt'.
205217
"""
206218

207219
__analysis_class__ = T1Analysis
@@ -237,7 +249,7 @@ def __init__(
237249
# Set experiment options
238250
self.set_options(delays=delays, unit=unit)
239251

240-
def circuits(self, backend: Optional["Backend"] = None) -> List[QuantumCircuit]:
252+
def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
241253
"""
242254
Return a list of experiment circuits
243255

qiskit_experiments/composite/composite_analysis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Composite Experiment Analysis class.
1414
"""
1515

16+
from qiskit.exceptions import QiskitError
1617
from qiskit_experiments.base_analysis import BaseAnalysis, AnalysisResult
1718
from .composite_experiment_data import CompositeExperimentData
1819

qiskit_experiments/randomized_benchmarking/rb_analysis.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@
1616
from typing import Optional, List
1717

1818
from qiskit.providers.options import Options
19+
from qiskit_experiments.experiment_data import ExperimentData
1920
from qiskit_experiments.base_analysis import BaseAnalysis
2021
from qiskit_experiments.analysis.curve_fitting import curve_fit, process_curve_data
2122
from qiskit_experiments.analysis.data_processing import (
2223
level2_probability,
2324
mean_xy_data,
2425
)
25-
from qiskit_experiments.analysis.plotting import (
26-
HAS_MATPLOTLIB,
27-
plot_curve_fit,
28-
plot_scatter,
29-
plot_errorbar,
30-
)
26+
from qiskit_experiments.analysis import plotting
3127

3228

3329
class RBAnalysis(BaseAnalysis):
@@ -50,10 +46,10 @@ def _default_options(cls):
5046
# pylint: disable = arguments-differ, invalid-name
5147
def _run_analysis(
5248
self,
53-
experiment_data: "ExperimentData",
49+
experiment_data: ExperimentData,
5450
p0: Optional[List[float]] = None,
5551
plot: bool = True,
56-
ax: Optional["AxesSubplot"] = None,
52+
ax: Optional["plotting.pyplot.AxesSubplot"] = None,
5753
):
5854
"""Run analysis on circuit data.
5955
Args:
@@ -95,10 +91,10 @@ def fit_fun(x, a, alpha, b):
9591
analysis_result["EPC"] = scale * (1 - popt[1])
9692
analysis_result["EPC_err"] = scale * popt_err[1] / popt[1]
9793

98-
if plot and HAS_MATPLOTLIB:
99-
ax = plot_curve_fit(fit_fun, analysis_result, ax=ax)
100-
ax = plot_scatter(x_raw, y_raw, ax=ax)
101-
ax = plot_errorbar(xdata, ydata, ydata_sigma, ax=ax)
94+
if plot and plotting.HAS_MATPLOTLIB:
95+
ax = plotting.plot_curve_fit(fit_fun, analysis_result, ax=ax)
96+
ax = plotting.plot_scatter(x_raw, y_raw, ax=ax)
97+
ax = plotting.plot_errorbar(xdata, ydata, ydata_sigma, ax=ax)
10298
self._format_plot(ax, analysis_result)
10399
figures = [ax.get_figure()]
104100
else:

0 commit comments

Comments
 (0)