Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CurveAnalysis base class #765

Conversation

nkanazawa1989
Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 commented Apr 6, 2022

Summary

This PR introduces base class for curve analysis. See #737 for details.

Blocked by #762

Details and comments

TODO

@nkanazawa1989 nkanazawa1989 added the blocked Can't be worked on until another issue is resolved label Apr 6, 2022
@nkanazawa1989 nkanazawa1989 mentioned this pull request Apr 6, 2022
7 tasks
@nkanazawa1989 nkanazawa1989 added this to the Release 0.3 milestone Apr 6, 2022
@nkanazawa1989 nkanazawa1989 force-pushed the feature/curve_analysis_baseclass branch 2 times, most recently from fb14230 to 5d3a33f Compare April 6, 2022 21:04
@nkanazawa1989 nkanazawa1989 force-pushed the feature/curve_analysis_baseclass branch from 5d3a33f to 3a4f605 Compare April 6, 2022 21:08
Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be in good shape. Do you also need to refactor the other analysis classes to this?

qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
Comment on lines 52 to 53
A method to format curve data. By default this method takes y value average
over the same x values and then sort the entire data by x values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A method to format curve data. By default this method takes y value average
over the same x values and then sort the entire data by x values.
A method to format curve data. By default this method takes the average of the y values
over the same x values and then sort the entire data by x values.

This is not something that is needed all the time right? This is most useful for RB correct? Perhaps that's worth mentioning here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is always done. Because some guess function relies on the sequence ordering, e.g. computing slope by something like dx = x[1] - x[0]. There is no guarantee x values are in ascending order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two things here.

a) averaging the y data
b) sorting according to x data.

Makes sense to always do b). Do we always do a)?

Copy link
Collaborator Author

@nkanazawa1989 nkanazawa1989 Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should do. If you concatenate two experiments, you will create experiment data that may consist of something like x = [0,1,2,3,0,1,2,3] that will crash some guess function.

qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
https://github.com/Qiskit/qiskit-experiments/issues
"""
class CurveAnalysis(BaseCurveAnalysis):
"""Base class for curve analyis."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a base class is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still base class (e.g. ErrorAmplificationAnalysis(CurveAnalysis)). The reason we introduce BaseCurveAnalysis is to remove boilerplate code in GroupedCurveAnalysis.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm the naming gets a bit confusing no? Since CurveAnalysis is still a base class it could be called BaseCurveAnalysis which is already taken. What are the distinctive features between CurveAnalysis (a base class) and BaseCurveAnalysis? Perhaps that can help with the naming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a bit more to the class docstring to explain why we have this class? Currently it reads Base class for curve analyis. which is too brief given that we have another class called BaseCurveAnalysis.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be clearer once we introduce the GroupCurveAnalysis (perhaps MultiGroupCurveAnalysis to be precise). The base one is the superclass of both CurveAnalysis and GroupCurveAnalysis . The difference between CurveAnalysis and BaseCurveAnalysis is implementation of _run_analysis method. In the group one the logic inside the _run_analysis will be different from CurveAnalysis though each subroutines can be reused. This is why BaseCurveAnalysis only implements subroutines.

qiskit_experiments/curve_analysis/curve_data.py Outdated Show resolved Hide resolved
@nkanazawa1989 nkanazawa1989 removed the blocked Can't be worked on until another issue is resolved label Apr 21, 2022
@nkanazawa1989 nkanazawa1989 changed the title [WIP] CurveAnalysis base class CurveAnalysis base class Apr 22, 2022
- small docs fix
- lint
- reno
@nkanazawa1989 nkanazawa1989 force-pushed the feature/curve_analysis_baseclass branch from d3cde71 to 62d1609 Compare April 22, 2022 18:25
Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks mostly good. The only thing I still find a bit awkward is the naming between CurveAnalysis and BaseCurveAnalysis as both are base classes (see some of the comments below).

https://github.com/Qiskit/qiskit-experiments/issues
"""
class CurveAnalysis(BaseCurveAnalysis):
"""Base class for curve analyis."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a bit more to the class docstring to explain why we have this class? Currently it reads Base class for curve analyis. which is too brief given that we have another class called BaseCurveAnalysis.

qiskit_experiments/curve_analysis/__init__.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@chriseclectic chriseclectic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review

qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
qiskit_experiments/curve_analysis/curve_data.py Outdated Show resolved Hide resolved
Curve Analysis Overview
=======================

The base class :class:`CurveAnalysis` implements the multi-objective optimization on
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is starting to get too detailed for class level API docs and should instead be moved to its own separate User Guide on curve analysis?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Do we create user guide with this PR? I've already moved some long API docs (basically how code author can override method) to here and left :ref: link in the original place so I cannot simply remove this. Note that this is not a class level docs, this is module docs so I think this is probably okey for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this can be a separate PR, I think we should do a bit of planning on what would make some good mode detailed user guides

Co-authored-by: Daniel J. Egger <[email protected]>
@nkanazawa1989 nkanazawa1989 force-pushed the feature/curve_analysis_baseclass branch from e7f83e9 to 3a86a25 Compare April 25, 2022 17:20
Co-authored-by: Christopher J. Wood <[email protected]>
@nkanazawa1989 nkanazawa1989 force-pushed the feature/curve_analysis_baseclass branch from 3d043d9 to 3d7a5e4 Compare April 25, 2022 18:46
Copy link
Collaborator

@chriseclectic chriseclectic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, couple more documentation comments

qiskit_experiments/curve_analysis/base_curve_analysis.py Outdated Show resolved Hide resolved
"""Description of curve."""
"""A dataclass to describe the definition of the curve.

Args:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious what the "correct" way to comment a dataclass is and found this https://stackoverflow.com/a/51131941

They suggest preferring option (3) using Attributes: rather than using Args:. I didn't test myself, but I wonder if this will will override the empty attribute desciptions currently populated here. Checking the artifact on this PR the attribute doc stirngs are unchanged, but the Parameters: field is populated correctly from these args.

image

Can you try changing to attributes and checking what the built docs looks like and pick the one you think looks best?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for searching. I also prefer attribute style but I was not sure the best one. I just copied style from primitives in terra :)
image

@nkanazawa1989 nkanazawa1989 force-pushed the feature/curve_analysis_baseclass branch from 38ceaa0 to d7e25a4 Compare April 25, 2022 22:09
@eggerdj eggerdj dismissed their stale review April 26, 2022 05:33

LGTM now

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. @chriseclectic as you have also commented on this PR I'll let you give the final approval.

@nkanazawa1989 nkanazawa1989 force-pushed the feature/curve_analysis_baseclass branch from 317c687 to 67c942b Compare April 26, 2022 07:08
Copy link
Collaborator

@chriseclectic chriseclectic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chriseclectic chriseclectic merged commit 9fdc011 into qiskit-community:main Apr 26, 2022
paco-ri pushed a commit to paco-ri/qiskit-experiments that referenced this pull request Jul 11, 2022
Refactor of CurveAnalysis and introduction of BaseCurveAnalysis class

Co-authored-by: Daniel J. Egger <[email protected]>
Co-authored-by: Christopher J. Wood <[email protected]>
@nkanazawa1989 nkanazawa1989 deleted the feature/curve_analysis_baseclass branch October 27, 2022 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants