amazon-braket / amazon-braket/amazon-braket-sdk-python

ProgramSet MeasuredEntry.expectation() returns None when no observable is attached (unimplemented)

Abierto
#1,316 1 comentario 0 reacciones 1 asignado Reclamado por @speller26 Ver en GitHub
Lenguaje dominante
Python
Estrellas
373
Forks
195
Merge medio
4 d 15 h
PR fusionados (30 d)
8

Descripción

### Summary
`MeasuredEntry.expectation()` on a `ProgramSetQuantumTaskResult` returns `None` (and warns `"No observable was measured"`) whenever the entry has no attached observable, even though the entry contains the `measurements` needed to compute the expectation. The code path is explicitly unimplemented.

### Location
`src/braket/tasks/program_set_quantum_task_result.py`, `MeasuredEntry` (verified present on `main` as of 2026-07):
```python
self._expectation = (
expectation_from_measurements(counts, measured_qubits, self.observable, self.observable.targets)
if self.observable
else None
)

def expectation(self) -> float | None:
# TODO: Use program set payload to calculate expectation
if self._expectation is None:
warnings.warn("No observable was measured", stacklevel=1)
return self._expectation
```

### Impact
Downstream consumers that request an expectation from a program-set result receive `None`/no usable value and can silently produce wrong results, despite the measurements being present and correct. We hit this via the PennyLane–Braket plugin, where `qml.expval` returns values off by up to ~1.5 for a program-set result on a QPU (filing a companion issue on that repo, will cross-link). Because the failure is silent (only a `UserWarning`) and the measurements look fine, the corruption is easy to miss, in our case it manufactured a spurious ~0.2 R² effect that looked like a hardware-fidelity difference.

### Suggested fix
Implement the `# TODO`: when `self.observable` is absent but the requested observable is a computational-basis/diagonal observable (or is recoverable from the program-set payload), compute the expectation from `measurements` instead of returning `None`.

### Environment
Reproduced on `amazon-braket-sdk==1.113.1`; the unimplemented path is still present on `main` (1.121.0). Device: Rigetti Cepheus-1-108Q. The measurement bitstrings on the entry are correct, only the computed expectation is missing.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.