-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fixed Issue 11026: SparsePauliOp.apply_layout should do nothing if given None #11041
Fixed Issue 11026: SparsePauliOp.apply_layout should do nothing if given None #11041
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:
|
@mtreinish I brought the branch up to date with the main because I saw some tests were failing due to the old error (regarding the name property PR11065). I think the coverage should pass now (sorry if you are the wrong person to tag, I'm still new here) |
Pull Request Test Coverage Report for Build 6868163290Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
def test_apply_layout_null_layout(self): | ||
"""Test apply_layout with a null layout""" | ||
op = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)]) | ||
res = op.apply_layout(layout=None, num_qubits=5) | ||
self.assertEqual(op, res) |
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 test looks odd to me: it specifically asks for num_qubits=5
, but the output operator then asserted to be 2q (by comparison to the input op, which is 2q). Certainly I think that that should be invalid, but it's not clear to me whether it should be an error during SparsePauliOp.apply_layout
, or whether that method should do something to expand the operator. I expect it should be an error, but I've opened a discussion in the initial thread: #11026 (comment)
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 very much for this. The new tests look good and complete, and the new behaviour matches what's discussed in the issue. Could you add a one-line "feature" release note explaining that SparsePauliOp.apply_layout
now accepts None
as an argument, to support the case that no transpilation/routing took place?
@jakelishman I added a release note regarding this. Can you please check if it's ok? |
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.
Looks fine to me, thanks for the release note and the updates!
Summary
fixes #11026 SparsePauliOp.apply_layout should do nothing if given None
Details and comments
As pointed out in the issue #11026 : since using a simulator as a backend for the transpiler function gives a circuit with a None layout, when passing the layout to the apply_layout function an exception is raised. It would be better if the function does nothing in this case, so the same code can be run for both a simulator and a backend. Therefore, an additional condition is added to treat this case.