pennylane icon indicating copy to clipboard operation
pennylane copied to clipboard

Support native measurement-based snapshots in Default Clifford

Open trbromley opened this issue 9 months ago • 0 comments

Important Note

⚠️ This issue is not open for contributions. ⚠️

Feature details

The default.clifford device allows PennyLane users to quickly simulate Clifford circuits in PennyLane using the Stim library as a backend. The device was recently added in v0.35 and is not yet at feature parity with devices like default.qubit.

PennyLane provides support for circuit snapshots, allowing users to inspect circuits at different stages of execution on some simulator devices. Snapshots can can be placed in circuits using qml.Snapshot(), which defaults to providing the snapshot of the statevector at that point in the circuit. If a measurement argument is provided to qml.Snapshot(), then Pennylane measurements like qml.expval() can be inspected.

The default.clifford device only supports statevector-based snapshots. The objective of this feature request is to extend support to measurement-based snapshots.

Implementation

It should be possible to execute the following code:

import pennylane as qml

dev = qml.device("default.clifford")

@qml.qnode(dev)
def circuit():
    qml.Hadamard(0)
    qml.Snapshot(measurement=qml.expval(qml.X(0)))
    qml.S(wires=0)
    return qml.expval(qml.X(0))

qml.snapshots(circuit)()

A successful PR must include:

  • The requested feature
  • Comprehensive tests
  • Relevant updates to the documentation
  • An entry in the release notes
  • Passing all CI tests

Check out our development guide for more information, and don't hesitate to reach out to us if you need assistance.

Additional requirements:

  • Measurements done during qml.Snapshot shouldn't alter the state of the main execution workflow.
  • Efficiency is important, the addition of snapshots should not come with much overhead.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

Support for measurement-based snapshots was provided in default.mixed in this recent PR.

trbromley avatar May 03 '24 19:05 trbromley