Skip to content
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

Python: Long gate names are rendered poorly in ASCII art circuits #1476

Open
minestarks opened this issue May 3, 2024 · 1 comment
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@minestarks
Copy link
Member

When rendering circuits (see https://github.com/microsoft/qsharp/blob/main/samples/notebooks/circuits.ipynb) , if the gate label is longer than our fixed column width (e.g. rx(3.1416)) then the resulting ASCII art circuit looks terrible.

We should make column widths vary with the gate label, so that the gates are displayed properly on the qubit wire.

See the below samples in Python.

import qsharp

print("gates that fit the column width")
print("circuit looks okay")

qsharp.eval("""

use q0 = Qubit();
use q1 = Qubit();

H(q0);
H(q1);
X(q1);     
CNOT(q0, q1);
M(q0)

""")

print(qsharp.dump_circuit())


print("q_2 has gates that are too wide for the column width")
print("circuit wires disappear, and the vertical columns don't align anymore")

qsharp.eval("""

use q2 = Qubit();

Rx(1.0, q2);
Rx(1.0, q2);

""")

print(qsharp.dump_circuit())


print("q_3 has gates with both short and long gate labels")
print("here, the column widths should be variable so that the H doesn't take up too much width, but rx(1.000) still fits within a column")

qsharp.eval("""

use q3 = Qubit();

H(q3);
Rx(1.0, q3);
H(q3);
Rx(1.0, q3);
H(q3);
Rx(1.0, q3);


""")

print(qsharp.dump_circuit())

Output:

gates that fit the column width
circuit looks okay
q_0    ── H ─────────── ● ──── M ──
                        │      ╘═══
q_1    ── H ──── X ──── X ─────────

q_2 has gates that are too wide for the column width
circuit wires disappear, and the vertical columns don't align anymore
q_0    ── H ─────────── ● ──── M ──
                        │      ╘═══
q_1    ── H ──── X ──── X ─────────
q_2     rx(1.0000)  rx(1.0000) ──────────────

q_3 has gates with both short and long gate labels
here, the column widths should be variable so that the H doesn't take up too much width, but rx(1.000) still fits within a column
q_0    ── H ─────────── ● ──── M ────────────────
                        │      ╘═════════════════
q_1    ── H ──── X ──── X ───────────────────────
q_2     rx(1.0000)  rx(1.0000) ────────────────────────────
q_3    ── H ── rx(1.0000) ── H ── rx(1.0000) ── H ── rx(1.0000)

@minestarks minestarks added bug Something isn't working needs triage hack-candidates collecting candidate issues and removed needs triage labels May 3, 2024
@tcNickolas tcNickolas added good first issue Good for newcomers and removed hack-candidates collecting candidate issues labels May 9, 2024
@Pulkit1822
Copy link

@minestarks @tcNickolas , I would like to work on this issue. Can please tell me how critical is the issue of long gate names affecting the readability of ASCII art circuits in the Q# framework?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants