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

"cregbundle set to False" warning should not raised when no classical bits are involved #8689

Merged
merged 15 commits into from
Oct 1, 2022

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Sep 6, 2022

@Guillermo-Mijares-Vilarino discovered that the following code raises a very confusing warning:

from qiskit.circuit.library import QFT
qft = QFT(3)
qft.decompose().draw('mpl', reverse_bits=True)
RuntimeWarning: Cregbundle set to False since either reverse_bits or wire_order has been set.
  wire_order=wire_order,

This fix checks if classical bits are involved before touching cregbundle.

Fixes #8690

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

@coveralls
Copy link

coveralls commented Sep 6, 2022

Pull Request Test Coverage Report for Build 3162371682

  • 12 of 12 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 84.663%

Totals Coverage Status
Change from base Build 3162371342: 0.004%
Covered Lines: 61510
Relevant Lines: 72653

💛 - Coveralls

@Guillermo-Mijares-Vilarino
Copy link
Contributor

This PR would be very helpful for the explanation section I'm adding in #8685.

@jakelishman
Copy link
Member

Would you like to make this part of a slightly larger issue surrounding the cregbundle parameter? I've just made #8690 to describe it, although the behaviour has been present for a super long time. Your fix here is good with or without touching that issue, I'm just bringing it up since you're touching the code anyway.

---
fixes:
- |
When :func:`~circuit_drawer` was used with `reverse_bits=True` on a circuit without classical bits, warning about `cregbundle` was raised, creating confusion. The warning was removed for this case.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could do with wrapping - when reno generates the rst for the metapackage, this goes in at a few levels of nesting that might cause its linter to complain.

(It wouldn't hurt for us to get a checker running on Terra to enforce that.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 56d3e38

Comment on lines 124 to 132
def test_reverse_bits(self):
"""Test reverse_bits should not raise warnings when no classical qubits:
See: https://github.com/Qiskit/qiskit-terra/pull/8689"""
circuit = QuantumCircuit(3)
circuit.x(1)

with catch_warnings():
simplefilter("error")
visualization.circuit_drawer(circuit, reverse_bits=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to test the output of this against the expected one as well, just to be sure.

I think the test suite should automatically fail if the warning is emitted without messing with catch_warnings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to test the output of this against the expected one as well, just to be sure.

checking the result in 6a1e223

I think the test suite should automatically fail if the warning is emitted without messing with catch_warnings?

I dont disagree, but I think we have some warnings around. Maybe for another PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the warning missing

@1ucian0 1ucian0 added this to the 0.22 milestone Sep 13, 2022
@1ucian0
Copy link
Member Author

1ucian0 commented Sep 18, 2022

Would you like to make this part of a slightly larger issue surrounding the cregbundle parameter?

I fixed that one too by changing the way that the default is handled for that parameter.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some small doc fixes inline

@mtreinish mtreinish added Changelog: Bugfix Include in the "Fixed" section of the changelog automerge labels Sep 30, 2022
@mergify mergify bot merged commit 2b8a9e0 into Qiskit:main Oct 1, 2022
@1ucian0 1ucian0 deleted the fix/8685 branch October 4, 2022 09:51
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuantumCircuit.draw triggers warning with default arguments for single bits
7 participants