-
Notifications
You must be signed in to change notification settings - Fork 127
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
Setting type for composite experiment #1296
Setting type for composite experiment #1296
Conversation
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.
Thank you for working on this 😄 .
@@ -65,6 +66,9 @@ def __init__( | |||
provided this will be initialized automatically from the | |||
supplied experiments. | |||
""" | |||
# Experiment identification metadata | |||
self._type = experiment_type if experiment_type else type(self).__name__ |
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.
This will happen in the parent's constructor, what you have to do is to pass experiment_type
to the parent's constructor.
By the way, in BaseExperiment
you can modify this line to self.experiment_type = experiment_type
.
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.
lol I should have read docs first, fixed it, removed proparty
and setter
from both BaseExperiment
and ParallelExperiment
added init arg experiment_type
in both.
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.
Remove this line.
Then, in BaseExperiment
, replace this line with self.experiment_type = experiment_type
.
@@ -89,6 +93,19 @@ def __init__( | |||
experiments, qubits, backend=backend, analysis=analysis, flatten_results=flatten_results | |||
) | |||
|
|||
@property |
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.
These property and setter already exist in BaseExperiment
, so there is no reason to copy them here.
Note that all the comments for the BatchExperiment
apply also to the ParallelExperiment
.
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.
fixed
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.
What do you mean by "fixed"? Did you commit the fix? Because the property and setter are still here.
--- | ||
features: | ||
- | | ||
Added ``experiment_type`` as optional ``__init__`` kwarg in BatchExperiment |
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.
There are two separate things in this PR: the setter and the args in init. You can separate them in the release notes.
and ParallelExperiment the 'experiment_type' can now be easily set and | ||
retrieved from the experiment object post-construction using the 'experiment_type' | ||
property and setter. | ||
:math":`BatchExperiment.experiment_type` as property and setter. |
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.
Change after fixing batch_experiment.py
.
- | | ||
:math:`BaseExperiment.experiment_type` as setter. | ||
- | | ||
Refer issue |
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.
@coruscating Do we usually refer to issues in the release notes?
test/framework/test_composite.py
Outdated
@@ -151,6 +152,29 @@ def test_roundtrip_serializable(self): | |||
|
|||
self.assertRoundTripSerializable(exp) | |||
|
|||
@data(None, "Test") | |||
def test_experiment_type(self, exp_type): | |||
"""Test the experiment_type setter for the parallel experiment and |
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.
Once you remove the setters from these classes, you can also remove the test here. However do test the the init arg (such a test is currently missing).
test/framework/test_framework.py
Outdated
def circuits(self): | ||
pass | ||
|
||
exp1 = MyExp(physical_qubits=[0], experiment_type=exp_type1) |
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.
Instead of passing exp_type
to the constructor, pass some arbitrary string (like blaaa
) and verify that the setter overrides it.
test/framework/test_framework.py
Outdated
|
||
exp1 = MyExp(physical_qubits=[0], experiment_type=exp_type1) | ||
if exp_type1 is None: | ||
exp_type1 = type(exp1).__name__ |
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 don't understand what you're trying to test here. Note that you're not testing the case where the setters gets None
.
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.
like this?
def test_experiment_type(self):
"""Test the experiment_type setter for the experiment."""
class MyExp(BaseExperiment):
"""Some arbitrary experiment"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def circuits(self):
pass
exp1 = MyExp(physical_qubits=[0], experiment_type="blaaa")
self.assertEqual(exp1.experiment_type, "blaaa")
exp2 = MyExp(physical_qubits=[0])
exp2.experiment_type = "suieee"
self.assertEqual(exp2.experiment_type, "suieee")
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.
Yes, and between the third and fourth line add:
self.assertEqual(exp2.experiment_type, "MyExp")
@@ -65,6 +66,9 @@ def __init__( | |||
provided this will be initialized automatically from the | |||
supplied experiments. | |||
""" | |||
# Experiment identification metadata | |||
self._type = experiment_type if experiment_type else type(self).__name__ |
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.
Remove this line.
Then, in BaseExperiment
, replace this line with self.experiment_type = experiment_type
.
@@ -89,6 +93,19 @@ def __init__( | |||
experiments, qubits, backend=backend, analysis=analysis, flatten_results=flatten_results | |||
) | |||
|
|||
@property |
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.
What do you mean by "fixed"? Did you commit the fix? Because the property and setter are still here.
ce63ed3
to
ec9686f
Compare
--- | ||
features: | ||
- | | ||
Added ``experiment_type`` as optional ``__init__`` kwarg in BatchExperiment |
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.
Mark BatchExperiment
as a class
Added ``experiment_type`` as optional ``__init__`` kwarg in BatchExperiment | ||
and ParallelExperiment. | ||
- | | ||
:math:`BaseExperiment.experiment_type` as setter,'experiment_type' can 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.
:math:`BaseExperiment.experiment_type` as setter,'experiment_type' can now | |
'experiment_type' can now |
The code looks fine. I don't understand why the docs don't build. I'll try to rerun. |
CI is fixed now. |
### Summary This PR solves issue qiskit-community#1289 Added `experiment_type` property and setter in `BatchExperiment` and `ParallelExperiment` also added `experiment_type` setter in `BaseExperiment`, this changes will provide user flexibility and ease of use within their applications. ### PR checklist (delete when all criteria are met) - [X] I have read the contributing guide `CONTRIBUTING.md`. - [X] I have added the tests to cover my changes. - [X] I have updated the documentation accordingly. - [X] I have added a release note file using `reno` if this change needs to be documented in the release notes. --------- Co-authored-by: Helena Zhang <Helena.Zhang@ibm.com>
Summary
This PR solves issue #1289
Added
experiment_type
property and setter inBatchExperiment
andParallelExperiment
also addedexperiment_type
setter inBaseExperiment
, this changes will provide user flexibility and ease of use within their applications.PR checklist (delete when all criteria are met)
CONTRIBUTING.md
.reno
if this change needs to be documented in the release notes.