qml.snapshots¶
-
snapshots
(qnode)[source]¶ Create a function that retrieves snapshot results from a QNode.
- Parameters
qnode (QNode) – the input QNode to be simulated
- Returns
A function that has the same argument signature as
qnode
and returns a dictionary. When called, the function will execute the QNode on the registered device and retrieve the saved snapshots obtained via theSnapshot
operation. Additionally, the snapshot dictionary always contains the execution results of the QNode, so the use of the tag “execution_results” should be avoided to prevent conflicting key names.
Example
dev = qml.device("default.qubit", wires=2) @qml.qnode(dev, interface=None) def circuit(): qml.Snapshot() qml.Hadamard(wires=0) qml.Snapshot("very_important_state") qml.CNOT(wires=[0, 1]) qml.Snapshot() return qml.expval(qml.PauliX(0))
>>> qml.snapshots(circuit)() {0: array([1., 0., 0., 0.]), 'very_important_state': array([0.70710678, 0. , 0.70710678, 0. ]), 2: array([0.70710678, 0. , 0. , 0.70710678]), 'execution_results': 0.0}
code/api/pennylane.snapshots
Download Python script
Download Notebook
View on GitHub