class_docstr: Tests if the mitigate_with_zne transform is compatible with using mitiq as a backend
class_docstr_tok: ["Tests","if","the","mitigate_with_zne","transform","is","compatible","with","using","mitiq","as","a","backend"]
docstr: Tests if the gradient is calculated successfully.
docstr_tok: ["Tests","if","the","gradient","is","calculated","successfully","."]
code: def test_grad(self):
      """Tests if the gradient is calculated successfully."""
      from mitiq.zne.inference import RichardsonFactory
  
      noise_strength = 0.05
  
      dev_noise_free = qml.device("default.mixed", wires=2)
      dev = qml.transforms.insert(qml.AmplitudeDamping, noise_strength)(
          dev_noise_free
      )
  
      n_wires = 2
      n_layers = 2
  
      shapes = qml.SimplifiedTwoDesign.shape(n_layers, n_wires)
      np.random.seed(0)
      w1, w2 = [np.random.random(s, requires_grad=True) for s in shapes]
  
      @partial(
          qml.transforms.mitigate_with_zne,
          scale_factors=[1, 2, 3],
          folding=fold_global,
          extrapolate=RichardsonFactory.extrapolate,
      )
      @qml.qnode(dev)
      def mitigated_circuit(w1, w2):
          qml.SimplifiedTwoDesign(w1, w2, wires=range(2))
          return qml.expval(qml.PauliZ(0))
  
      g = qml.grad(mitigated_circuit)(w1, w2)
      for g_ in g:
          assert not np.allclose(g_, 0)
  
imports: from functools import partial
  import pytest
  from packaging import version
  import pennylane
  from pennylane import numpy
  from pennylane.tape import QuantumScript
  from pennylane.transforms import mitigate_with_zne, richardson_extrapolate, fold_global
label_desc: Use image node_id 5 for calling the TestMitiqIntegration obj's underlying member method code with example usage: obj.test_grad() and returns: qml