code: def expected_purity_grad_ising_xx(param):
      """The analytic gradient purity for the IsingXX"""
  
      eig_1 = (
          1
          + np.sqrt(
              1 - 4 * np.cos(param / 2) ** 2 * np.sin(param / 2) ** 2
          )
      ) / 2
      eig_2 = (
          1
          - np.sqrt(
              1 - 4 * np.cos(param / 2) ** 2 * np.sin(param / 2) ** 2
          )
      ) / 2
      grad_expected_purity = (
          2
          * eig_1
          * (
              np.sin(param / 2) ** 3 * np.cos(param / 2)
              - np.sin(param / 2) * np.cos(param / 2) ** 3
          )
          / np.sqrt(
              1 - 4 * np.sin(param / 2) ** 2 * np.cos(param / 2) ** 2
          )
      ) + (
          2
          * eig_2
          * (
              np.sin(param / 2)
              * np.cos(param / 2)
              * (np.cos(param / 2) ** 2 - np.sin(param / 2) ** 2)
          )
          / np.sqrt(
              1 - 4 * np.sin(param / 2) ** 2 * np.cos(param / 2) ** 2
          )
      )
      return grad_expected_purity
  
file_path: pennylane/tests/measurements/legacy/test_purity_measurement_legacy.py
imports: import pytest
  import numpy
  import pennylane
  from pennylane.measurements import Shots
label_desc: Use image node_id 2 for calling a global function with example usage: expected_purity_grad_ising_xx(param) and returns: grad_expected_purity