class_docstr: Tests for the finite difference gradient transform
class_docstr_tok: ["Tests","for","the","finite","difference","gradient","transform"]
docstr: Test error raised if attempting to differentiate with
  respect to a non-differentiable argument
docstr_tok: ["Test","error","raised","if","attempting","to","differentiate","with","respect","to","a","non-differentiable","argument"]
code: def test_non_differentiable_error(self):
      """Test error raised if attempting to differentiate with
      respect to a non-differentiable argument"""
      psi = np.array([1, 0, 1, 0], requires_grad=False) / np.sqrt(2)
  
      with qml.queuing.AnnotatedQueue() as q:
          qml.StatePrep(psi, wires=[0, 1])
          qml.RX(0.543, wires=[0])
          qml.RY(-0.654, wires=[1])
          qml.CNOT(wires=[0, 1])
          qml.probs(wires=[0, 1])
  
      tape = qml.tape.QuantumScript.from_queue(
          q, shots=default_shot_vector
      )
      # by default all parameters are assumed to be trainable
      with pytest.raises(
          ValueError,
          match=r"Cannot differentiate with respect to parameter\(s\) {0}",
      ):
          finite_diff(tape)
  
      # setting trainable parameters avoids this
      tape.trainable_params = {1, 2}
      dev = qml.device(
          "default.qubit", wires=2, shots=default_shot_vector
      )
      tapes, fn = finite_diff(tape, h=h_val)
  
      all_res = fn(dev.execute(tapes))
  
      assert isinstance(all_res, tuple)
      assert len(all_res) == len(default_shot_vector)
  
      for res in all_res:
          assert isinstance(res, tuple)
  
          assert isinstance(res[0], numpy.ndarray)
          assert res[0].shape == (4,)
  
          assert isinstance(res[1], numpy.ndarray)
          assert res[1].shape == (4,)
  
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 1 for calling the TestFiniteDiff obj's underlying member method code with example usage: obj.test_non_differentiable_error() without return types