class_docstr: Test that tapes ending with expectations
  of Hamiltonians provide correct results and gradients
class_docstr_tok: ["Test","that","tapes","ending","with","expectations","of","Hamiltonians","provide","correct","results","and","gradients"]
docstr: Test hamiltonian with trainable parameters.
docstr_tok: ["Test","hamiltonian","with","trainable","parameters","."]
code: def test_multiple_hamiltonians_trainable(
      self, cost_fn, execute_kwargs, shots, use_new_op_math
  ):
      """Test hamiltonian with trainable parameters."""
      if execute_kwargs["gradient_fn"] == "adjoint":
          pytest.skip(
              "trainable hamiltonians not supported with adjoint"
          )
      if use_new_op_math:
          pytest.skip(
              "parameter shift derivatives do not yet support sums."
          )
  
      coeffs1 = tf.Variable([0.1, 0.2, 0.3], dtype=tf.float64)
      coeffs2 = tf.Variable([0.7], dtype=tf.float64)
      weights = tf.Variable([0.4, 0.5], dtype=tf.float64)
  
      with tf.GradientTape() as tape:
          res = cost_fn(weights, coeffs1, coeffs2)
  
      expected = self.cost_fn_expected(weights, coeffs1, coeffs2)
      assert np.allclose(
          res, expected, atol=atol_for_shots(shots), rtol=0
      )
  
      jac = qml.math.hstack(
          tape.jacobian(res, [weights, coeffs1, coeffs2]),
          like="tensorflow",
      )
      expected = self.cost_fn_jacobian(weights, coeffs1, coeffs2)
      assert np.allclose(
          jac, expected, atol=atol_for_shots(shots), rtol=0
      )
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane.devices import DefaultQubit
  from pennylane.gradients import param_shift
  from pennylane import execute
label_desc: Use image node_id 5 for calling the TestHamiltonianWorkflows obj's underlying member method code with example usage: obj.test_multiple_hamiltonians_trainable(cost_fn, execute_kwargs, shots, use_new_op_math) without return types