code: def get_metric_from_single_input_qnode(
      params, finite_diff_step, tensor_dirs
  ):
      """Compute the expected raw metric tensor from analytical state overlap expression."""
      dir_vec1 = tensor_dirs[0]
      dir_vec2 = tensor_dirs[1]
      dir1 = dir_vec1.reshape(params.shape)
      dir2 = dir_vec2.reshape(params.shape)
      perturb1 = dir1 * finite_diff_step
      perturb2 = dir2 * finite_diff_step
  
      def get_state_overlap(params1, params2):
          # analytically computed state overlap between two parameterized ansatzes
          # with input params1 and params2
          return (
              np.cos(params1[0][0] / 2) * np.cos(params2[0][0] / 2)
              + np.sin(params1[0][0] / 2)
              * np.sin(params2[0][0] / 2)
              * (
                  np.sin(params1[0][1] / 2) * np.sin(params2[0][1] / 2)
                  + np.cos(params1[0][1] / 2)
                  * np.cos(params2[0][1] / 2)
              )
          ) ** 2
  
      tensor_finite_diff = (
          get_state_overlap(params, params + perturb1 + perturb2)
          - get_state_overlap(params, params + perturb1)
          - get_state_overlap(params, params - perturb1 + perturb2)
          + get_state_overlap(params, params - perturb1)
      )
      metric_tensor_expected = (
          -(
              np.tensordot(dir_vec1, dir_vec2, axes=0)
              + np.tensordot(dir_vec2, dir_vec1, axes=0)
          )
          * tensor_finite_diff
          / (8 * finite_diff_step * finite_diff_step)
      )
      return metric_tensor_expected
  
file_path: pennylane/tests/optimize/test_qnspsa.py
imports: from copy import deepcopy
  import pytest
  from scipy.linalg import sqrtm
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: get_metric_from_single_input_qnode(params, finite_diff_step, tensor_dirs) and returns: metric_tensor_expected, unknown