class_docstr: Tests for the finite difference gradient transform
class_docstr_tok: ["Tests","for","the","finite","difference","gradient","transform"]
docstr: Tests correct output shape and evaluation for a tape
  with a multiple measurement, where only one parameter is chosen to
  be trainable.
  
  This test relies on the fact that exactly one term of the estimated
  jacobian will match the expected analytical value.
docstr_tok: ["Tests","correct","output","shape","and","evaluation","for","a","tape","with","a","multiple","measurement",",","where","only","one","parameter","is","chosen","to","be","trainable",".","This","test","relies","on","the","fact","that","exactly","one","term","of","the","estimated","jacobian","will","match","the","expected","analytical","value","."]
code: def test_probs_expval_with_argnum_one(
      self, approx_order, strategy, validate
  ):
      """Tests correct output shape and evaluation for a tape
      with a multiple measurement, where only one parameter is chosen to
      be trainable.
  
      This test relies on the fact that exactly one term of the estimated
      jacobian will match the expected analytical value.
      """
  
      dev = qml.device(
          "default.qubit", wires=2, shots=many_shots_shot_vector
      )
      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.probs(wires=[0, 1])
          qml.expval(qml.PauliZ(0) @ qml.PauliX(1))
  
      tape = qml.tape.QuantumScript.from_queue(
          q, shots=many_shots_shot_vector
      )
      # we choose only 1 trainable parameter
      tapes, fn = finite_diff(
          tape,
          argnum=1,
          approx_order=approx_order,
          strategy=strategy,
          validate_params=validate,
          h=h_val,
      )
      all_res = fn(dev.execute(tapes))
  
      assert isinstance(all_res, tuple)
      assert len(all_res) == len(many_shots_shot_vector)
  
      cx, sx, cy, sy = (
          np.cos(x / 2),
          np.sin(x / 2),
          np.cos(y / 2),
          np.sin(y / 2),
      )
      # probability vector is [cx**2 * cy**2, cx**2 * sy**2, sx**2 * sy**2, sx**2 * cy**2]
      exp_dprob = np.array(
          [-(cx**2), cx**2, sx**2, -(sx**2)]
      ) * (sy * cy)
      exp_probs = [np.zeros(4), exp_dprob]
      # expval is np.sin(y) * np.cos(x)
      exp_expval = [0, np.cos(y) * np.cos(x)]
  
      for res in all_res:
          assert isinstance(res, tuple)
          assert len(res) == 2  # two measurements
          assert np.allclose(res[0], exp_probs, atol=0.07)
          assert np.allclose(res[1], exp_expval, atol=0.2)
  
imports: import numpy
  import pytest
  from pennylane import numpy
  import pennylane
  from pennylane.gradients import finite_diff
  from pennylane.devices import DefaultQubitLegacy
  from pennylane.measurements import Shots
  from pennylane.operation import Observable, AnyWires
label_desc: Use image node_id 5 for calling the TestFiniteDiffIntegration obj's underlying member method code with example usage: obj.test_probs_expval_with_argnum_one(approx_order, strategy, validate) without return types