Braket backend: circuit mutation and NumPy scalar parity bugs

Open
#1,541 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@andrewmusselman is already working on this.

Since Oct 20, 2026.

  • #1543 by @andrewmusselman — open

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
1/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

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

bug enhancement

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(): call state_vector() on circuit.copy() instead of the caller's circuit, as the Qiskit backend already does.
  • New _as_angle(): strings become FreeParameter, any numbers.Real becomes a plain float; replaces three copies of the isinstance(angle, (int, float)) check in apply_rx/ry/rz_gate.
  • New _bound_inputs(): casts bound values to float; shared by execute_circuit and get_final_state_vector.
  • apply_u_gate: same numeric cast, angles annotated SupportsFloat (so the repo's ty hook 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 binding np.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 ty clean (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

https://claude.ai/code/session_01GuXmXRXdNF43h2FoQcNAZb

Dominant language
Rust
Stars
2.3k
Forks
1k
Avg merge
2d 20h
Merged PRs (30d)
7

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/mahout

All issues in apache/mahout

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.