[Bug] Amazon Braket get_final_state_vector() changes the circuit, so execute_circuit() fails afterwards

Open Beginner friendly
#1,538 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@Howardisme is already working on this.

Since Oct 18, 2026.

  • #1539 by @Howardisme — open

Assessment

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

Research direction

Read qumat/amazon_braket_backend.py at get_final_state_vector() and the related coverage in test_amazon_braket_backend.py. First check how the method obtains the state vector and how existing tests detect circuit mutations; verify that execution and drawing still work after reading the state vector. Done means the circuit remains unchanged and the regression is covered by a test.

Written by the indexing model from the issue text.

Description

bug enhancement
What

amazon_braket_backend.get_final_state_vector() calls circuit.state_vector() on the circuit held by QuMat. In Braket this adds a StateVector result type to the circuit in place, and that result type is only allowed with shots=0. After reading the state vector once, the circuit can no longer be executed with shots:

from qumat import QuMat

qm = QuMat({"backend_name": "amazon_braket", "backend_options": {"simulator_type": "local", "shots": 10}})
qm.create_empty_circuit(1)
qm.apply_hadamard_gate(0)

qm.get_final_state_vector()
qm.execute_circuit()
# ValueError: StateVector or Amplitude cannot be specified when shots>0

Actual result: after get_final_state_vector(), execute_circuit() (and anything built on it, such as measure_overlap()) raises ValueError, and draw_circuit() shows an extra Additional result types: StateVector line. Qiskit and Cirq are not affected: Qiskit works on circuit.copy(), and Cirq's simulate() does not modify the circuit.

The existing TestCircuitMutationPrevention test does not catch this because it compares len(circuit.instructions), and Braket stores result types separately from instructions.

Expected result:get_final_state_vector() leaves the circuit unchanged on all backends, as #1072 did for Cirq's execute_circuit().

Where: qumat/amazon_braket_backend.py (get_final_state_vector) / test_amazon_braket_backend.py

Environment
  • OS: macOS 26.6.2
  • Python version: 3.12.15
  • Qumat version: 0.7.0.dev0 (main at 37cf3878c)
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.