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: Cost function for gradient tests
code: def cost_fn(self, execute_kwargs):
      """Cost function for gradient tests"""
  
      def _cost_fn(weights, coeffs1, coeffs2, dev=None):
          obs1 = [
              qml.PauliZ(0),
              qml.PauliZ(0) @ qml.PauliX(1),
              qml.PauliY(0),
          ]
          H1 = qml.Hamiltonian(coeffs1, obs1)
  
          obs2 = [qml.PauliZ(0)]
          H2 = qml.Hamiltonian(coeffs2, obs2)
  
          with qml.queuing.AnnotatedQueue() as q:
              qml.RX(weights[0], wires=0)
              qml.RY(weights[1], wires=1)
              qml.CNOT(wires=[0, 1])
              qml.expval(H1)
              qml.expval(H2)
  
          tape = qml.tape.QuantumScript.from_queue(q)
  
          return torch.hstack(execute([tape], dev, **execute_kwargs)[0])
  
      return _cost_fn
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane.gradients import finite_diff, param_shift
  from pennylane import execute
label_desc: Use image node_id 1 for calling the TestHamiltonianWorkflows obj's underlying member method code with example usage: obj.cost_fn(execute_kwargs) and returns: _cost_fn, torch