Skip to content

Commit

Permalink
finalize
Browse files Browse the repository at this point in the history
- small docs fix
- lint
- reno
  • Loading branch information
nkanazawa1989 committed Apr 22, 2022
1 parent eb22e39 commit d3cde71
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
13 changes: 7 additions & 6 deletions qiskit_experiments/curve_analysis/base_curve_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@ def _default_options(cls) -> Options:
instance that defines the `self.__call__` method.
normalization (bool) : Set ``True`` to normalize y values within range [-1, 1].
Default to ``False``.
p0 (Dict[str, float]): Array-like or dictionary
of initial parameters.
bounds (Dict[str, Tuple[float, float]]): Array-like or dictionary
of (min, max) tuple of fit parameter boundaries.
p0 (Dict[str, float]): Initial guesses for the fit parameters.
The dictionary is keyed on the fit parameter names.
bounds (Dict[str, Tuple[float, float]]): Boundary of fit parameters.
The dictionary is keyed on the fit parameter names and
values are the tuples of (min, max) of each parameter.
curve_fitter_options (Dict[str, Any]) Options that are passed to the
scipy curve fit which performs the least square fitting on the experiment results.
x_key (str): Circuit metadata key representing a scanned value.
result_parameters (List[Union[str, ParameterRepr]): Parameters reported in the
database as a dedicated entry. This is a list of parameter representation
Expand All @@ -149,8 +152,6 @@ def _default_options(cls) -> Options:
Representation should be printable in standard output, i.e. no latex syntax.
extra (Dict[str, Any]): A dictionary that is appended to all database entries
as extra information.
curve_fitter_options (Dict[str, Any]) Options that are passed to the
specified curve fitting function.
fixed_parameters (Dict[str, Any]): Fitting model parameters that are fixed
during the curve fitting. This should be provided with default value
keyed on one of the parameter names in the series definition.
Expand Down
10 changes: 4 additions & 6 deletions qiskit_experiments/curve_analysis/curve_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ def __init__(self):
#: List[CurveData]: Processed experiment data set. For backward compatibility.
self.__processed_data_set = {}

#: List[int]: Index of physical qubits
self._physical_qubits = None

@classmethod
def _fit_params(cls) -> List[str]:
"""Return a list of fitting parameters.
Expand Down Expand Up @@ -200,9 +197,7 @@ def _run_analysis(
quality = self._evaluate_quality(fit_data)

# Create analysis results
analysis_results.extend(
self._create_analysis_results(fit_data, quality, **metadata)
)
analysis_results.extend(self._create_analysis_results(fit_data, quality, **metadata))
# calling old extra entry method for backward compatibility
if hasattr(self, "_extra_database_entry"):
warnings.warn(
Expand Down Expand Up @@ -331,6 +326,9 @@ def analysis_result_to_repr(result: AnalysisResultData) -> str:
Returns:
String representation of the data.
Raises:
AnalysisError: When the result data is not likely fit parameter.
"""
if not isinstance(result.value, (float, UFloat)):
raise AnalysisError(f"Result data {result.name} is not a valid fit parameter data type.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def _evaluate_quality(self, fit_data: curve.FitData) -> Union[str, None]:
fit_a = fit_data.fitval("a")
fit_b = fit_data.fitval("b")
fit_freq = fit_data.fitval("freq")
fit_kappa = fit_data.fitval("kappa")
fit_sigma = fit_data.fitval("sigma")

snr = abs(fit_a.n) / np.sqrt(abs(np.median(fit_data.y_data) - fit_b.n))
fit_width_ratio = fit_kappa.n / np.ptp(fit_data.x_data)
fit_width_ratio = fit_sigma.n / np.ptp(fit_data.x_data)

criteria = [
fit_data.x_range[0] <= fit_freq.n <= fit_data.x_range[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import qiskit_experiments.curve_analysis as curve

import qiskit_experiments.data_processing as dp
from qiskit_experiments.database_service.device_component import Qubit
from qiskit_experiments.framework import AnalysisResultData


Expand Down
31 changes: 31 additions & 0 deletions releasenotes/notes/cleanup-curve-analysis-96d7ff706cae5b4e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
developer:
- |
:class:`CurveAnalysis` is now a subclass of :class:`BaseCurveAnalysis`.
This change has been made to introduce multi-grouped curve analysis,
see qiskit-experiments/#737 for details.
According to this update, several protected methods that are
originally designed to be overridden by subclass have been deprecated or upgraded.
Check the following list of changes you may need to upgrade your analysis subclass.
- :meth:`CurveAnalysis._generate_fit_guesses`
The signature of method has been upgraded. Now this method should be called with
``curve_data`` and calling ``self._data()`` to get curve data has been deprecated.
- :meth:`CurveAnalysis._data`
This method has been deprecated.
- :meth:`CurveAnalysis._extra_database_entry`
This method has been deprecated. You can directly override
new method :meth:`CurveAnalysis._create_analysis_results`.
- :class:`FitData`
Fit data dataclass is now created with :attr:`x_data` and :attr:`y_data`
so that you can retrieve the data used for the fitting along with the outcome parameters.
See :ref:`curve_analysis_overview` for the overview of new curve analysis base class.
10 changes: 4 additions & 6 deletions test/curve_analysis/test_baseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class TestCurveAnalysisUnit(QiskitExperimentsTestCase):

class TestAnalysis(CurveAnalysis):
"""Fake analysis class for unittest."""

__series__ = [
SeriesDef(
name="curve1",
Expand Down Expand Up @@ -136,9 +137,7 @@ def test_data_extraction(self):
xvalues = np.linspace(1.0, 5.0, 10)

analysis = self.TestAnalysis()
analysis.set_options(
data_processor=DataProcessor("counts", [Probability("1")])
)
analysis.set_options(data_processor=DataProcessor("counts", [Probability("1")]))

# data to analyze
test_data0 = simulate_output_data(
Expand Down Expand Up @@ -171,9 +170,7 @@ def test_data_extraction_with_subset(self):
xvalues = np.linspace(1.0, 5.0, 10)

analysis = self.TestAnalysis()
analysis.set_options(
data_processor=DataProcessor("counts", [Probability("1")])
)
analysis.set_options(data_processor=DataProcessor("counts", [Probability("1")]))

# data to analyze
test_data0 = simulate_output_data(
Expand Down Expand Up @@ -257,6 +254,7 @@ def test_invalid_options(self):

class InvalidClass:
"""Dummy class."""

pass

with self.assertRaises(TypeError):
Expand Down

0 comments on commit d3cde71

Please sign in to comment.