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: Analytic value of cost_fn above
docstr_tok: ["Analytic","value","of","cost_fn","above"]
code: def cost_fn_expected(weights, coeffs1, coeffs2):
      """Analytic value of cost_fn above"""
      a, b, c = coeffs1.clone().detach()
      d = coeffs2[0].clone().detach()
      x, y = weights.clone().detach()
      return torch.tensor(
          [
              -c * torch.sin(x) * torch.sin(y)
              + torch.cos(x) * (a + b * torch.sin(y)),
              d * torch.cos(x),
          ]
      )
  
imports: import numpy
  import pytest
  from param_shift_dev import ParamShiftDerivativesDevice
  import pennylane
  from pennylane.devices import DefaultQubit
  from pennylane.gradients import param_shift
  from pennylane import execute
  from pennylane.measurements import Shots
label_desc: Use image node_id 2 for calling the TestHamiltonianWorkflows obj's underlying member method code with example usage: obj.cost_fn_expected(weights, coeffs1, coeffs2) and returns: torch