class_docstr: Tests for VQE with interfaces.
class_docstr_tok: ["Tests","for","VQE","with","interfaces","."]
docstr: Test the gradient agrees across all interfaces
docstr_tok: ["Test","the","gradient","agrees","across","all","interfaces"]
code: def test_all_interfaces_gradient_agree(self, tol):
      """Test the gradient agrees across all interfaces"""
      import tensorflow as tf
      import torch
  
      dev = qml.device("default.qubit", wires=2)
  
      coeffs = [0.2, 0.5]
      observables = [qml.PauliX(0) @ qml.PauliZ(1), qml.PauliY(0)]
  
      H = qml.Hamiltonian(coeffs, observables)
  
      np.random.seed(1)
      shape = qml.templates.StronglyEntanglingLayers.shape(3, 2)
      params = np.random.uniform(low=0, high=2 * np.pi, size=shape)
  
      # TensorFlow interface
      w = tf.Variable(params)
      ansatz = qml.templates.layers.StronglyEntanglingLayers
  
      cost = catch_warn_ExpvalCost(ansatz, H, dev, interface="tf")
  
      with tf.GradientTape() as tape:
          loss = cost(w)
          res_tf = np.array(tape.gradient(loss, w))
  
      # Torch interface
      w = torch.tensor(params, requires_grad=True)
      w = torch.autograd.Variable(w, requires_grad=True)
      ansatz = qml.templates.layers.StronglyEntanglingLayers
  
      cost = catch_warn_ExpvalCost(ansatz, H, dev, interface="torch")
      loss = cost(w)
      loss.backward()
      res_torch = w.grad.numpy()
  
      # NumPy interface
      w = params
      ansatz = qml.templates.layers.StronglyEntanglingLayers
      cost = catch_warn_ExpvalCost(ansatz, H, dev, interface="autograd")
      dcost = qml.grad(cost, argnum=[0])
      res = dcost(w)
  
      assert np.allclose(res, res_tf, atol=tol, rtol=0)
      assert np.allclose(res, res_torch, atol=tol, rtol=0)
  
imports: import copy
  import numpy
  import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 4 for calling the TestInterfaces obj's underlying member method code with example usage: obj.test_all_interfaces_gradient_agree(tol) without return types