-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add BaseResult functionality to primitives module #8091
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 3051563525
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the features are useful and they are great from a code standpoint. I leave some minor comments. But, from an interface point of view, it would be good to have @ajavadia and @levbishop review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. LGTM. But I would like to wait more comments.
bdcb36c
to
0753bc9
Compare
Looks good to me too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I think the name experiments
is a poor choice. In the process of developing OpenQASM3, we proposed a generalized "circuit" concept that supplants what has previously been called an "experiment" in terra. This word is also overloaded by the "experiment" concept in qiskit-experiments
.
I realize that there are many residual uses of "experiments" in terra, but would it make sense to already start the move away by settling on "circuits" here? i.e. num_circuits
and circuits
as the property names?
I don't think that would work @blakejohnson . Some of the primitives (if not all) currently hold a list of circuits that they can use to run "experiments". That means that the user can request n different experiments on anyone of theses circuits (e.g. for different observables in I am very curious to learn how this distinction is being handled in OpenQASM3. I have no personal attachment to the word "experiment" though, and I'll be happy to change it if we come up with a better alternative. What I like about it though, is that it conveys the fact that we are referring to something atomic; as opposed to "job", for example, which can encapsulate several of these atomic elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (need to fix lint and tests). Thank you! (I was about to point out that base_result does not use __future__.annotations
, but you already fixed it.)
We cannot see the docs of |
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LTGM, Thanks!
I want to wait @t-imamichi's approval. |
qiskit/primitives/base_result.py
Outdated
""" | ||
for value in self._field_values: # type: Sequence | ||
# TODO: enforce all data fields to be tuples instead of sequences | ||
if not isinstance(value, (Sequence, ndarray)) or isinstance(value, str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether the check isinstance(value, str)
is enough or not. What if bytes
object is given?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check each entry of Sequence
perhaps? Do you have any suggestion, @ikkoham?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with checking each sequence entry is that the types will differ for each data attribute (e.g. values and metadata), and between primitives (e.g. sampler and estimator). So those checks should probably live under the particular primitives' __post_init__
methods (e.g. Estimator.__post_init__
), instead of inside BasePrimitiveResult
.
Is this what you are referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I just wondered whether there is any simpler way of this check.
This PR looks good overall. I have a minor comment. I'm wondering about the validation check of the data. #8091 (comment) |
Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com>
I have already excluded I don't think that this type check is comprehensive though (surely better than no check at all), but the best approach to solve it should be by enforcing an specific type (e.g. |
Thank you, @pedrorrivero. This PR looks good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's merge this PR!
Summary
Adds a primitive result base class to provide common functionality to all inheriting result dataclasses.
Closes #8089
Changelog: New Feature
Details and comments
result.num_experiments
property.result.experiments
property.__post_init__
).To do
autosummary
)