def cost(x):
     tape.set_parameters(x, trainable_only=False)
     tapes, fn = qml.transforms.hamiltonian_expand(tape)
     res = [t.execute(dev) for t in tapes]
     return fn(res)
 def cost(x):
     tape.set_parameters(x, trainable_only=False)
     tapes, fn = qml.transforms.hamiltonian_expand(tape)
     res = qml.execute(tapes, dev, qml.gradients.param_shift)
     return fn(res)