Skip to content

Commit 4f73766

Browse files
nkanazawa1989yaelbh
andcommitted
Documentation fixes
Co-authored-by: Yael Ben-Haim <yaelbh@il.ibm.com>
1 parent a25043d commit 4f73766

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

qiskit_experiments/curve_analysis/__init__.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
1818
.. currentmodule:: qiskit_experiments.curve_analysis
1919
20-
Curve analysis provides the analysis base class for variety of experiments with 1-D parameter scan.
21-
Subclass can override several class attributes to define the behavior of the
22-
data formatting and fitting. Here we describe how code developer can create new curve fit
20+
Curve analysis provides the analysis base class for a variety of experiments with 1-D parameter scan.
21+
Subclasses can override several class attributes to define the behavior of the
22+
data formatting and fitting. Here we describe how code developers can create new curve fit
2323
analysis inheriting from the base class.
2424
2525
2626
Overview
2727
========
2828
2929
The base class :class:`CurveAnalysis` supports multi-objective optimization on
30-
different set of experiment results, and you can also define multiple independent
31-
optimization tasks in the same class. The analysis is implemented with following data model.
30+
different sets of experiment results, and you can also define multiple independent
31+
optimization tasks in the same class. The analysis is implemented with the following data model.
3232
3333
- Group: This is top level component of the fitting. If an analysis defines
34-
multiple groups, it performs multiple independent optimization
34+
multiple groups, it performs multiple independent optimizations
3535
and generates results for every optimization group.
3636
3737
- Series: This is a collection of curves to form a multi-objective optimization task.
@@ -43,8 +43,8 @@
4343
along with the callback function used for the curve fitting.
4444
4545
To manage this structure, curve analysis provides a special dataclass :class:`SeriesDef`
46-
that represents a optimization configuration for a single curve data.
47-
Based on this information, the analysis automatically constructs a proper optimization logic.
46+
that represents an optimization configuration for a single curve data.
47+
Based on this information, the analysis automatically constructs proper optimization logic.
4848
Thus one can avoid writing boilerplate code in various curve analyses
4949
and quickly write up the analysis code for a particular experiment.
5050
This analysis generates a set of :class:`~qiskit_experiments.framework.AnalysisResultData`
@@ -55,7 +55,7 @@
5555
Defining new curves
5656
===================
5757
58-
You can intuitively write definition of new curve, as shown below
58+
You can intuitively write the definition of a new curve, as shown below:
5959
6060
.. code-block:: python3
6161
@@ -69,12 +69,12 @@
6969
)
7070
7171
The minimum field you must fill with is the ``fit_func``, which is a callback function used
72-
with the optimization solver. Here you must call one of fit functions from the module
72+
with the optimization solver. Here you must call one of the fit functions from the module
7373
:mod:`qiskit_experiments.curve_analysis.fit_function` because they implement
74-
a special logic to compute error propagation.
74+
special logic to compute error propagation.
7575
Note that argument name of the fit function, i.e. ``[p0, p1, p2]``, is important because
76-
the signature of the provided fit function is parsed behind the scene and
77-
used as a parameter name of analysis result instance.
76+
the signature of the provided fit function is parsed behind the scenes and
77+
used as a parameter name of the analysis result instance.
7878
Thus, this name may be used to populate your experiment database with the result.
7979
8080
Optionally you can set ``model_description`` which is a string representation of your
@@ -111,7 +111,7 @@
111111
distinguish the entries and filter the corresponding (x, y) data from the experiment results.
112112
Optionally, you can provide ``plot_color`` and ``plot_symbol`` to visually
113113
separate two curves in the plot. In this model, you have 4 parameters ``[p0, p1, p2, p3]``
114-
and two curves share ``p0`` (``p3``) for ``amp`` (``baseline``) of
114+
and the two curves share ``p0`` (``p3``) for ``amp`` (``baseline``) of
115115
the :func:`exponential_decay` fit function.
116116
Here one should expect the experiment results will have two classes of data with metadata
117117
``"tag": 1`` and ``"tag": 2`` for ``my_experiment1`` and ``my_experiment2``, respectively.
@@ -180,7 +180,7 @@ def _default_options(cls) -> Options:
180180
The parameter specified in :attr:`CurveAnalysis.__fixed_parameters__` should be provided
181181
via the analysis options. Thus you may need to define a default value of the parameter in the
182182
:meth:`CurveAnalysis._default_options`.
183-
This code will give you identical fit model to one defined in the following class
183+
This code will give you identical fit model to the one defined in the following class:
184184
185185
.. code-block:: python3
186186
@@ -194,8 +194,8 @@ class AnalysisB(CurveAnalysis):
194194
),
195195
]
196196
197-
however, note that you can also inherit other features, e.g. the algorithm to
198-
generate initial guess, from the :class:`AnalysisA` in the first example.
197+
However, note that you can also inherit other features, e.g. the algorithm to
198+
generate initial guesses, from the :class:`AnalysisA` in the first example.
199199
On the other hand, in the latter case, you need to manually copy and paste
200200
every logic defined in the :class:`AnalysisA`.
201201
@@ -204,7 +204,7 @@ class AnalysisB(CurveAnalysis):
204204
Defining multiple tasks
205205
=======================
206206
207-
The code blow shows how a subclass can define separate optimization tasks.
207+
The code below shows how a subclass can define separate optimization tasks.
208208
209209
.. code-block:: python3
210210
@@ -232,11 +232,11 @@ class AnalysisB(CurveAnalysis):
232232
]
233233
234234
The code looks almost identical to one in :ref:`curve_analysis_define_new`,
235-
however, here we are providing unique ``group`` value to each series definition.
235+
however, here we are providing a unique ``group`` value to each series definition.
236236
In this configuration, the parameters ``[p0, p1, p2, p3]`` are not shared among
237237
underlying curve fittings, thus we will get two fit parameter sets as a result.
238238
This means the ``p*`` value may change between curves.
239-
The parameters can be distinguished by ``group`` value passed to the result metadata.
239+
The parameters can be distinguished by the ``group`` value passed to the result metadata.
240240
241241
This is identical to running individual ``my_experiment1`` and ``my_experiment2`` as a
242242
:class:`~qiskit_experiments.framework.BatchExperiment` and collect fit results afterwards
@@ -265,17 +265,17 @@ class AnalysisB(CurveAnalysis):
265265
266266
A subclass may override :meth:`CurveAnalysis._format_data` to perform custom pre-processing
267267
on experiment data before computing the initial guesses.
268-
Here a subclass may perform data smoothing, removal of outlier, etc...
268+
Here a subclass may perform data smoothing, removal of outliers, etc...
269269
By default, it performs averaging of y values over the same x values,
270270
followed by the data sort by x values.
271-
This method should return :class:`CurveData` instance with `label="fit_ready"`.
271+
This method should return a :class:`CurveData` instance with `label="fit_ready"`.
272272
273273
.. _curve_analysis_init_guess:
274274
275275
Providing initial guesses and boundaries
276276
========================================
277277
278-
A template for initial guesses and boundaries are automatically generated in
278+
A template for initial guesses and boundaries is automatically generated in
279279
:attr:`CurveAnalysis.options` as a dictionary keyed on the parameter names parsed from
280280
the series definition. The default values are set to ``None``.
281281
The list of parameter names is also available in the property
@@ -284,7 +284,7 @@ class AnalysisB(CurveAnalysis):
284284
A developer of the curve analysis subclass is recommended to override
285285
:meth:`CurveAnalysis._generate_fit_guesses` to provide systematic guesses and boundaries
286286
based on the experimental result.
287-
For accessing the formatted experiment result, you can use :meth:`CurveAnalysis._data` method.
287+
For accessing the formatted experiment result, you can use the :meth:`CurveAnalysis._data` method.
288288
289289
.. code-block:: python3
290290
@@ -293,7 +293,7 @@ class AnalysisB(CurveAnalysis):
293293
x = curve_data.x # you can get x-values
294294
y = curve_data.y # you can get y-values
295295
296-
In addition, there are several common initial guess estimators available in the
296+
In addition, there are several common initial guess estimators available in
297297
:mod:`qiskit_experiments.curve_analysis.guess`.
298298
299299
When fit is performed without any prior information of parameters, it usually
@@ -314,35 +314,35 @@ class AnalysisB(CurveAnalysis):
314314
315315
return [opt1, opt2]
316316
317-
The ``user_opt`` is :class:`FitOptions` instance, which consists of sub dictionary for
318-
initial guesses (``.p0``), boundaries (``.bounds``).
319-
The :meth:`.set_if_empty` method overrides parameter value only when user doesn't provide
317+
``user_opt`` is a :class:`FitOptions` instance, which consists of sub-dictionaries for
318+
initial guesses (``.p0``) and boundaries (``.bounds``).
319+
The :meth:`.set_if_empty` method overrides the parameter value only when the user doesn't provide
320320
any prior information.
321-
The ``user_opt`` also has extra configuration dictionary that is directly passed to
321+
``user_opt`` also has extra configuration dictionary that is directly passed to
322322
the curve fitting function. Note that the :class:`CurveAnalysis` uses
323323
SciPy `curve_fit`_ function as a core solver. See the API documentation for available options.
324324
325325
The final fitting outcome is determined with the following procedure.
326326
327-
1. The ``user_opt`` is initialized with values a user provides via the analysis options.
327+
1. ``user_opt`` is initialized with the values provided by the user via the analysis options.
328328
329-
2. Algorithmic guess is generated in :meth:`_generate_fit_guesses`
330-
in which the logic implemented by a subclass may overrides the ``user_opt``.
329+
2. The algorithmic guess is generated in :meth:`_generate_fit_guesses`,
330+
where the logic implemented by a subclass may override the ``user_opt``.
331331
If you want, you can copy it to create multiple fitting configurations.
332332
When multiple configurations are generated here, the curve fitter runs fitting multiple times.
333333
334334
3. If multiple configurations are created, the curve analysis framework checks
335-
duplication of configurations and perform fitting multiple times with unique configuration set.
335+
duplication of configurations and performs fitting multiple times with a unique configuration set.
336336
337337
4. The curve fitter computes a reduced chi-squared value for every attempt,
338-
and find the outcome with the minimum reduced chi-squared value.
339-
If the fitting fails, or the solver cannot find reasonable parameter within the maximum recursion,
338+
and finds the outcome with the minimum reduced chi-squared value.
339+
If the fitting fails, or the solver cannot find reasonable parameters within the maximum recursion,
340340
it just ignores the current configuration and moves to the next.
341341
If all provided configurations fail, it raises ``UserWarning`` and continues
342-
the rest of analysis.
342+
the rest of the analysis.
343343
344344
5. Analysis results are automatically generated if the curve fitter
345-
successfully find the best-fit outcome.
345+
successfully finds the best-fit outcome.
346346
347347
.. _curve_fit: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
348348
@@ -352,7 +352,7 @@ class AnalysisB(CurveAnalysis):
352352
======================
353353
354354
A subclass can override :meth:`CurveAnalysis._evaluate_quality` method to provide an algorithm to
355-
evaluate quality of the fitting. This method is called with :class:`FitData` object
355+
evaluate quality of the fitting. This method is called with the :class:`FitData` object
356356
which contains fit parameters and the reduced chi-squared value.
357357
Qiskit Experiments often uses the empirical condition chi-squared < 3 as a goodness of fitting.
358358
@@ -361,7 +361,7 @@ class AnalysisB(CurveAnalysis):
361361
Computing new quantity with fit parameters
362362
==========================================
363363
364-
Once the best fit parameters are found, :meth:`CurveAnalysis._extra_database_entry` method is
364+
Once the best fit parameters are found, the :meth:`CurveAnalysis._extra_database_entry` method is
365365
called with the same :class:`FitData` object.
366366
You can compute new quantities by combining multiple fit parameters.
367367
@@ -378,7 +378,7 @@ class AnalysisB(CurveAnalysis):
378378
)
379379
380380
Note that both ``p0`` and ``p1`` are `ufloat`_ object consisting of
381-
nominal value and error value assuming the standard deviation.
381+
a nominal value and an error value which assumes the standard deviation.
382382
Since this object natively supports error propagation, you don't need to manually compute errors.
383383
384384
.. _ufloat: https://pythonhosted.org/uncertainties/user_guide.html
@@ -392,7 +392,7 @@ class AnalysisB(CurveAnalysis):
392392
This entry consists of a value which is a list of all fitting parameters
393393
with extra metadata involving their covariance matrix.
394394
If you want to save a particular parameter as a standalone entry,
395-
you can override ``result_parameters`` option of the analysis.
395+
you can override the ``result_parameters`` option of the analysis.
396396
By using :class:`ParameterRepr` representation, you can rename the parameter in the database.
397397
398398
.. code-block:: python3

qiskit_experiments/curve_analysis/curve_analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ def _run_analysis(
776776
"popt_keys": fit_result.popt_keys,
777777
"dof": fit_result.dof,
778778
"covariance_mat": fit_result.pcov,
779-
"fit_models": fit_result.fit_mdoel,
779+
"fit_models": fit_result.fit_model,
780780
**self.options.extra,
781781
},
782782
)
@@ -809,7 +809,7 @@ def _run_analysis(
809809
quality=quality,
810810
extra={
811811
"group": fit_result.group,
812-
"fit_models": fit_result.fit_mdoel,
812+
"fit_models": fit_result.fit_model,
813813
**metadata,
814814
},
815815
)

qiskit_experiments/curve_analysis/curve_data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def __post_init__(self):
6565
class CompositeFitFunction:
6666
"""Function-like object that is generated by a curve analysis subclass.
6767
68-
This is function-like object that implements a fit model as a ``__call__`` magic method,
69-
thus it behaves as if a python function that the SciPy curve_fit solver accepts.
68+
This is a function-like object that implements a fit model as a ``__call__`` magic method,
69+
thus it behaves like a Python function that the SciPy curve_fit solver accepts.
7070
Note that the fit function there only accepts variadic arguments.
7171
7272
This class ties together the fit function and associated parameter names to
73-
perform correct parameter mapping among multiple objective functions with different signature,
73+
perform correct parameter mapping among multiple objective functions with different signatures,
7474
in which some parameters may be excluded from the fitting when they are fixed.
7575
"""
7676

@@ -87,11 +87,11 @@ def __init__(
8787
8888
Args:
8989
group: A name of the fit group that this function belongs to.
90-
fit_functions: List of callable that defines fit function of a single series.
90+
fit_functions: List of callables that defines fit function of a single series.
9191
signatures: List of parameter names of a single series.
9292
curve_inds: List of index corresponding to the curve data.
9393
fixed_parameters: List of parameter names that are fixed in the fit.
94-
**metadata: Arbitrary dictionary with information of this fit function.
94+
**metadata: An arbitrary dictionary with information about this fit function.
9595
9696
Raises:
9797
AnalysisError: When ``fit_functions`` and ``signatures`` don't match.
@@ -244,7 +244,7 @@ class FitData:
244244
y_range: Tuple[float, float]
245245

246246
# String representation of fit model
247-
fit_mdoel: str = "not defined"
247+
fit_model: str = "not defined"
248248

249249
# String representation of the group that this fit belongs to.
250250
group: str = "default"

test/curve_analysis/test_curve_analysis_base_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class MyCurveFit(CurveAnalysis):
205205
)
206206
self.assertIsInstance(result, FitData)
207207

208-
self.assertEqual(result.fit_mdoel, "not defined")
208+
self.assertEqual(result.fit_model, "not defined")
209209
self.assertEqual(result.popt_keys, ["p0", "p1"])
210210
self.assertEqual(result.dof, 8)
211211
self.assertEqual(result.group, "default")
@@ -266,7 +266,7 @@ class MyCurveFit(CurveAnalysis):
266266
bounds={"p0": (0, 2), "p1": (1, 3), "p2": (2, 4)},
267267
)
268268

269-
self.assertEqual(result.fit_mdoel, "p0 x + p1,p0 x - p2")
269+
self.assertEqual(result.fit_model, "p0 x + p1,p0 x - p2")
270270
self.assertEqual(result.popt_keys, ["p0", "p1", "p2"])
271271
np.testing.assert_array_almost_equal(unp.nominal_values(result.popt), [p0, p1, p2])
272272

0 commit comments

Comments
 (0)