Braket backend: circuit mutation and NumPy scalar parity bugs

Aperta
#1,541 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@andrewmusselman ci sta già lavorando.

Dal 20/10/2026.

  • #1543 di @andrewmusselman — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
1-3 ore
Idoneità per principianti
1/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Rust
Stelle
2.3k
Fork
1k
Merge medio
2g 20h
PR unite (30g)
7

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/mahout

Tutte le issue di apache/mahout

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.