class_docstr: Test for operator and tape expansion
docstr: Test that an operator is automatically expanded as needed
docstr_tok: ["Test","that","an","operator","is","automatically","expanded","as","needed"]
code: def test_auto_expansion(self):
      """Test that an operator is automatically expanded as needed"""
  
      @qml.op_transform
      def get_matrix(op):
          return op.matrix()
  
      weights = np.ones([2, 3, 3])
      op = qml.StronglyEntanglingLayers(weights, wires=[0, 2, "a"])
  
      # strongly entangling layers does not define a matrix representation
  
      with pytest.raises(qml.operation.MatrixUndefinedError):
          op.matrix()
  
      # attempting to call our operator transform will fail
  
      with pytest.raises(qml.operation.MatrixUndefinedError):
          get_matrix(op)
  
      # if we define how the transform acts on a tape,
      # then pennylane will automatically expand the object
      # and apply the tape transform
  
      @get_matrix.tape_transform
      def _(tape):
          n_wires = len(tape.wires)
          unitary_matrix = np.eye(2**n_wires)
  
          for op in tape.operations:
              mat = qml.math.expand_matrix(
                  get_matrix(op), op.wires, tape.wires
              )
              unitary_matrix = mat @ unitary_matrix
  
          return unitary_matrix
  
      res = get_matrix(op)
      assert isinstance(res, np.ndarray)
      assert res.shape == (2**3, 2**3)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.transforms.op_transforms import OperationTransformError
label_desc: Use image node_id 1 for calling the TestExpansion obj's underlying member method code with example usage: obj.test_auto_expansion() and returns: op, unitary_matrix