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
2323analysis inheriting from the base class.
2424
2525
2626Overview
2727========
2828
2929The 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.
4343 along with the callback function used for the curve fitting.
4444
4545To 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.
4848Thus one can avoid writing boilerplate code in various curve analyses
4949and quickly write up the analysis code for a particular experiment.
5050This analysis generates a set of :class:`~qiskit_experiments.framework.AnalysisResultData`
5555Defining 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
6969 )
7070
7171The 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.
7575Note 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.
7878Thus, this name may be used to populate your experiment database with the result.
7979
8080Optionally you can set ``model_description`` which is a string representation of your
111111distinguish the entries and filter the corresponding (x, y) data from the experiment results.
112112Optionally, you can provide ``plot_color`` and ``plot_symbol`` to visually
113113separate 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
115115the :func:`exponential_decay` fit function.
116116Here 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:
180180The parameter specified in :attr:`CurveAnalysis.__fixed_parameters__` should be provided
181181via 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.
199199On the other hand, in the latter case, you need to manually copy and paste
200200every logic defined in the :class:`AnalysisA`.
201201
@@ -204,7 +204,7 @@ class AnalysisB(CurveAnalysis):
204204Defining 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
234234The 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.
236236In this configuration, the parameters ``[p0, p1, p2, p3]`` are not shared among
237237underlying curve fittings, thus we will get two fit parameter sets as a result.
238238This 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
241241This 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
266266A subclass may override :meth:`CurveAnalysis._format_data` to perform custom pre-processing
267267on 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...
269269By default, it performs averaging of y values over the same x values,
270270followed 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
275275Providing 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
280280the series definition. The default values are set to ``None``.
281281The list of parameter names is also available in the property
@@ -284,7 +284,7 @@ class AnalysisB(CurveAnalysis):
284284A developer of the curve analysis subclass is recommended to override
285285:meth:`CurveAnalysis._generate_fit_guesses` to provide systematic guesses and boundaries
286286based 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
299299When 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
320320any 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
322322the curve fitting function. Note that the :class:`CurveAnalysis` uses
323323SciPy `curve_fit`_ function as a core solver. See the API documentation for available options.
324324
325325The 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
3343343. 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
3373374. 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
3443445. 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
354354A 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
356356which contains fit parameters and the reduced chi-squared value.
357357Qiskit Experiments often uses the empirical condition chi-squared < 3 as a goodness of fitting.
358358
@@ -361,7 +361,7 @@ class AnalysisB(CurveAnalysis):
361361Computing 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
365365called with the same :class:`FitData` object.
366366You can compute new quantities by combining multiple fit parameters.
367367
@@ -378,7 +378,7 @@ class AnalysisB(CurveAnalysis):
378378 )
379379
380380Note 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.
382382Since 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):
392392This entry consists of a value which is a list of all fitting parameters
393393with extra metadata involving their covariance matrix.
394394If 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.
396396By using :class:`ParameterRepr` representation, you can rename the parameter in the database.
397397
398398.. code-block:: python3
0 commit comments