class_docstr: Test that the expval transform is applied correctly
class_docstr_tok: ["Test","that","the","expval","transform","is","applied","correctly"]
docstr: Test the gradient of the expval transform
docstr_tok: ["Test","the","gradient","of","the","expval","transform"]
code: def test_basic_entangler_backward(self):
      """Test the gradient of the expval transform"""
  
      obs = [
          qml.PauliX(1),
          qml.PauliX(0) @ qml.PauliX(2),
          qml.PauliX(0) @ qml.Identity(1) @ qml.PauliX(2),
          qml.PauliY(2),
          qml.PauliY(1) @ qml.PauliZ(2),
          qml.PauliX(0) @ qml.PauliY(1),
          qml.PauliX(0) @ qml.PauliY(1) @ qml.Identity(2),
      ]
  
      shadow_circuit = basic_entangler_circuit(
          3, shots=20000, interface="autograd"
      )
      shadow_circuit = qml.shadows.shadow_expval(shadow_circuit, obs)
      exact_circuit = basic_entangler_circuit_exact_expval(
          3, "autograd"
      )
  
      x = np.random.uniform(
          0.8,
          2,
          size=qml.BasicEntanglerLayers.shape(n_layers=1, n_wires=3),
      )
  
      def shadow_cost(x):
          res = shadow_circuit(x)
          return qml.math.stack(res)
  
      def exact_cost(x, obs):
          res = exact_circuit(x, obs)
          return qml.math.stack(res)
  
      actual = qml.jacobian(shadow_cost)(x)
      expected = qml.jacobian(exact_cost)(x, obs)
  
      assert qml.math.allclose(actual, expected, atol=1e-1)
  
imports: from functools import partial
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.shadows.transforms import _replace_obs
label_desc: Use image node_id 2 for calling the TestExpvalTransform obj's underlying member method code with example usage: obj.test_basic_entangler_backward() and returns: qml, qml