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

Fixed Issue 11026: SparsePauliOp.apply_layout should do nothing if given None #11041

Merged
merged 7 commits into from Nov 16, 2023

Conversation

SoranaAurelia
Copy link
Contributor

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.

@SoranaAurelia SoranaAurelia requested review from ikkoham and a team as code owners October 18, 2023 23:38
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Oct 18, 2023
@CLAassistant
Copy link

CLAassistant commented Oct 18, 2023

CLA assistant check
All committers have signed the CLA.

@qiskit-bot
Copy link
Collaborator

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:

  • @Qiskit/terra-core
  • @ikkoham

@SoranaAurelia
Copy link
Contributor Author

@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)

@coveralls
Copy link

coveralls commented Oct 29, 2023

Pull Request Test Coverage Report for Build 6868163290

Warning: 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.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • 25 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.03%) to 85.902%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 7 91.16%
crates/qasm2/src/parse.rs 18 96.67%
Totals Coverage Status
Change from base Build 6865596785: -0.03%
Covered Lines: 65921
Relevant Lines: 76740

💛 - Coveralls

Comment on lines 1091 to 1095
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)
Copy link
Member

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)

Copy link
Member

@jakelishman jakelishman left a 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?

@SoranaAurelia
Copy link
Contributor Author

@jakelishman I added a release note regarding this. Can you please check if it's ok?

Copy link
Member

@jakelishman jakelishman left a 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!

@jakelishman jakelishman added this pull request to the merge queue Nov 16, 2023
@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators) labels Nov 16, 2023
@jakelishman jakelishman added this to the 1.0.0pre1 milestone Nov 16, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 16, 2023
@jakelishman jakelishman added this pull request to the merge queue Nov 16, 2023
Merged via the queue into Qiskit:main with commit 8707699 Nov 16, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: quantum info Related to the Quantum Info module (States & Operators)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

SparsePauliOp.apply_layout should do nothing if given None
5 participants