class_docstr: Test errors raised by stoch_pulse_grad.
class_docstr_tok: ["Test","errors","raised","by","stoch_pulse_grad","."]
docstr: Test that an empty gradient is returned when there are no trainable parameters.
docstr_tok: ["Test","that","an","empty","gradient","is","returned","when","there","are","no","trainable","parameters","."]
code: def test_warning_no_trainable_params(self, num_meas):
      """Test that an empty gradient is returned when there are no trainable parameters."""
      measurements = [
          qml.expval(qml.PauliX(w)) for w in range(num_meas)
      ]
      # No parameters at all
      tape = qml.tape.QuantumScript([], measurements=measurements)
      with pytest.warns(
          UserWarning,
          match="Attempted to compute the gradient of a tape with no trainable",
      ):
          tapes, fn = stoch_pulse_grad(tape)
      assert not tapes
      assert qml.math.allclose(
          fn([]), tuple(qml.math.zeros([0]) for _ in range(num_meas))
      )
  
      # parameters but none are trainable
      ops = [qml.RX(0.4, 2), qml.CRY(0.1, [1, 0])]
      tape = qml.tape.QuantumScript(ops, measurements=measurements)
      tape.trainable_params = []
      with pytest.warns(
          UserWarning,
          match="Attempted to compute the gradient of a tape with no trainable",
      ):
          tapes, fn = stoch_pulse_grad(tape)
      assert not tapes
      assert qml.math.allclose(
          fn([]), tuple(qml.math.zeros([0]) for _ in range(num_meas))
      )
  
imports: import warnings
  import copy
  import pytest
  import numpy
  import pennylane
  from pennylane.gradients.general_shift_rules import eigvals_to_frequencies, generate_shift_rule
  from pennylane.gradients.pulse_gradient import _parshift_and_integrate, _split_evol_ops, _split_evol_tape, stoch_pulse_grad
label_desc: Use image node_id 5 for calling the TestStochPulseGradErrors obj's underlying member method code with example usage: obj.test_warning_no_trainable_params(num_meas) without return types