class_docstr: Tests for the QutritUnitary class.
class_docstr_tok: ["Tests","for","the","QutritUnitary","class","."]
docstr: Test that the unitary operator produces the correct output and
  catches incorrect input with autograd.
docstr_tok: ["Test","that","the","unitary","operator","produces","the","correct","output","and","catches","incorrect","input","with","autograd","."]
code: def test_qutrit_unitary_autograd(self, U, num_wires):
      """Test that the unitary operator produces the correct output and
      catches incorrect input with autograd."""
  
      out = qml.QutritUnitary(U, wires=range(num_wires)).matrix()
  
      # verify output type
      assert isinstance(out, np.ndarray)
  
      # verify equivalent to input state
      assert qml.math.allclose(out, U)
  
      # test non-square matrix
      with pytest.raises(ValueError, match="must be of shape"):
          qml.QutritUnitary(U[:, 1:], wires=range(num_wires)).matrix()
  
      # test non-unitary matrix
      U3 = U.copy()
      U3[0, 0] += 0.5
      with pytest.warns(UserWarning, match="may not be unitary"):
          qml.QutritUnitary(U3, wires=range(num_wires)).matrix()
  
      # test an error is thrown when constructed with incorrect number of wires
      with pytest.raises(ValueError, match="must be of shape"):
          qml.QutritUnitary(U, wires=range(num_wires + 1)).matrix()
  
      # verify adjoint behaves correctly
      op = qml.QutritUnitary(U, wires=range(num_wires)).adjoint()
      mat = op.matrix()
      expected = (
          np.conj(np.transpose(U))
          if len(np.shape(U)) == 2
          else np.conj(np.swapaxes(U, -2, -1))
      )
      assert qml.math.allclose(mat, expected)
  
imports: import pytest
  import numpy
  from scipy.stats import unitary_group
  from gate_data import TSWAP
  import pennylane
  from pennylane.wires import Wires
  from pennylane.operation import DecompositionUndefinedError
label_desc: Use image node_id 5 for calling the TestQutritUnitary obj's underlying member method code with example usage: obj.test_qutrit_unitary_autograd(U, num_wires) without return types