class_docstr: Tests for the SPSA gradient transform
class_docstr_tok: ["Tests","for","the","SPSA","gradient","transform"]
docstr: Tests correct output shape and evaluation for a tape
  with multiple expval outputs
docstr_tok: ["Tests","correct","output","shape","and","evaluation","for","a","tape","with","multiple","expval","outputs"]
code: def test_multiple_expectation_values(
      self, approx_order, strategy, validate, tol
  ):
      """Tests correct output shape and evaluation for a tape
      with multiple expval outputs"""
      dev = qml.device("default.qubit", wires=2)
      x = 0.543
      y = -0.654
  
      with qml.queuing.AnnotatedQueue() as q:
          qml.RX(x, wires=[0])
          qml.RY(y, wires=[1])
          qml.CNOT(wires=[0, 1])
          qml.expval(qml.PauliZ(0))
          qml.expval(qml.PauliX(1))
  
      tape = qml.tape.QuantumScript.from_queue(q)
      tapes, fn = spsa_grad(
          tape,
          approx_order=approx_order,
          strategy=strategy,
          num_directions=2,
          sampler=coordinate_sampler,
          validate_params=validate,
      )
      res = fn(dev.execute(tapes))
  
      assert isinstance(res, tuple)
      assert len(res) == 2
  
      # The coordinate_sampler produces the right evaluation points, but the tape execution
      # results are averaged instead of added, so that we need to account for the prefactor
      # 1 / num_params here.
      res = tuple(
          tuple(qml.math.convert_like(_r * 2, _r) for _r in r)
          for r in res
      )
  
      assert isinstance(res[0], tuple)
      assert len(res[0]) == 2
      assert np.allclose(res[0], [-np.sin(x), 0], atol=tol, rtol=0)
      assert isinstance(res[0][0], numpy.ndarray)
      assert isinstance(res[0][1], numpy.ndarray)
  
      assert isinstance(res[1], tuple)
      assert len(res[1]) == 2
      assert np.allclose(res[1], [0, np.cos(y)], atol=tol, rtol=0)
      assert isinstance(res[1][0], numpy.ndarray)
      assert isinstance(res[1][1], numpy.ndarray)
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.devices import DefaultQubitLegacy
  from pennylane.gradients import spsa_grad
  from pennylane.gradients.spsa_gradient import _rademacher_sampler
  from pennylane.operation import AnyWires, Observable
label_desc: Use image node_id 6 for calling the TestSpsaGradientIntegration obj's underlying member method code with example usage: obj.test_multiple_expectation_values(approx_order, strategy, validate, tol) without return types