class_docstr: Tests that correct gradients are obtained for `CommutingEvolution` when frequencies
  are specified.
class_docstr_tok: ["Tests","that","correct","gradients","are","obtained","for","`","CommutingEvolution","`","when","frequencies","are","specified","."]
docstr: Tests the parameter shift rules for `CommutingEvolution` equal the
  finite difference result for a four term shift rule case.
docstr_tok: ["Tests","the","parameter","shift","rules","for","`","CommutingEvolution","`","equal","the","finite","difference","result","for","a","four","term","shift","rule","case","."]
code: def test_four_term_case(self):
      """Tests the parameter shift rules for `CommutingEvolution` equal the
      finite difference result for a four term shift rule case."""
  
      n_wires = 2
      dev = qml.device("default.qubit", wires=n_wires)
  
      coeffs = [1, -1]
      obs = [
          qml.PauliX(0) @ qml.PauliY(1),
          qml.PauliY(0) @ qml.PauliX(1),
      ]
      hamiltonian = qml.Hamiltonian(coeffs, obs)
      frequencies = (2, 4)
  
      @qml.qnode(dev)
      def circuit(time):
          qml.PauliX(0)
          qml.CommutingEvolution(hamiltonian, time, frequencies)
          return qml.expval(qml.PauliZ(0))
  
      x_vals = [
          np.array(x, requires_grad=True)
          for x in np.linspace(-np.pi, np.pi, num=10)
      ]
  
      grads_finite_diff = [
          qml.gradients.finite_diff(circuit)(x) for x in x_vals
      ]
      grads_param_shift = [
          qml.gradients.param_shift(circuit)(x) for x in x_vals
      ]
  
      assert all(
          np.isclose(grads_finite_diff, grads_param_shift, atol=1e-4)
      )
  
file_path: pennylane/tests/templates/test_subroutines/test_commuting_evolution.py
imports: import pytest
  from scipy.linalg import expm
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 2 for calling the TestGradients obj's underlying member method code with example usage: obj.test_four_term_case() and returns: qml