-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Long gate in ASCII art circuits - lengthen column width when necessary (
#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.
- Loading branch information
Showing
3 changed files
with
245 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.