I use pennylane and qiskit to build a same circuit. But I get different unitary matrix. Can you help me with this. By the way, I use bqskit to get the qiskit circuit unitary matrix. The code is as follows:
def circuit_pennylane(w):
qml.U3(*w[0: 3], wires=0)
qml.U3(*w[3: 6], wires=2)
qml.U3(*w[6: 9], wires=3)
qml.CNOT(wires=[4, 5])
qml.CNOT(wires=[6, 7])
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[2, 3])
qml.U3(*w[9: 12], wires=4)
qml.U3(*w[12: 15], wires=7)
qml.U3(*w[15: 18], wires=1)
qml.U3(*w[18: 21], wires=3)
qml.CNOT(wires=[4, 5])
qml.CNOT(wires=[6, 7])
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[2, 3])
qml.U3(*w[21: 24], wires=4)
qml.U3(*w[24: 27], wires=5)
qml.U3(*w[27: 30], wires=7)
qml.U3(*w[30: 33], wires=1)
qml.U3(*w[33: 36], wires=3)
def circuit_qiskit(w):
qr = qiskit.circuit.QuantumRegister(8)
circuit_qiskit = qiskit.circuit.QuantumCircuit(qr)
circuit_qiskit.u3(*w[0: 3], qr[0])
circuit_qiskit.u3(*w[3: 6], qr[2])
circuit_qiskit.u3(*w[6: 9], qr[3])
circuit_qiskit.cx(qr[4], qr[5])
circuit_qiskit.cx(qr[6], qr[7])
circuit_qiskit.cx(qr[0], qr[1])
circuit_qiskit.cx(qr[2], qr[3])
circuit_qiskit.u3(*w[9: 12], qr[4])
circuit_qiskit.u3(*w[12: 15], qr[7])
circuit_qiskit.u3(*w[15: 18], qr[1])
circuit_qiskit.u3(*w[18: 21], qr[3])
circuit_qiskit.cx(qr[4], qr[5])
circuit_qiskit.cx(qr[6], qr[7])
circuit_qiskit.cx(qr[0], qr[1])
circuit_qiskit.cx(qr[2], qr[3])
circuit_qiskit.u3(*w[21: 24], qr[4])
circuit_qiskit.u3(*w[24: 27], qr[5])
circuit_qiskit.u3(*w[27: 30], qr[7])
circuit_qiskit.u3(*w[30: 33], qr[1])
circuit_qiskit.u3(*w[33: 36], qr[3])
return circuit_qiskit
com_params = np.array([0.5017826429101869, 3.6367716666551555, 2.7505603097266587,
5.2689878096886, 1.9469336295216628, -1.3368441720095896,
0.513074271033224, 4.199584296075159, 6.306066549892076,
2.7683481555222893, 0.7127131166893816, -0.06444712800830774,
-28.083197394636084, 4.7158324361873225, 1.5702730577895188,
3.5346400976751595, 3.2665036868214488, 2.128460281389509,
-3.9528591944637474, 5.333712463704893, 2.60882112672375,
4.391537489903239, 5.632487318517943, 3.779765489939559,
3.91163645661754, 1.2912910442439236, 7.512955104697662,
30.343523516097846, 6.172208326683445, 0.1080466303692923,
1.3628332318551757, 6.399627690003927, 0.667632291595952,
2.6854448789723238, 2.2782012039524724, 6.937858784422129])
get_matrix = qml.matrix(circuit_pennylane)
pennylane_matrix = get_matrix(com_params)
circuit = circuit_qiskit(com_params)
qiskit_matrix = qiskit_to_bqskit(circuit).get_unitary().numpy
A = qiskit_matrix
B = pennylane_matrix
epsilon = np.abs(1 - np.abs(np.sum(np.multiply(A,np.conj(B)))) / A.shape[0])
print(epsilon)