Hello! I am wondering how to transpile (or compile) a circuit with a specific hardware setting (or specific coupling maps and basic gate sets). Suppose I have a circuit like this:
def circuit():
qml.CNOT(wires=[0, 1])
qml.PauliY(wires=0)
qml.CNOT(wires=[2, 3])
qml.Hadamard(wires=3)
qml.CNOT(wires=[1, 2])
qml.PauliZ(wires=0)
qml.PauliX(wires=1)
qml.Hadamard(wires=2)
qml.CNOT(wires=[3,1])
qml.PauliZ(wires=2)
qml.CNOT(wires=[0, 3])
return qml.probs(wires=[0, 1, 2, 3])
dev = qml.device('default.qubit', wires=4)
qnode = qml.QNode(circuit, dev)
print(qml.draw(qnode)())
which is:
0: βββββYββZβββββββββββ€ βProbs
1: ββ°XβββββXββXββββββββ€ βProbs
2: βββββ°XββHβββββZβββββ€ βProbs
3: ββ°XββHβββββ°ββββββ°Xββ€ β°Probs
Now, suppose I want to have it executed on the ibmq_lima (or fake ibmq_lima) device, what can I do to acquire get the corresponding transpile circuit for my designed circuit circuit()
? I do not want to execute on the real hardware but only would like to get the transpiled to-be-executed circuit and output some data (like physical depth, gate counts, etc.) from it. Does Pennylane have another different compiling strategy for this compared with qiskit, and how can I implement it?
There is another approach in that I can specify the coupling map and the basis set of the specific hardware and implement the qml.compile
or qml.transforms.transpile
. However, I use the code below to transpile my circuit
with specific basis_set={["CNOT", "X", "SX", "RZ"]}
(which is exactly
the gate set of ibmq_lima):
compiled_circuit = qml.compile(basis_set=["CNOT", "X", "SX", "RZ"])(circuit)
compiled_qnode = qml.QNode(compiled_circuit, dev)
print(qml.draw(compiled_qnode)())
and I get:
0: βββββRZ(1.57)ββRY(3.14)ββββββββββββββββββββββββββββββββββββββRZ(4.71)ββ€ βProbs
1: ββ°XββββββββββββRZ(1.57)ββRX(3.14)ββRZ(1.57)ββXβββββββββββββββββββββββββ€ βProbs
2: βββββ°XβββββββββRZ(1.57)ββRX(1.57)ββRZ(4.71)ββββββββββββββββββββββββββββ€ βProbs
3: ββ°XββRZ(1.57)ββRX(1.57)ββββββββββββββββββββββ°βββRZ(1.57)ββ°Xββββββββββββ€ β°Probs
We can see that there is still RX
gate inside. This will become even worse when I implement custom unitary gates in the circuit. I cannot get the circuit with my indicated basis_set
.
Thanks a lot and looking forward to your answers!
This is my environment:
Name: PennyLane
Version: 0.30.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for differentiable programming of quantum computers. Train a quantum computer the same way as a neural network.
*Author: *
*Author-email: *
License: Apache License 2.0
Location: e:\anaconda3\lib\site-packages
Requires: autograd, requests, autoray, semantic-version, scipy, rustworkx, appdirs, numpy, networkx, toml, pennylane-lightning, cachetools
Required-by: PennyLane-qiskit, PennyLane-Lightning
Platform info: Windows-10-10.0.19042-SP0
Python version: 3.9.12
Numpy version: 1.23.5
Scipy version: 1.9.3
Installed devices:
- qiskit.aer (PennyLane-qiskit-0.30.1)
- qiskit.basicaer (PennyLane-qiskit-0.30.1)
- qiskit.ibmq (PennyLane-qiskit-0.30.1)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.30.1)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.30.1)
- default.gaussian (PennyLane-0.30.0)
- default.mixed (PennyLane-0.30.0)
- default.qubit (PennyLane-0.30.0)
- default.qubit.autograd (PennyLane-0.30.0)
- default.qubit.jax (PennyLane-0.30.0)
- default.qubit.tf (PennyLane-0.30.0)
- default.qubit.torch (PennyLane-0.30.0)
- default.qutrit (PennyLane-0.30.0)
- null.qubit (PennyLane-0.30.0)
- lightning.qubit (PennyLane-Lightning-0.30.0)