Executing that with real noise simulator from IBM Quantum:
import pennylane as qml
import matplotlib.pyplot as plt
from pennylane import numpy as np
from qiskit_ibm_provider import IBMProvider
from qiskit_aer import noise, AerSimulator
provider = IBMProvider()
NUM_QUBITS = 2
wires = list(range(NUM_QUBITS))
try:
simulator = AerSimulator.from_backend(provider.get_backend('ibm_osaka'))
dev_ibm = qml.device("qiskit.aer", wire=NUM_QUBITS, simulator=simulator)
except Exception as e:
print(e)
def equal_superposition(wires):
for wire in wires:
qml.Hadamard(wires=wire)
@qml.qnode(dev_ibm)
def circuit():
qml.Snapshot("Initial state")
equal_superposition(wires)
qml.Snapshot("After applying the Hadamard gates")
return qml.probs(wires=wires) # Probability of finding a computational basis state on the wires
qml.snapshots(circuit)()
for k, result in results.items():
print(f"{k}: {result}")
I’m getting that error message below:
---------------------------------------------------------------------------
DeviceError Traceback (most recent call last)
Cell In[16], line 13
10 qml.Snapshot("After applying the Hadamard gates")
11 return qml.probs(wires=wires) # Probability of finding a computational basis state on the wires
---> 13 qml.snapshots(circuit)()
15 for k, result in results.items():
16 print(f"{k}: {result}")
File ~/.local/lib/python3.11/site-packages/pennylane/debugging.py:94, in snapshots.<locals>.get_snapshots(*args, **kwargs)
91 if old_interface == "auto":
92 qnode.interface = qml.math.get_interface(*args, *list(kwargs.values()))
---> 94 with _Debugger(qnode.device) as dbg:
95 results = qnode(*args, **kwargs)
96 # Reset interface
File ~/.local/lib/python3.11/site-packages/pennylane/debugging.py:34, in _Debugger.__init__(self, dev)
31 def __init__(self, dev):
32 # old device API: check if Snapshot is supported
33 if isinstance(dev, qml.Device) and "Snapshot" not in dev.operations:
---> 34 raise DeviceError("Device does not support snapshots.")
36 # new device API: check if it's the simulator device
37 if isinstance(dev, qml.devices.Device) and not isinstance(dev, qml.devices.DefaultQubit):
DeviceError: Device does not support snapshots.
And, finally, make sure to include the versions of your packages. Specifically, show us the output of qml.about()
.
Name: PennyLane
Version: 0.33.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /home/jose/.local/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning, PennyLane-qiskit
Platform info: Linux-6.5.13-7-MANJARO-x86_64-with-glibc2.38
Python version: 3.11.6
Numpy version: 1.23.5
Scipy version: 1.11.4
Installed devices:
- default.gaussian (PennyLane-0.33.1)
- default.mixed (PennyLane-0.33.1)
- default.qubit (PennyLane-0.33.1)
- default.qubit.autograd (PennyLane-0.33.1)
- default.qubit.jax (PennyLane-0.33.1)
- default.qubit.legacy (PennyLane-0.33.1)
- default.qubit.tf (PennyLane-0.33.1)
- default.qubit.torch (PennyLane-0.33.1)
- default.qutrit (PennyLane-0.33.1)
- null.qubit (PennyLane-0.33.1)
- lightning.qubit (PennyLane-Lightning-0.33.1)
- qiskit.aer (PennyLane-qiskit-0.33.1)
- qiskit.basicaer (PennyLane-qiskit-0.33.1)
- qiskit.ibmq (PennyLane-qiskit-0.33.1)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.33.1)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.33.1)
- qiskit.remote (PennyLane-qiskit-0.33.1)
QISKIT VERSION:
{'qiskit': '0.45.1', 'qiskit-aer': '0.13.1', 'qiskit-ignis': None, 'qiskit-ibmq-provider': None, 'qiskit-nature': '0.7.1', 'qiskit-finance': '0.4.0', 'qiskit-optimization': '0.6.0', 'qiskit-machine-learning': '0.7.1'}
What I do to that work with AerSimulator?
Thanks,