amazon-braket-sdk-python icon indicating copy to clipboard operation
amazon-braket-sdk-python copied to clipboard

Tensored Paulis formed without explicit qubit yield IR error

Open sesmart opened this issue 1 month ago • 2 comments

Describe the bug

Error in generating OpenQASM from observables without indices. This also occurs using the braket.quantum_information.PauliString(..).to_unsigned_observable() method.

To reproduce

from braket.circuits.observables import X
from braket.circuits.serialization import IRType

good = (X(0) @ X(1)).to_ir(IRType("OPENQASM") # works 
bad  = (X() @ X()).to_ir(IRType("OPENQASM") # does not work 

Expected behavior

Given case above.

Screenshots or logs

obs2.to_ir(ir_type = IRType("OPENQASM")) <generator object IndexedSet.iter.. at 0x1274de670> Traceback (most recent call last): File "", line 1, in File "/ZZZ/braket/circuits/observable.py", line 95, in to_ir return self._to_openqasm( ^^^^^^^^^^^^^^^^^^ File "/ZZZ/braket/circuits/observables.py", line 402, in _to_openqasm obs_target.add(next(use_qubits)) ^^^^^^^^^^^^^^^^ StopIteration

System information A description of your system. Please provide:

  • Amazon Braket Python SDK version: 1.103
  • Amazon Braket Python Schemas version: 1.26.1
  • Amazon Braket Python Default Simulator version: 1.32.0
  • Python version: 3.12.10

sesmart avatar Nov 19 '25 18:11 sesmart

This shouldn't work (you'd need to pass a target to .to_ir, but the error message should be clearer.

speller26 avatar Dec 02 '25 21:12 speller26

Might be worth fixing PauliString to automatically create targets if none are specified.

speller26 avatar Dec 02 '25 21:12 speller26