class_docstr: Test that all operations in the ``has_unitary_generator`` attribute
  actually have unitary generators.
docstr: Test directly that generators of the operators in the ``has_unitary_generator``
  attribute are unitary up to a factor of 2.
docstr_tok: ["Test","directly","that","generators","of","the","operators","in","the","``","has_unitary_generator","``","attribute","are","unitary","up","to","a","factor","of","2","."]
code: def test_generator_unitarity(self, entry):
      """Test directly that generators of the operators in the ``has_unitary_generator``
      attribute are unitary up to a factor of 2."""
      op_class = getattr(qml, entry)
      phi = 1.23
      wires = (
          [0, 1, 2]
          if op_class.num_wires is AnyWires
          else list(range(op_class.num_wires))
      )
      if op_class is qml.PauliRot:
          op = op_class(
              phi, pauli_word="XYZ", wires=wires
          )  # PauliRot has num_wires == AnyWires
      elif op_class is qml.PCPhase:
          op = op_class(phi, dim=(2 ** len(wires) - 1), wires=wires)
      else:
          op = op_class(phi, wires=wires)
      gen = qml.generator(op, format="observable")
      # Some generators are unitary up to a factor - in this case norm of first
      # column will be scaled by this factor, so normalize generator first.
      assert qml.is_unitary(
          qml.s_prod(
              1 / np.linalg.norm(qml.matrix(gen), axis=0)[0], gen
          )
      )
  
imports: import itertools
  import pytest
  import numpy
  from scipy.stats import unitary_group
  import pennylane
  from pennylane.ops.qubit.attributes import Attribute, has_unitary_generator
  from pennylane.operation import AnyWires
label_desc: Use image node_id 1 for calling the TestHasUnitaryGenerator obj's underlying member method code with example usage: obj.test_generator_unitarity(entry) without return types