class_docstr: Unit tests for the pennylane.qnn.torch.TorchLayer class.
class_docstr_tok: ["Unit","tests","for","the","pennylane.qnn.torch.TorchLayer","class","."]
docstr: Test if the forward() method accepts a batched input with multiple dimensions and returns a tensor of the
  right shape by broadcasting. Also tests if gradients are still backpropagated correctly.
docstr_tok: ["Test","if","the","forward","(",")","method","accepts","a","batched","input","with","multiple","dimensions","and","returns","a","tensor","of","the","right","shape","by","broadcasting",".","Also","tests","if","gradients","are","still","backpropagated","correctly","."]
code: def test_forward_broadcasting(
      self, get_circuit, output_dim, middle_dim, batch_size, n_qubits
  ):  # pylint: disable=too-many-arguments,no-self-use
      """Test if the forward() method accepts a batched input with multiple dimensions and returns a tensor of the
      right shape by broadcasting. Also tests if gradients are still backpropagated correctly.
      """
      c, w = get_circuit
      layer = TorchLayer(c, w)
  
      x = torch.Tensor(np.ones((batch_size, middle_dim, n_qubits)))
  
      weights = layer.qnode_weights.values()
  
      layer_out = layer.forward(x)
      layer_out.backward(torch.ones_like(layer_out))
  
      g_layer = [w.grad for w in weights]
  
      assert g_layer.count(None) == 0
      assert layer_out.shape == torch.Size(
          (batch_size, middle_dim, output_dim)
      )
  
imports: from unittest import mock
  import math
  from collections import defaultdict
  import numpy
  import pytest
  import pennylane
  from pennylane.qnn.torch import TorchLayer
label_desc: Use image node_id 21 for calling the TestTorchLayer obj's underlying member method code with example usage: obj.test_forward_broadcasting(get_circuit, output_dim, middle_dim, batch_size, n_qubits) without return types