code: def autodiff_metric_tensor(ansatz, num_wires):
      """Compute the metric tensor by full state vector
      differentiation via autograd."""
      dev = qml.device("default.qubit", wires=num_wires)
  
      @qml.qnode(dev)
      def qnode(*params):
          ansatz(*params, wires=dev.wires)
          return qml.state()
  
      def mt(*params):
          state = qnode(*params)
  
          def rqnode(*params):
              return np.real(qnode(*params))
  
          def iqnode(*params):
              return np.imag(qnode(*params))
  
          rjac = qml.jacobian(rqnode)(*params)
          ijac = qml.jacobian(iqnode)(*params)
  
          if isinstance(rjac, tuple):
              out = []
              for rc, ic in zip(rjac, ijac):
                  c = rc + 1j * ic
                  psidpsi = np.tensordot(
                      np.conj(state), c, axes=([0], [0])
                  )
                  out.append(
                      np.real(
                          np.tensordot(np.conj(c), c, axes=([0], [0]))
                          - np.tensordot(
                              np.conj(psidpsi), psidpsi, axes=0
                          )
                      )
                  )
              return tuple(out)
  
          jac = rjac + 1j * ijac
          psidpsi = np.tensordot(np.conj(state), jac, axes=([0], [0]))
          return np.real(
              np.tensordot(np.conj(jac), jac, axes=([0], [0]))
              - np.tensordot(np.conj(psidpsi), psidpsi, axes=0)
          )
  
      return mt
  
imports: import pytest
  from pennylane import numpy
  import pennylane
label_desc: Use image node_id 12 for calling a global function with example usage: autodiff_metric_tensor(ansatz, num_wires) and returns: mt, qml, np, np, np, tuple