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

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

Đang mở
#1,316 1 bình luận 0 reaction 1 người được giao Được @speller26 nhận Xem trên GitHub
Ngôn ngữ chính
Python
Star
373
Fork
195
Merge trung bình
4 ngày 15 giờ
Pull request đã merge (30 ngày)
8

Mô tả

### 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.