class_docstr: Integration tests for the pennylane.qnn.torch.TorchLayer class.
class_docstr_tok: ["Integration","tests","for","the","pennylane.qnn.torch.TorchLayer","class","."]
docstr: Test if a gradient can be calculated with respect to all of the trainable variables in
  the module
docstr_tok: ["Test","if","a","gradient","can","be","calculated","with","respect","to","all","of","the","trainable","variables","in","the","module"]
code: def test_module_gradients(
      self, module, output_dim, n_qubits, get_circuit
  ):  # pylint: disable=redefined-outer-name,no-self-use
      """Test if a gradient can be calculated with respect to all of the trainable variables in
      the module"""
      _, w = get_circuit
  
      x = torch.zeros((2, n_qubits))
      y = torch.zeros((2, output_dim))
  
      module_out = module(x)
      loss_func = torch.nn.MSELoss()
      loss = loss_func(module_out, y)
      loss.backward()
  
      gradients = [w.grad for w in module.parameters()]
      assert all(g.is_floating_point() for g in gradients)
      assert len(gradients) == 2 * len(w) + 6
  
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 2 for calling the TestTorchLayerIntegration obj's underlying member method code with example usage: obj.test_module_gradients(module, output_dim, n_qubits, get_circuit) without return types