Braket backend: circuit mutation and NumPy scalar parity bugs
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 1/100
Research direction
The issue says both fixes are in qumat/amazon_braket_backend.py and regression tests are in testing/qumat/test_amazon_braket_backend.py. Start by reading the tests and backend changes; run the testing/qumat suite to check the circuit-copy and NumPy scalar cases. Done means the tests pass and state-vector inspection leaves the caller's circuit usable for shot-based execution.
Written by the indexing model from the issue text.
Description
Title: [Qumat] Fix two Braket backend parity bugs: circuit mutation and NumPy scalars
Purpose of PR
Two common patterns work on Qiskit and Cirq but fail on Amazon Braket. Reading the state vector mutated the caller's circuit, so a later shot-based run raised; and NumPy scalar angles or bound values (as produced by NumPy/PyTorch training loops) were rejected. Both are fixed in qumat/amazon_braket_backend.py.
Related Issues or PRs
Fixes a bug found during the CoC Glasgow 2026 hackathon prep (no issue filed yet — file one with the reproducer below before opening).
Reproducer (found by the backend parity sweep):
q.get_final_state_vector() # inspect the state...
q.execute_circuit() # ...then sample it: Braket raises
("StateVector or Amplitude cannot be specified when shots>0")
q.apply_rx_gate(0, "t")
q.execute_circuit({"t": np.float32(0.5)}) # Braket raises
("Cannot wrap 0.5 into literal type"; an np.float32 angle passed directly raises "FreeParameter names must be strings")
Changes Made
get_final_state_vector(): callstate_vector()oncircuit.copy()instead of the caller's circuit, as the Qiskit backend already does.- New
_as_angle(): strings becomeFreeParameter, anynumbers.Realbecomes a plainfloat; replaces three copies of theisinstance(angle, (int, float))check inapply_rx/ry/rz_gate. - New
_bound_inputs(): casts bound values tofloat; shared byexecute_circuitandget_final_state_vector. apply_u_gate: same numeric cast, angles annotatedSupportsFloat(so the repo'styhook passes); U stays non-parameterisable, as on the other backends.testing/qumat/test_amazon_braket_backend.py: mocked tests assert the copy is used and the original untouched; end-to-end local-simulator regression; NumPy scalar tests for rotation and U gates and for bindingnp.float32(pi).
Testing
testing/qumat: 604 passed (main: 589).- The new tests fail against the old code (3 for the copy fix; 14 for the NumPy fix).
- ruff, ruff format and
tyclean (no new diagnostics vs main). - Not verified: AWS SV1 (cloud); the copy and float casts are device-independent.
Merging
Conflicts with the #1507 PR on one import line in testing/qumat/test_amazon_braket_backend.py. A rebased "#1507 after A1" version exists.
🤖 Generated with Claude Code
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 1k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 7
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a 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 apache/mahout
-
[Bug] Amazon Braket get_final_state_vector() changes the circuit, so execute_circuit() fails afterwardsPossibly taken @Howardisme claimed this 48 days ago. Openbug enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
apache/mahout#1538 · 1 comment ·
Maintainers usually reply within 2 days
-
[Bug] Reusing a parameter name on two gates fails on Qiskit only (name conflict adding parameter)Possibly taken @Imad2702 claimed this 50 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/mahout#1509 · 2 comments ·
Maintainers usually reply within 2 days
-
[Bug] Cirq backend ignores the initialized simulator and creates its own cirq.Simulator()Possibly taken @Howardisme claimed this 49 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
apache/mahout#1508 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
[Bug] Unknown backend_name leaks ModuleNotFoundError instead of a clear ValueErrorPossibly taken @Asterisk-Hunter claimed this 38 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
apache/mahout#1506 · 5 comments ·
Maintainers usually reply within 2 days
-
bug docs enhancement question
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
ClickHouse/clickhouse-rs#589 ·
Maintainers usually reply within 2 days
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pbakaus/impeccable#1887 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
bruits/satteri#400 · 2 comments ·
Maintainers usually reply within 5 days