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 reverse_bits with registerless bits in all 3 circuit drawers #7319

Merged
merged 69 commits into from
Feb 11, 2022

Conversation

enavarro51
Copy link
Contributor

Summary

Fixes #7303

Details and comments

This PR fixes an issue with the 3 circuit drawers where the registerless bits indexing was not reversed when the reverse_bits option was used. It now correctly displays as,

bits = [Qubit(), Qubit(), Clbit(), Clbit()]
bits1 = [Clbit()]
cr = ClassicalRegister(2, "cr")
cs = ClassicalRegister(2, "cs")
qc = QuantumCircuit(bits, cr, [Clbit()], cs, bits1)
qc.h(0).c_if(4, 0)
qc.measure(0, bits[3])
qc.draw('mpl', scale=0.7,cregbundle=False, reverse_bits=True)

image

@coveralls
Copy link

coveralls commented Nov 27, 2021

Pull Request Test Coverage Report for Build 1830645646

  • 250 of 358 (69.83%) changed or added relevant lines in 4 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.05%) to 83.334%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/visualization/utils.py 55 57 96.49%
qiskit/visualization/text.py 61 75 81.33%
qiskit/visualization/latex.py 109 131 83.21%
qiskit/visualization/matplotlib.py 25 95 26.32%
Files with Coverage Reduction New Missed Lines %
qiskit/visualization/matplotlib.py 3 25.58%
Totals Coverage Status
Change from base Build 1829418994: -0.05%
Covered Lines: 52228
Relevant Lines: 62673

💛 - Coveralls

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.

Thanks for doing this - the new form looks right. The way that registers interact in the "order" with respect to loose bits is slightly unusual, but that's because of the super weird position ClassicalRegister is in right now in our data model - not the fault of this PR at all.

qiskit/visualization/utils.py Outdated Show resolved Hide resolved
qiskit/visualization/utils.py Outdated Show resolved Hide resolved
@enavarro51
Copy link
Contributor Author

@jakelishman I have now deprecated qregs, cregs, global_phase, layout, and calibrations from the 3 circuit drawers and these are now set using the newly passed in circuit kwarg. If circuit is None, a new circuit is created in the __init__ of the drawer using the qubits and clbits args. I also added with_layout as a kwarg and this is used to decide whether to use the QuantumCircuit._layout or not. I believe this covers all the outstanding review issues.

Comment on lines +120 to +126
warn(
"The 'circuit' kwarg to the QCircuitImage class must be a valid "
"QuantumCircuit and not None. A new circuit is being created using "
"the qubits and clbits for rendering the drawing.",
DeprecationWarning,
2,
)
Copy link
Member

Choose a reason for hiding this comment

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

Is this a deprecation warning? What is being replaced with in the future?

@1ucian0 1ucian0 added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Feb 11, 2022
Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

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

Thanks Edwin!

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.

Circuit drawer reverse_bits does not reverse registerless bits
5 participants