feature: add interactive Plotly circuit visualization#1292
Conversation
|
not linked, maybe a keyword fixes #1250 missing |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feature/graphical-visualization #1292 +/- ##
===================================================================
- Coverage 100.00% 99.83% -0.17%
===================================================================
Files 173 174 +1
Lines 11375 11743 +368
Branches 1472 1536 +64
===================================================================
+ Hits 11375 11724 +349
- Misses 0 13 +13
- Partials 0 6 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
thank you, I'll look into it |
742b747 to
1242555
Compare
|
Pushed a follow-up to bring patch coverage back to 100%. |
|
Thanks for picking this up, @spital — I also have an implementation open in #1284 for the same issue, so it's good to compare approaches. A few things that stood out in your PR: Nice catches:
Design divergence worth discussing:
I'd suggest the maintainers (@speller26 @krneta) compare #1284 and #1292 side by side. They overlap significantly but each has unique strengths — #1284 is lighter (~68 tests, minimal base-class changes), #1292 is more comprehensive (GPhase fix, text-diagram consistency, 426 tests). Might be worth cherry-picking the best parts of both. |
Summary
Closes #1250
(edited - would github link issue now?)
This adds
PlotlyCircuitDiagram, an optional interactive renderer for Braket circuits. It reuses the graphical circuit layout used by the Matplotlib renderer and returns aplotly.graph_objects.FigurefromCircuit.show("interactive")orCircuit.show("plotly"). The existing defaultCircuit.show()Matplotlib behavior is unchanged.What changed
PlotlyCircuitDiagramundergraphical_diagram_builders.Circuit.show("interactive")/Circuit.show("plotly")aliases that return a Plotly figure.updatemenus.amazon-braket-sdk[interactive]optional extra and lazy Plotly import handling.examples/plotly_circuit_visualization.py.Correctness note
While wiring the global-phase footer into the renderers, I found that powered
GPhaseinstructions were not reflected in the publicCircuit.global_phasevalue: the current value used only the raw angle and ignored the instruction power. This PR updates the public value and the text/graphical footers to use the effective phaseangle * power, matching the unitary behavior. PoweredGPhaseinstructions are also suppressed as standalone gate boxes so they appear only in the global-phase footer.Testing
After final formatting, I ran:
python -m pytest -p no:randomly test/unit_tests/braket/circuits/test_plotly_circuit_diagram.py -qpython -m pytest -p no:randomly test/unit_tests -qruff format --check .ruff check srcAI assistance disclosure
I used AI assistants (Codex, Claude, and Hermes) to help draft and review parts of the renderer, tests, and PR text. I manually reviewed the implementation against #1250, refined the generated suggestions, and verified the final code locally with the tests and lint checks above.
Merge Checklist
General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.