Repository navigation
Remove wire sizes - #10531
Remove wire sizes#10531pragati903 wants to merge 31 commits into
Conversation
Remove 'pl-env' from the .gitignore file.
|
Hello, and thanks so much for your contribution!! 🎉 Could you please resolve the merge conflicts so that we can run CI and make sure that there are no failures in the test suite? 🙂 Thanks so much! |
| # make sure wires have the right sizes | ||
| error_msg = f"Wires argument {name} has an invalid dimension." | ||
| assert dim is None or len(val) == dim, error_msg | ||
|
|
||
|
|
There was a problem hiding this comment.
Should we replace this check with a check against arg_specs?
There was a problem hiding this comment.
Thanks, I have added a test for the same.
| """Test that when ``wire_sizes`` is not declared, it defaults to a tuple | ||
| of ``None`` matching the length of ``wire_argnames``.""" | ||
|
|
||
| class Op(Operator2): | ||
| wire_argnames = ("wires", "ctrl_wires") | ||
|
|
||
| def __init__(self, wires, ctrl_wires): | ||
| super().__init__(wires=wires, ctrl_wires=ctrl_wires) | ||
|
|
||
| assert Op.wire_sizes == (None, None) | ||
|
|
There was a problem hiding this comment.
Is this behaviour matched with arg_specs? Do we need a test for it?
There was a problem hiding this comment.
Thanks, I have added a test for this.
lillian542
left a comment
There was a problem hiding this comment.
Thanks, Pragati! This is looking good. I left a few questions/suggestions regarding docstrings and tests :)
|
|
||
| class Op(Operator2): | ||
| wire_sizes = (2,) | ||
|
|
There was a problem hiding this comment.
Some of the tests from here onward in this file look like they are testing behaviour that we still want in terms of validating the wire input matches the expected input for the operator - we just want it specified via arg_specs instead.
Are these same things already tested using arg_specs elsewhere? If not, let's keep the tests and update them to use arg_specs.
For example, we still want an operator whose arg_specs indicate 2 is the correct wire size to raise the same error as before 3 wires are passed - we're only changing how you specify that 2 is the correct size when defining the operator.
There was a problem hiding this comment.
I have added these tests back and replaced wire_sizes with arg_specs where applicable
| @@ -107,8 +108,6 @@ class CRot(Controlled2): | |||
|
|
|||
| wire_argnames = ("wires",) | |||
|
|
|||
| wire_sizes = (2,) | |||
|
|
|||
There was a problem hiding this comment.
I think in this example this needs to be replaced with arg_specs rather than just removed, since we still need to define the appropriate number of wires for the operator
There was a problem hiding this comment.
I have replaced with arg_specs
|
|
||
| class SX2(Operator2): | ||
| """A new SX gate.""" | ||
|
|
||
| wire_sizes = (1,) | ||
|
|
||
| is_verified_hermitian = True |
There was a problem hiding this comment.
It doesn't actually change anything about the current tests, but its probably best to replace this with arg_specs instead of just removing, as I understand it that would be the intended way of defining these operators going forward. Otherwise this new SX can have more than one wire.
Same goes for the operator definitions in the rest of the tests below :)
There was a problem hiding this comment.
Updated by adding arg_specs = {"wires": Wire[1]}
JerryChen97
left a comment
There was a problem hiding this comment.
Would you mind adding an item to changelog as well as your name to the contributor list? Thanks!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10531 +/- ##
==========================================
- Coverage 99.40% 99.38% -0.03%
==========================================
Files 614 613 -1
Lines 67812 67616 -196
==========================================
- Hits 67411 67202 -209
- Misses 401 414 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi @pragati903 thanks so much for continuing to work on this! I wonder if I could please ask however for a little more descriptive commit messages, so the reviewers can see what is being changed and what might need our attention. Thanks! 🙂 |
| class RX2(Operator2): | ||
| """A simplified RX operator that inherit from Operator2.""" | ||
|
|
||
| dynamic_argnames = ("theta",) | ||
|
|
There was a problem hiding this comment.
Does it need an arg specs as well
There was a problem hiding this comment.
Ah I think I got it it's all only for test dummy op2
There was a problem hiding this comment.
It's technically doesn't change anything about how the tests behave right now, but it would feel more consistent to me if we replaced wire_sizes with arg_specs in all these test classes, especially the ones that get reused and might be used in additional tests in the future. A simplified RX operator should only accept one wire, even if it's just created for testing; it seems like its a standard part of how the operator would be defined normally, so it should be in the test op definition too.
There was a problem hiding this comment.
I have added arg_specs in each place where there was wire_sizes initially in testing operators
…nnylane into remove-wire_sizes
lillian542
left a comment
There was a problem hiding this comment.
Thanks, @pragati903! I left a couple additional comments.
To me it seems like we should replace wire_sizes with arg_specs in the test ops throughout, instead of just removing them. I know it doesn't modify current test behaviour, but it's part of the standard definition for an operator with a set number of wires, which is what all of those tests are creating and testing.
| validation of an operators inputs during construction. Additionally, when defining | ||
| decomposition rules for an operator, operator types with ``arg_specs`` that spans | ||
| all the arguments with static types can be placed in the rules' resources without needing | ||
| to fully construct abstract operators. |
There was a problem hiding this comment.
should we add info in the docstring here about how to define wire sizes in arg_specs (i.e. any of the removed info above about how to support arbitrary size versus set wire size, etc, that might still be relevant, just defined in a new place now)
There was a problem hiding this comment.
Thanks, I have updated the docstring.
| class RX2(Operator2): | ||
| """A simplified RX operator that inherit from Operator2.""" | ||
|
|
||
| dynamic_argnames = ("theta",) | ||
|
|
There was a problem hiding this comment.
It's technically doesn't change anything about how the tests behave right now, but it would feel more consistent to me if we replaced wire_sizes with arg_specs in all these test classes, especially the ones that get reused and might be used in additional tests in the future. A simplified RX operator should only accept one wire, even if it's just created for testing; it seems like its a standard part of how the operator would be defined normally, so it should be in the test op definition too.
| plt.savefig(folder / "mid_measure.png") | ||
| plt.close() | ||
|
|
||
|
|
There was a problem hiding this comment.
These 3 files seem to have been reformatted and then accidentally added to the PR - they aren't related, so let's not change them here.
There was a problem hiding this comment.
Thanks. The formatting checks were failing until I ran black on these files, so I think it wouldn't be possible to merge the PR unless these files are reformatted.
Context:
As part of the ongoing work on future-facing design abstractions for program expression (PL2), the
Operator2base class was originally implemented with awire_sizesproperty to specify the expected sizes of each wire argument. However, with the subsequent addition of the comprehensivearg_specsproperty—which handles the expected shape and data type of every argument including wires—wire_sizeshas become fully redundant.Description of the Change:
wire_sizesclass attribute declaration from theOperator2base class interface.init_wireslogic withinOperator2to eliminate any dependencies or fallbacks related towire_sizes.wire_sizesspecifications from subclass initializations.wire_sizes.Benefits:
Operator2interface by removing redundant abstractions.Possible Drawbacks:
Related GitHub Issues:
#124345