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 expected shape is returned when mitigating a circuit with two returns
docstr_tok: ["Tests","if","the","expected","shape","is","returned","when","mitigating","a","circuit","with","two","returns"]
code: def test_multiple_returns(self):
      """Tests if the expected shape is returned when mitigating a circuit with two returns"""
      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]
  
      @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)), qml.expval(qml.Hadamard(1))
  
      @qml.qnode(dev_noise_free)
      def ideal_circuit(w1, w2):
          qml.SimplifiedTwoDesign(w1, w2, wires=range(2))
          return qml.expval(qml.PauliZ(0)), qml.expval(qml.Hadamard(1))
  
      res_mitigated = mitigated_circuit(w1, w2)
      res_ideal = ideal_circuit(w1, w2)
  
      # check shapes
      assert isinstance(res_mitigated, tuple)
      assert len(res_mitigated) == 2
      assert all(res.shape == () for res in res_mitigated)
  
      assert isinstance(res_ideal, tuple)
      assert len(res_ideal) == 2
      assert all(res.shape == () for res in res_ideal)
  
      res_mitigated = qml.math.stack(res_mitigated)
      res_ideal = qml.math.stack(res_ideal)
  
      assert res_mitigated.shape == res_ideal.shape
      assert not np.allclose(res_mitigated, res_ideal)
  
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 1 for calling the TestMitiqIntegration obj's underlying member method code with example usage: obj.test_multiple_returns() and returns: qml,  qml, qml,  qml