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

Long gate in ASCII art circuits - lengthen column width when necessary #2126

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Morcifer
Copy link
Contributor

@Morcifer Morcifer commented Jan 25, 2025

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.

column = row.next_column;
}
}
let column = rows[begin..end]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same logic, and I believe it's more readable - but let me know if you want me to put it back the way it was.

@Morcifer Morcifer changed the title (personal placeholder) Long gate in ASCII art circuits - proper fix Long gate in ASCII art circuits - lengthen column width when necessary Jan 26, 2025
@Morcifer Morcifer marked this pull request as ready for review January 26, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant