code: def get_grad_finite_diff(params, finite_diff_step, grad_dirs):
      """Helper function computing the qnode finite difference for computing the gradient analytically.
      One can expand the following expression to get the qnode_finite_diff expression:
      qnode(params + finite_diff_step * grad_dirs) - qnode(params - finite_diff_step * grad_dirs)
      """
      qnode_finite_diff = (
          -np.sin(params[0]) * np.sin(finite_diff_step * grad_dirs[0])
          + np.sin(params[1]) * np.sin(finite_diff_step * grad_dirs[1])
          + (
              np.cos(
                  params[0]
                  + params[1]
                  + finite_diff_step * grad_dirs[0]
                  + finite_diff_step * grad_dirs[1]
              )
              + np.cos(
                  params[0]
                  + finite_diff_step * grad_dirs[0]
                  - params[1]
                  - finite_diff_step * grad_dirs[1]
              )
              - np.cos(
                  params[0]
                  + params[1]
                  - finite_diff_step * grad_dirs[0]
                  - finite_diff_step * grad_dirs[1]
              )
              - np.cos(
                  params[0]
                  - finite_diff_step * grad_dirs[0]
                  - params[1]
                  + finite_diff_step * grad_dirs[1]
              )
          )
          / 4
      )
      return qnode_finite_diff
  
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 3 for calling a global function with example usage: get_grad_finite_diff(params, finite_diff_step, grad_dirs) and returns: qnode_finite_diff