class_docstr: Test the purity meausrement with qnodes and devices.
class_docstr_tok: ["Test","the","purity","meausrement","with","qnodes","and","devices","."]
docstr: Tests gradient of purity for a qnode on a noisy device with bit flips
docstr_tok: ["Tests","gradient","of","purity","for","a","qnode","on","a","noisy","device","with","bit","flips"]
code: def test_bit_flip_qnode_purity_grad(
      self, device, wires, param, is_partial, diff_method
  ):
      """Tests gradient of purity for a qnode on a noisy device with bit flips"""
  
      dev = qml.device(device, wires=2)
  
      @qml.qnode(dev, diff_method=diff_method)
      def circuit(p):
          qml.Hadamard(wires=0)
          qml.CNOT(wires=[0, 1])
          qml.BitFlip(p, wires=0)
          qml.BitFlip(p, wires=1)
          return qml.purity(wires=wires)
  
      purity_grad = qml.grad(circuit)(param)
      expected_purity_grad = (
          0 if is_partial else 32 * (param - 0.5) ** 3
      )
      assert qml.math.allclose(
          purity_grad, expected_purity_grad, rtol=1e-04, atol=1e-05
      )
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane.measurements import PurityMP, Shots
label_desc: Use image node_id 4 for calling the TestPurityIntegration obj's underlying member method code with example usage: obj.test_bit_flip_qnode_purity_grad(device, wires, param, is_partial, diff_method) and returns: qml