Tensored Paulis formed without explicit qubit yield IR error
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
This shouldn't work (you'd need to pass a target to .to_ir, but the error message should be clearer.
Might be worth fixing PauliString to automatically create targets if none are specified.