qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Create option for measures without arrows in mpl and text circuit drawers

Open enavarro51 opened this issue 5 months ago • 2 comments

Summary

Fixes #4149 Fixes #11895 Fixes #13581

Details and comments

This PR adds an option to the mpl and text drawers, measure_arrows, which will allow measures to be shown with or without the arrows pointing down to the clbits. If True, the default, the behavior will be exactly as it was before this PR. If False, the arrows will not be shown and instead the clbit name will be shown inside the measure box. This will allow measures to appear in the same layer, especially on a measure_all at the end of a circuit, the measures will stack on top of one another.

There is now a user_config option, circuit_measure_arrows which can be added to the user's config file if the user wants to default the option to False.

In some cases, especially in the text drawer, the measures may take up more room when the option is False due to the need to put the register/clbit name in the measure box.

Some examples,

qr = QuantumRegister(3, "qr")
cr = ClassicalRegister(3, "c")
qc = QuantumCircuit(qr, cr)
qc.x(0)
qc.h(0)
qc.measure(0, 0)
qc.x(1)
qc.h(1)
qc.measure(1, 1)
qc.x(2)
qc.h(2)
qc.measure(2, 2)
qc.draw(measure_arrows=False)

image

      ┌───┐┌───┐┌───────┐
qr_0: ┤ X ├┤ H ├┤ M-c_0 ├
      ├───┤├───┤├───────┤
qr_1: ┤ X ├┤ H ├┤ M-c_1 ├
      ├───┤├───┤├───────┤
qr_2: ┤ X ├┤ H ├┤ M-c_2 ├
      └───┘└───┘└───────┘
 c: 3/═══════════════════

enavarro51 avatar Jun 14 '25 23:06 enavarro51

One or more of the following people are relevant to this code:

  • @enavarro51
  • @Qiskit/terra-core

qiskit-bot avatar Jun 14 '25 23:06 qiskit-bot

Pull Request Test Coverage Report for Build 15744321646

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

  • 30 of 53 (56.6%) changed or added relevant lines in 5 files are covered.
  • 864 unchanged lines in 19 files lost coverage.
  • Overall coverage remained the same at 88.009%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/visualization/circuit/_utils.py 11 12 91.67%
qiskit/visualization/circuit/text.py 9 10 90.0%
qiskit/user_config.py 3 6 50.0%
qiskit/visualization/circuit/matplotlib.py 4 22 18.18%
<!-- Total: 30 53
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.23%
qiskit/circuit/_classical_resource_map.py 1 75.0%
qiskit/circuit/annotation.py 2 95.56%
qiskit/synthesis/boolean/boolean_expression.py 2 96.7%
qiskit/visualization/circuit/matplotlib.py 3 48.16%
crates/circuit/src/symbol_expr.rs 4 73.81%
crates/circuit/src/lib.rs 6 95.0%
crates/qasm2/src/lex.rs 6 92.48%
qiskit/providers/backend.py 6 91.43%
crates/circuit/src/classical/expr/var.rs 7 93.4%
<!-- Total: 864
Totals Coverage Status
Change from base Build 15687720415: 0.0%
Covered Lines: 84032
Relevant Lines: 95481

💛 - Coveralls

coveralls avatar Jun 18 '25 22:06 coveralls

Thanks, Raynel. My 100th merged PR. Some kind of milestone, I guess.

enavarro51 avatar Sep 03 '25 14:09 enavarro51