The ability to draw quantum circuits natively from Rust (i.e. from CircuitData) as text was added in #15357. The initial implementation of this feature was done with the C API usage in mind, hence included support for drawing circuit elements which can be constructed from C API, which were standard and unitary gates and standard instructions during the development period of #15357. While the Rust circuit drawer produces output which is very similar to the one produced by the Python drawer hence already usable, there are still known gaps in the current implementation which should be closed to improve usability. In addition, the Rust model has evolved since the initial submission of #15357 and includes operation types which are not supported currently by the Rust circuit drawer.
This issue describes the known gaps in the drawer which are worth handling for improved usability.
┌───────┐┌────────┐┌─────────┐┌──────────┐
q: ┤ Rx(π) ├┤ Rx(2π) ├┤ Rx(π/3) ├┤ Rx(3π/2) ├
└───────┘└────────┘└─────────┘└──────────┘
instead of this:
┌───────────────────────┐┌───────────────────────┐┌────────────────────────┐┌──────────────────────┐
q_0: ┤ Rx(3.141592653589793) ├┤ Rx(6.283185307179586) ├┤ Rx(1.0471975511965976) ├┤ Rx(4.71238898038469) ├
└───────────────────────┘└───────────────────────┘└────────────────────────┘└──────────────────────┘
We should have something in Rust similar to
|
def pi_check(inpt, eps=1e-9, output="text", ndigits=None): |
┌───────────┐┌──────┐
q_0: ┤0 ├┤0 ├
│ Rxx(1.2) ││ │
q_1: ┤1 ├┤ ├
└───────────┘│ Ecr │
q_2: ─────────────┤ ├
│ │
q_3: ─────────────┤1 ├
└──────┘
instead of this:
┌────────────┐┌───────┐
q_0: ┤0 Rxx(1.2) ├┤0 ├
│ ││ │
q_1: ┤1 ├┤ Ecr ├
└────────────┘│ │
q_2: ──────────────┤ ├
│ │
q_3: ──────────────┤1 ├
└───────┘
instead of:
Like the previous bullet, this is mostly an aesthetic improvement, but worthwhile to further visually highlight the difference between measurement instructions and e.g. standard gates.
Other known differences between the Rust circuit drawer and the Python one, are included here for completeness. These would be nice to close, but arguably they are really minor from usability perspective:
q_0: ─■───────
│P(0.5)
q_1: ─■───────
instead of:
q_0: ─────■─────
┌────┴────┐
q_1: ┤ P(0.5) ├
└─────────┘
┌───┐┌─┐
q: ┤ H ├┤M├
└───┘└╥┘
c: ══════╩═
instead of this:
┌───┐┌───┐
q_0: ┤ H ├┤ M ├
└───┘└─╥─┘
c_0: ═══════╩══
Note that for classical bits the above is relevant only if cregbundle=False (which is the case in this example).
The ability to draw quantum circuits natively from Rust (i.e. from
CircuitData) as text was added in #15357. The initial implementation of this feature was done with the C API usage in mind, hence included support for drawing circuit elements which can be constructed from C API, which were standard and unitary gates and standard instructions during the development period of #15357. While the Rust circuit drawer produces output which is very similar to the one produced by the Python drawer hence already usable, there are still known gaps in the current implementation which should be closed to improve usability. In addition, the Rust model has evolved since the initial submission of #15357 and includes operation types which are not supported currently by the Rust circuit drawer.This issue describes the known gaps in the drawer which are worth handling for improved usability.
1) Add support for
PauliProductMeasurementandPauliProductRotationgates. These are now part of the Rust model and should be rendered asBoxedElement::Multivisualization element.Add Pauli product gates support to the Rust circuit drawer #15948
2) Print$pi$ fractions and multiples nicely. E.g., render this:
instead of this:
We should have something in Rust similar to
qiskit/qiskit/circuit/tools/pi_check.py
Line 27 in 919eaf6
fix: PI format for rust Circuit display #15917
3) Truncate long decimal values, e.g. render the box label
Rx(1.1235)instead ofRx(1.123456789).Format floating-point values in the Rust circuit drawer #15899
4) This is a minor aesthetic improvement: fix label rendering of multi-wire boxes.
There are two issues: a) labels should not be left-padded with space and b)(handled in Add Pauli product gates support to the Rust circuit drawer #15948) vertical alignment should be fixed for boxes which span even number of wires. For example, render this:instead of this:
instead of:
Like the previous bullet, this is mostly an aesthetic improvement, but worthwhile to further visually highlight the difference between measurement instructions and e.g. standard gates.
Add control flow op support to the Rust circuit drawer #16063
Other known differences between the Rust circuit drawer and the Python one, are included here for completeness. These would be nice to close, but arguably they are really minor from usability perspective:
CPhasegate like this:instead of:
instead of this:
Note that for classical bits the above is relevant only if
cregbundle=False(which is the case in this example).Avoid adding auto-indices numbers for single bit registers #15966
9) There was an issue with vertical line alignment of controlled gates whose label length are even, which was fixed in 9a00b5a. The fix was hacky in the sense that it added an extra padding space to the label string, making its length even. A better fix, i.e. without adding an extra space, would require changing the way an entire visual element padding is computed in final drawing stage, once the text width of each circuit layer is already known.