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

Fix a corner case of SparsePauliOp.apply_layout (backport #12375) #12402

Merged
merged 1 commit into from
May 14, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented May 14, 2024

Summary

SparsePauliOp.apply_layout raises an error if a zero-qubit operator is given.
This PR fixes the case.

from qiskit.quantum_info import SparsePauliOp

op = SparsePauliOp("")
print(op.apply_layout(None, 3))

main branch

SparsePauliOp([''],
              coeffs=[1.+0.j])
Traceback (most recent call last):
  File "/Users/ima/tasks/4_2024/qiskit/terra/tmp/layout.py", line 5, in <module>
    print(op.apply_layout(None, 3))
  File "/Users/ima/tasks/4_2024/qiskit/terra/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py", line 1167, in apply_layout
    return new_op.compose(self, qargs=layout)
  File "/Users/ima/tasks/4_2024/qiskit/terra/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py", line 349, in compose
    q = np.logical_and(z1[:, np.newaxis], x2).reshape((-1, num_qubits))
ValueError: cannot reshape array of size 0 into shape (0)

this PR

SparsePauliOp(['III'],
              coeffs=[1.+0.j])

Although Pauli.apply_layout works correctly, I added the zero-qubit test cases to ensure it.

Details and comments


This is an automatic backport of pull request #12375 done by [Mergify](https://mergify.com).

* fix a corner case of `SparsePauliOp.apply_layout`

* Add zero-qubit tests of Pauli.apply_layout

* use combine and apply isort

* Update releasenotes/notes/fix-sparse-pauli-op-apply-layout-zero-43b9e70f0d1536a6.yaml

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit cea93a0)
@mergify mergify bot requested a review from a team as a code owner May 14, 2024 17:01
@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

@github-actions github-actions bot added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators) labels May 14, 2024
@github-actions github-actions bot added this to the 1.1.0 milestone May 14, 2024
@mtreinish mtreinish enabled auto-merge May 14, 2024 17:16
@coveralls
Copy link

Pull Request Test Coverage Report for Build 9083279815

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.001%) to 89.639%

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 88.2%
crates/qasm2/src/lex.rs 4 93.38%
Totals Coverage Status
Change from base Build 9082210021: -0.001%
Covered Lines: 62265
Relevant Lines: 69462

💛 - Coveralls

@mtreinish mtreinish added this pull request to the merge queue May 14, 2024
Merged via the queue into stable/1.1 with commit 49bd0d3 May 14, 2024
18 checks passed
@mergify mergify bot deleted the mergify/bp/stable/1.1/pr-12375 branch May 14, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants