Pennylane to Qiskit

Hey, I want to convert my pennylane code to qiskit. Can anyone help me in this regard?

This is the code:

wires=4
dev4 = qml.device(“defaults.qubit”, wires=wires) # define the simulator
@qml.qnode(dev4)
def CONVCircuit(phi, wires, i=0):
“”"
quantum convolution Node
“”"
# parameter
theta = np.pi / 2
qml.RX(phi[0] * np.pi, wires=0)
qml.RX(phi[1] * np.pi, wires=1)
qml.RX(phi[2] * np.pi, wires=2)
qml.RX(phi[3] * np.pi, wires=3)
qml.CRZ(theta, wires=[1, 0])
qml.CNOT(wires=[0, 1])
qml.CRZ(theta, wires=[3, 2])
qml.CNOT(wires=[2, 3])
qml.CRX(theta, wires=[1, 0])
qml.CNOT(wires=[0, 1])
qml.CRX(theta, wires=[3, 2])
qml.CNOT(wires=[2, 3])
qml.CRZ(theta, wires=[2, 0])
qml.CNOT(wires=[0, 2])
qml.CRX(theta, wires=[2, 0])
qml.CNOT(wires=[0, 2])

# Expectation value
measurement = qml.expval(qml.PauliZ(wires=0))
return measurement

Please look into this.

Hi @mass_of_15, welcome to the forum!

You could try converting your code to Open QASM using the to_openqasm function. Then you can load it in Qiskit. You may need to remove the measurement because I’m not sure that it will work with Qiskit.

You can take a look at the thread here for an example on how to convert your circuit to Open QASM.

Does this work for you?

Hi! I was searching a similar functionality to convert qml code to Qiskit. Just want to confirm that conversion Pennylane->QASM->Qiskit is still the only option?

Thanks!

Hi @NotSchrodinger, welcome to the Forum!

That is indeed the only option at the moment. You can tell us more about your problem to see if there’s an alternate solution. For example, if you want to run your code on IBM hardware or simulators you can do it directly from PennyLane.

Also, we have a very small survey for PennyLane v0.33, and it would be awesome if you’d give us some feedback and tell us about your needs. Thank you! :grin: