qiskit
qiskit copied to clipboard
Add barrier labels and display in 3 circuit drawers
Summary
Fixes #8428 Fixes #1298
Details and comments
This PR adds a label
parameter to the Barrier
class and displays the label at the top of the barrier in the 3 circuit drawers. The existing label on snapshot
directives is now also displayed. The display in the 'latex' drawer may not be optimal, but there are limitations in qcircuit for displaying text outside boxes. The info is still readable and does not overwrite any gate info.
qc = QuantumCircuit(2)
qc.x(0)
qc.y(1)
qc.barrier()
qc.y(0)
qc.x(1)
qc.barrier(label="End Y/X")
qc.draw('text')
┌───┐ ░ ┌───┐ End Y/X
q_0: ┤ X ├─░─┤ Y ├────░────
├───┤ ░ ├───┤ ░
q_1: ┤ Y ├─░─┤ X ├────░────
└───┘ ░ └───┘ ░
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
- @enavarro51
Pull Request Test Coverage Report for Build 2890221517
- 13 of 21 (61.9%) changed or added relevant lines in 5 files are covered.
- 4 unchanged lines in 3 files lost coverage.
- Overall coverage increased (+0.002%) to 84.051%
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
---|---|---|---|
qiskit/visualization/matplotlib.py | 0 | 8 | 0.0% |
<!-- | Total: | 13 | 21 |
Files with Coverage Reduction | New Missed Lines | % |
---|---|---|
qiskit/extensions/simulator/snapshot.py | 1 | 76.74% |
qiskit/visualization/matplotlib.py | 1 | 25.29% |
qiskit/extensions/quantum_initializer/squ.py | 2 | 79.78% |
<!-- | Total: | 4 |
Totals | |
---|---|
Change from base Build 2882958684: | 0.002% |
Covered Lines: | 56322 |
Relevant Lines: | 67009 |
💛 - Coveralls
I'll dig into the text problem. It's repeatable. Replacing the barrier piece with text should not change the connections.
(Edit) This relates to vertical_compression
. It can be set by the user or it happens when there needs to be space for text to display between gates vertically. Turns out this code does this,
qc = QuantumCircuit(6)
qc.cx(1, 4)
qc.x(1)
qc.draw('text', vertical_compression="low")
q_0: ──────────
┌───┐
q_1: ──■──┤ X ├
│ └───┘
q_2: ──────────
q_3: ──────────
┌─┴─┐
q_4: ┤ X ├─────
└───┘
q_5: ──────────
So this is something that needs to be addressed for controlled gates with low_compression
. I assume open a separate issue for this.
Also on the font size for 'mpl' drawer. There are 2 defined font sizes in the styles - fontsize
- fs and subfontsize
- sfs, which users can change by setting the style parameter. I thought I would need to use sfs for the barrier label to avoid interfering with a control label, but after testing it, I think fs will work fine. I'll make the change.
Done in https://github.com/Qiskit/qiskit-terra/pull/8440/commits/1a17e25056c74e66f6229975af0e86aaf24ef759.