class_docstr: Testing differentiable ZNE
class_docstr_tok: ["Testing","differentiable","ZNE"]
docstr: Ensuring that the folded circuits always yields the same results.
docstr_tok: ["Ensuring","that","the","folded","circuits","always","yields","the","same","results","."]
code: def test_global_fold_constant_result(self):
      """Ensuring that the folded circuits always yields the same results."""
  
      dev = qml.device("default.qubit", wires=5)
  
      # Select template to use within circuit and generate parameters
      n_layers = 2
      n_wires = 3
      template = qml.SimplifiedTwoDesign
      weights_shape = template.shape(n_layers, n_wires)
      w1, w2 = [np.arange(np.prod(s)).reshape(s) for s in weights_shape]
  
      dev = qml.device("default.qubit", wires=range(n_wires))
  
      # This circuit itself produces the identity by construction
      @qml.qnode(dev)
      def circuit(w1, w2):
          template(w1, w2, wires=range(n_wires))
          qml.adjoint(template(w1, w2, wires=range(n_wires)))
          return qml.expval(qml.PauliZ(0))
  
      res = [
          fold_global(circuit, scale_factor=scale_factor)(w1, w2)
          for scale_factor in range(1, 5)
      ]
      assert np.allclose(res, 1)
  
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 TestDifferentiableZNE obj's underlying member method code with example usage: obj.test_global_fold_constant_result() and returns: qml