-
Notifications
You must be signed in to change notification settings - Fork 107
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
Comments
@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? |
@Pulkit1822 apologies for missing your post. It's been a while so hopefully you're still interested -- I'd say this is a fairly low-priority bug, and with no-one that I know currently working on it, it's probably a good first issue to experiment with. |
@minestarks
Any other hints? |
@ggridin, are you still working on this issue? I took a look at the code, and this seems to be known behavior, as can be seen I can think of several ways to resolve this issue:
Option 3 is probably the only future-proof solution, but is also a fair amount of work. So I personally believe a combination of 1 & 2 is the best approach for now. Specifically:
Do you have opinions on this? If we go with 1 & 2 I can probably make this change myself. If we want to go with 3, someone who's more experienced with this library should probably pick it up, or at least design it. |
@Morcifer |
I ended up implementing the future-proof way, because it was possible to do with only one large change relative to the previous logic (no need for a complete re-design). |
@minestarks I've actually been working on a solution and have already raised a PR for it. I made a couple of key changes to improve the rendering of long gate names in ASCII art circuits, specifically adjusting column widths to accommodate label length and ensuring proper alignment of columns and circuit wires. I'd love to hear any suggestions you may have to further improve the fix. Please feel free to review and let me know if there's anything I can do to enhance it. Thank you again for your time. |
Thanks for the PRs - sadly we can only take one, I'll review the PRs first-come first-served and see if one looks more viable than the other. Also, missed this message by @ggridin over the summer apparently. Fair question - I'll plan to update some READMEs in the repo to make the dev loop a bit more explicit
|
I'm really sorry about the confusion - I didn't notice it was two different people posting the questions, so I accidentally only tagged one when asking if I could pick it up. I'll make sure to pay closer attention next time! |
#2126) See issue #1476. I tried to keep the logic as close as possible to the original, because I wanted to keep it easy to review it in relation to the old logic. The main change here is that instead of having the `ObjectsByColumn` of every Row be a `FxHashMap<usize, String>` which contains the 7-width-wide strings, it's now a `FxHashMap<usize, CircuitObject>`, where `CircuitObject` is an enum that supports every circuit object except for than blanks and wires (because those are inserted later on, on-the-go). Using this enum allows us to calculate the required `ColumnWidthsByColumn` (a `FxHashMap<usize, usize>`) right before calling `row.fmt` - so we know what width the `CircuitObjects` need to be when converted into strings. In the example from the ticket, this means that this circuit: ``` use q3 = Qubit(); H(q3); Rx(1.0, q3); H(q3); Rx(1.0, q3); H(q3); Rx(1.0, q3); ``` Which used to give: ``` 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) ``` Now gives ``` 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) ── ``` Apart from this desired change for long gates, the only notable difference is that, where ket-zero (`|0〉`) used to show as a width-5 circuit object (`─ |0〉 ─`, it now shows as a width-7 circuit object (`── |0〉 ──`) - you can see the difference in every test that used it.
#2126) See issue #1476. I tried to keep the logic as close as possible to the original, because I wanted to keep it easy to review it in relation to the old logic. The main change here is that instead of having the `ObjectsByColumn` of every Row be a `FxHashMap<usize, String>` which contains the 7-width-wide strings, it's now a `FxHashMap<usize, CircuitObject>`, where `CircuitObject` is an enum that supports every circuit object except for than blanks and wires (because those are inserted later on, on-the-go). Using this enum allows us to calculate the required `ColumnWidthsByColumn` (a `FxHashMap<usize, usize>`) right before calling `row.fmt` - so we know what width the `CircuitObjects` need to be when converted into strings. In the example from the ticket, this means that this circuit: ``` use q3 = Qubit(); H(q3); Rx(1.0, q3); H(q3); Rx(1.0, q3); H(q3); Rx(1.0, q3); ``` Which used to give: ``` 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) ``` Now gives ``` 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) ── ``` Apart from this desired change for long gates, the only notable difference is that, where ket-zero (`|0〉`) used to show as a width-5 circuit object (`─ |0〉 ─`, it now shows as a width-7 circuit object (`── |0〉 ──`) - you can see the difference in every test that used it.
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.
Output:
The text was updated successfully, but these errors were encountered: