Skip to content

Fix barrier label when output='mpl' #13971

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

atharva-satpute
Copy link
Contributor

Summary

Fixes #13609
Changed the way the barrier label is applied to qubits.

Details and comments

PR-13780 resolved the issue for output=text, but the labels remained incorrectly placed when output=mpl.

@atharva-satpute atharva-satpute requested review from nonhermitian and a team as code owners March 8, 2025 07:26
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Mar 8, 2025
@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 following people are relevant to this code:

@coveralls
Copy link

coveralls commented Mar 8, 2025

Pull Request Test Coverage Report for Build 15516940949

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • 2737 unchanged lines in 113 files lost coverage.
  • Overall coverage decreased (-0.1%) to 87.993%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/visualization/circuit/matplotlib.py 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
crates/circuit/src/duration.rs 1 74.29%
crates/qasm2/src/expr.rs 1 94.23%
qiskit/circuit/controlflow/box.py 1 98.11%
qiskit/circuit/controlledgate.py 1 94.62%
qiskit/circuit/library/quantum_volume.py 1 93.18%
qiskit/circuit/library/standard_gates/r.py 1 96.88%
qiskit/circuit/library/standard_gates/rxx.py 1 97.14%
qiskit/circuit/library/standard_gates/rzx.py 1 97.14%
qiskit/circuit/library/standard_gates/u.py 1 92.22%
qiskit/init.py 1 94.19%
Totals Coverage Status
Change from base Build 13730247126: -0.1%
Covered Lines: 83040
Relevant Lines: 94371

💛 - Coveralls

@atharva-satpute
Copy link
Contributor Author

@jakelishman @nonhermitian could you please take a look at this? Any further changes required?

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.

Hi - sorry this fell through the cracks. The base changeset looks sensible, but please could you add a test and a release note?

Also: could you check if this works sensibly when the user passes something to the wire_map argument that causes a different ordering of qubits, other than simple inversion? (If that turns out to require much deeper changes, we can merge as-is and then follow up with that additional feature request.)

@johnbhurst
Copy link

Hey folks! Thanks so much for your work on this. I tried out the fix-barrier-label-mpl branch with my test program, and it works for reverse_bits=True.

I tried wire_order with the 3-qubit sample program from https://github.com/Qiskit/qiskit:

from qiskit.circuit import QuantumCircuit
import numpy as np

# 1. A quantum circuit for preparing the quantum state |000> + i |111> / √2
qc = QuantumCircuit(3)
qc.barrier(label='init')  # add a barrier for clarity
qc.h(0)             # generate superposition
qc.p(np.pi / 2, 0)  # add quantum phase
qc.cx(0, 1)         # 0th-qubit-Controlled-NOT gate on 1st qubit
qc.cx(0, 2)
qc.barrier(label='final')  # add a barrier for clarity

qc.draw(output='mpl', filename='qc.png')
qc.draw(output='mpl', filename='qc_reverse_bits.png', reverse_bits=True)
qc.draw(output='mpl', filename='qc_wire_order.png', wire_order=[1,2,0])

It generates the barrier labels in the correct positions for each ordering.

qc
qc_reverse_bits
qc_wire_order

Thanks again! Looking forward to seeing this in the release. You rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Barrier labels placed wrongly with draw(reverse_bits=True)
5 participants