PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.3k stars 592 forks source link

Support native measurement-based snapshots in Default Clifford #5647

Closed trbromley closed 3 months ago

trbromley commented 5 months ago

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:

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

Additional requirements:

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.

king-p3nguin commented 4 months ago

Hi, I would like to work on this issue for unitaryhack.

trbromley commented 4 months ago

Thanks @king-p3nguin for opening the PR! :star_struck:

Shall we start reviewing the PR now or do you have any more changes planned? In any case, we're happy to help if you have questions!

king-p3nguin commented 4 months ago

@trbromley Thank you for the reply! I think I have written the necessary code, so please let me know whether you are happy with it.

trbromley commented 4 months ago

Thanks @king-p3nguin! I've tagged someone from our team to review :rocket:

trbromley commented 4 months ago

It also looks like @EuGig has opened a PR :star_struck:

I just to clarify how things work in case of multiple contribution attempts for this bounty:

@king-p3nguin opened their PR first and we're taking a look at that now. @EuGig how would you like to proceed?

Thanks!

EuGig commented 4 months ago

Hi @trbromley! I've just seen @king-p3nguin's PR and it's actually quite good. So, I guess it wouldn't be fair to work both on it and to share the amount. Maybe I would still work on mine - though, I know that from your point of view this means another (possibly useless) code review.

trbromley commented 4 months ago

Thanks @EuGig! Yes you're welcome to have a go, but we could also recommend other projects to take on if you're interested? We're still waiting for an open PR on this bounty: https://github.com/PennyLaneAI/pennylane/issues/5646. Though there has been some interest already in the comments.

trbromley commented 3 months ago

Thanks so much @king-p3nguin! Great job on this bounty :medal_sports:

Would you optionally like to be tagged in any of our announcements around unitaryHACK or the upcoming PennyLane 0.37 release at the start of July? This would be on LinkedIn and Twitter, so if you would like, please share your username(s).

king-p3nguin commented 3 months ago

@trbromley Thank you very much! Yes, I would like to be tagged. Since I only have a LinkedIn account, I will give you my LinkedIn username. LinkedIn username: kazukitsuoka