Skip to content

Enhancements to the Rust circuit drawer #15849

Description

@eliarbel

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      ├
                   └───────┘

The vertical alignment issue is being handled here: #16207

  • 5) Draw measurement box like this:
┌─┐         
┤M├
└╥┘

instead of:

┌───┐
┤ M ├
└─╥─┘

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:

  • 7) Draw CPhase gate like this:
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).

  • 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.


Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RustThis PR or issue is related to Rust code in the repositorymod: visualizationqiskit.visualization

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions