code: def test_partial_evaluation_torch(diff_method):
      """Test gradient of partial evaluation matches gradients of
      individual full evaluations using PyTorch"""
      import torch
      import torch.autograd.functional as F
  
      dev = qml.device("default.qubit", wires=2)
  
      @qml.qnode(dev, diff_method=diff_method)
      def circuit(x, y):
          qml.RX(x, wires=0)
          qml.RY(y[..., 0], wires=0)
          qml.RY(y[..., 1], wires=1)
          return qml.expval(qml.PauliZ(wires=0) @ qml.PauliZ(wires=1))
  
      batch_size = 4
  
      # the partial argument to construct a new circuit with
      y = torch.tensor(np.random.uniform(size=2), requires_grad=True)
  
      # the batched argument to the new partial circuit
      x = torch.tensor(
          np.random.uniform(size=batch_size), requires_grad=True
      )
  
      batched_partial_circuit = qml.batch_partial(circuit, y=y)
  
      # we could also sum over the batch dimension and use the regular
      # gradient instead of the jacobian, but either works
      grad = torch.diagonal(F.jacobian(batched_partial_circuit, x))
  
      # check the results against individually executed circuits
      indiv_grad = []
      for x_indiv in x:
          # create a new variable since tensors created by
          # indexing a trainable variable aren't themselves trainable
          x_indiv = x_indiv.clone().detach().requires_grad_(True)
  
          out_indiv = circuit(x_indiv, y)
          out_indiv.backward()
  
          indiv_grad.append(x_indiv.grad)
  
      assert np.allclose(grad, indiv_grad)
  
imports: import re
  import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 10 for calling a global function with example usage: test_partial_evaluation_torch(diff_method) and returns: qml