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: Test if the error of the mitigated result is less than the error of the unmitigated
  result for a circuit with known expectation values
docstr_tok: ["Test","if","the","error","of","the","mitigated","result","is","less","than","the","error","of","the","unmitigated","result","for","a","circuit","with","known","expectation","values"]
code: def test_integration(self):
      """Test if the error of the mitigated result is less than the error of the unmitigated
      result for a circuit with known expectation values"""
      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) for s in shapes]
  
      def circuit(w1, w2):
          qml.SimplifiedTwoDesign(w1, w2, wires=range(2))
          qml.adjoint(qml.SimplifiedTwoDesign)(w1, w2, wires=range(2))
          return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
  
      exact_qnode = qml.QNode(circuit, dev_noise_free)
      noisy_qnode = qml.QNode(circuit, dev)
  
      @partial(
          qml.transforms.mitigate_with_zne,
          scale_factors=[1, 2, 3],
          folding=fold_global,
          extrapolate=RichardsonFactory.extrapolate,
      )
      @qml.qnode(dev)
      def mitigated_qnode(w1, w2):
          qml.SimplifiedTwoDesign(w1, w2, wires=range(2))
          qml.adjoint(qml.SimplifiedTwoDesign)(w1, w2, wires=range(2))
          return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
  
      exact_val = exact_qnode(w1, w2)
      noisy_val = noisy_qnode(w1, w2)
      mitigated_val = mitigated_qnode(w1, w2)
  
      for res in [exact_val, noisy_val, mitigated_val]:
          assert isinstance(res, tuple)
          assert len(res) == 2
          assert all(r.shape == () for r in res)
  
      exact_val = qml.math.stack(exact_val)
      noisy_val = qml.math.stack(noisy_val)
      mitigated_val = qml.math.stack(mitigated_val)
  
      mitigated_err = np.abs(exact_val - mitigated_val)
      noisy_err = np.abs(exact_val - noisy_val)
  
      assert np.allclose(exact_val, [1, 1])
      assert all(mitigated_err < noisy_err)
  
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 4 for calling the TestMitiqIntegration obj's underlying member method code with example usage: obj.test_integration() and returns: qml,  qml, qml,  qml