Special Unitary Matrix is not same as the one from qml.SpecialUnitary

Hi everyone, when i use .matrix() on qml.SpecialUnitary, the matrix i get back is not the same as the one I get when I manually create the SpecialUnitary. I should be getting the same matrix back. Why is this happening? Here is the code.

coeffs = theta = 0.3 * np.array([0, 1, 2, 0, -1, 1, 0, 0, 0, 1, 1, 1, 0, 0, -1])
dic = {
    "I" : qml.Identity.compute_matrix(),
    "X" : qml.PauliX.compute_matrix(),
    "Y" : qml.PauliY.compute_matrix(),
    "Z" : qml.PauliZ.compute_matrix()
}
mult = None
temp = np.array([[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]])

for i in range(len(columns)):
    c = columns[i]
    one = c[0]
    two = c[1]
    mult = np.kron(dic[one], dic[two]) *(1j * coeffs[i])
    temp =  np.add(temp, mult)
m1 = np.exp(temp)
m2 = qml.SpecialUnitary(coeffs, wires=[0,1]).matrix()

Here, m1 is not same as m2.

Hey @Mushahid_Khan!

I think you’re looking for the matrix exponential expm: scipy.linalg.expm β€” SciPy v1.10.1 Manual. exp will do an element-wise exponentiation. Let me know if this helps!

1 Like