Pennylane to Qiskit

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

This is the code:

dev4 = qml.device(“defaults.qubit”, wires=wires) # define the simulator
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?