Hi,
I want to execute a simple feed-forward circuit on IBM HW using PennyLane.
Attached code works for dev = qml.device('default.qubit', wires=range(4))
but it crashes when I want to run it against ‘ibm_cairo’ . Compiler seems to drop the feed-forward classical logic at the expense of adding ancilla and a CNOT.
I’d like to use the feed-forward logic available on IBM devices.
Can you help me to fix my code?
This is the circuit I want:
0: ──H─╭●─╭●──┤↗├─────||─┤ ╭Probs
1: ────╰X─│────║──────||─┤ ├Probs
2: ───────╰X───║──────||─┤ ├Probs
3: ────────────║───X──||─┤ ╰Probs
╚═══╝ ||
This is the circuit I get:
0: ──H─╭●─╭●─╭●─────||─┤ ╭Probs
1: ────╰X─│──│──────||─┤ ├Probs
2: ───────╰X─│──────||─┤ ├Probs
3: ──────────│──╭X──||─┤ ╰Probs
4: ──────────╰X─╰●──||─┤
This is the error I see:
WireError: Did not find some of the wires <Wires = [0, 4]> on device with wires <Wires = [0, 1, 2, 3]>.
# Reproducer
import pennylane as qml
def feedForwardGHZ(n=4):
qml.Hadamard(wires=0)
for i in range(1, n-1):
qml.CNOT(wires=[0,i])
m0 = qml.measure(0)
qml.cond(m0, qml.PauliX)(n-1)
qml.Barrier()
return qml.probs(wires=range(n))
if 1:
from qiskit_ibm_provider import IBMProvider
provider = IBMProvider()
backend = provider.get_backend('ibm_cairo')
dev = qml.device('qiskit.ibmq', wires=range(4), backend=backend, shots=2000)
else:
dev = qml.device('default.qubit', wires=range(4))
qnode = qml.QNode(feedForwardGHZ, dev)
print(qml.draw(qnode)())
# run job
probTens = qnode()
print("Probability of each computational basis state:")
for state, prob in enumerate(probTens):
print("State %2d=%s prob=%.3f"%(state,format(state, '04b'),prob))
The output of qml.about()
.
Name: PennyLane
Version: 0.34.0
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: /usr/local/lib/python3.10/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Cirq, PennyLane-Lightning, PennyLane-Lightning-GPU, PennyLane-qiskit, PennyLane-SF
Platform info: Linux-6.6.9-200.fc39.x86_64-x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 1.23.5
Scipy version: 1.11.4
Installed devices:
- default.gaussian (PennyLane-0.34.0)
- default.mixed (PennyLane-0.34.0)
- default.qubit (PennyLane-0.34.0)
- default.qubit.autograd (PennyLane-0.34.0)
- default.qubit.jax (PennyLane-0.34.0)
- default.qubit.legacy (PennyLane-0.34.0)
- default.qubit.tf (PennyLane-0.34.0)
- default.qubit.torch (PennyLane-0.34.0)
- default.qutrit (PennyLane-0.34.0)
- null.qubit (PennyLane-0.34.0)
- cirq.mixedsimulator (PennyLane-Cirq-0.34.0)
- cirq.pasqal (PennyLane-Cirq-0.34.0)
- cirq.qsim (PennyLane-Cirq-0.34.0)
- cirq.qsimh (PennyLane-Cirq-0.34.0)
- cirq.simulator (PennyLane-Cirq-0.34.0)
- lightning.qubit (PennyLane-Lightning-0.34.0)
- lightning.gpu (PennyLane-Lightning-GPU-0.34.0)
- strawberryfields.fock (PennyLane-SF-0.29.0)
- strawberryfields.gaussian (PennyLane-SF-0.29.0)
- strawberryfields.gbs (PennyLane-SF-0.29.0)
- strawberryfields.remote (PennyLane-SF-0.29.0)
- strawberryfields.tf (PennyLane-SF-0.29.0)
- qiskit.aer (PennyLane-qiskit-0.34.0)
- qiskit.basicaer (PennyLane-qiskit-0.34.0)
- qiskit.ibmq (PennyLane-qiskit-0.34.0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.34.0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.34.0)
- qiskit.remote (PennyLane-qiskit-0.34.0)
!pip3 list|grep qiskit
PennyLane-qiskit 0.34.0
qiskit 0.45.1
qiskit-aer 0.13.2
qiskit-ibm-provider 0.8.0
qiskit-ibm-runtime 0.17.0
qiskit-ibmq-provider 0.20.2
qiskit-terra 0.45.1