Add better support for MatrixGate in SVG output
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
Is your feature request related to a use case or problem? Please explain
This feature request is basically to implement the suggestion by @mpharrigan in #2313: handle MatrixGate in the SVG output module.
Describe the solution you would prefer
Here are some ideas for how to extend the code to do it:
-
Indexed label + SVG
<title>tooltip (recommended default): Render unnamedMatrixGates asU(orU₁,U₂, ... deduplicated by matrix value so repeated gates share an index;U₁[1],U₁[2]across multi-qubit wires) and attach the formatted matrix in an SVG<title>element for native browser/Jupyter hover inspection. Trade-off: keeps gate boxes uniform at any2^n × 2^nsize with zero JS, but exact entries are hidden in static PNG/PDF exports. -
Indexed label + optional legend below the circuit: Use the same
U₁,U₂labels on the wires and print each unique matrix in a compact footer block underneath the diagram (opt-in or auto-enabled for small matrices). Trade-off: preserves exact matrix values in static exports without distorting wire/column spacing, at the cost of extra vertical height and couplingcircuit_to_svg(or aget_circuit_diagram_infohook) to pass matrix data. -
Size-capped inline matrix: Render small matrices (e.g.,
2×2, optionally real/simple4×4) directly inside the gate box using multi-line<tspan>elements and vector brackets, and fall back to option 1 (U₁+<title>, orU(4×4)) for larger dimensions. Trade-off: stays consistent withto_text_diagram()for single-qubit gates and can be implemented insidetdd_to_svgdirectly from the multi-line text, but even a2×2complex matrix noticeably widens its column and tallens its row (the dynamic-spacing issue where PR #4630 stalled). -
Visual fingerprint glyph (magnitude/phase grid) +
<title>: Draw a small2^n × 2^ngrid inside the gate box encoding entry magnitude (opacity or cell size) and phase (hue), with the numeric matrix in<title>. Trade-off: reveals sparsity and structure (diagonal, permutation, block-diagonal) inside a fixed square box, but is unreadable numerically without hover and departs from Cirq SVG's monochrome styling (accessibility and grayscale print concerns).
Option 1 works best as the baseline, optionally combined with option 2 (legend) or option 3 (inline 2×2 only) when static readability of entries matters. For tdd_to_svg specifically, note that Cirq's to_text_diagram_drawer already strips the MatrixGate object down to its multi-line string, so deduplicating by matrix or attaching a <title> requires either hashing the formatted matrix string from tdd or passing a custom get_circuit_diagram_info callback from circuit_to_svg.
How urgent is this for you? Is it blocking important work?
P2 – we should do it in the next couple of quarters
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 48
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantumlib/Cirq
-
Potential missed optimization: `drop_diagonal_before_measurement` leaves an identity `PhasedXZGate` that blocks further removalPossibly taken @jangyoujin0917 claimed this 22 days ago. Openarea/gates area/optimization kind/feature-request triage/accepted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quantumlib/Cirq#8523 · 1 comment ·
Maintainers usually reply within 1 day
-
`defer_measurements` ignores `BitMaskKeyCondition.index` and changes circuit behaviorMay be free again @Tejendra-06 claimed this 54 days ago, and no pull request is open. Opengood for learning help wanted kind/bug-report skill/experienced triage/accepted triage/wont-fix
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
quantumlib/Cirq#8361 · 8 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
area/docstrings area/google kind/bug-report triage/discuss
Difficulty 1/5 1-3 hours Newbie friendliness 91/100
quantumlib/Cirq#8587 ·
Maintainers usually reply within 1 day
-
kind/bug-report triage/discuss
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
quantumlib/Cirq#8580 ·
Maintainers usually reply within 1 day
-
triage/discuss
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
quantumlib/Cirq#8558 ·
Maintainers usually reply within 1 day
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day