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 module that includes TorchLayers can perform one optimization step. This
  test checks that some of the parameters in the module are different after one step.
  The module is composed of two TorchLayers sandwiched between Linear neural network layers,
  and the dataset is simply input and output vectors of zeros.
docstr_tok: ["Test","if","a","module","that","includes","TorchLayers","can","perform","one","optimization","step",".","This","test","checks","that","some","of","the","parameters","in","the","module","are","different","after","one","step",".","The","module","is","composed","of","two","TorchLayers","sandwiched","between","Linear","neural","network","layers",",","and","the","dataset","is","simply","input","and","output","vectors","of","zeros","."]
code: def test_step_module(
      self, module, batch_size, n_qubits, output_dim, dtype
  ):  # pylint: disable=redefined-outer-name,too-many-arguments,no-self-use
      """Test if a module that includes TorchLayers can perform one optimization step. This
      test checks that some of the parameters in the module are different after one step.
      The module is composed of two TorchLayers sandwiched between Linear neural network layers,
      and the dataset is simply input and output vectors of zeros."""
      if dtype == "float32":
          dtype = torch.float32
      else:
          dtype = torch.float64
  
      module = module.type(dtype)
      loss_func = torch.nn.MSELoss()
      optimizer = torch.optim.SGD(module.parameters(), lr=0.5)
  
      x = torch.zeros((batch_size, n_qubits)).type(dtype)
      y = torch.zeros((batch_size, output_dim)).type(dtype)
  
      params_before = [w.detach().clone() for w in module.parameters()]
  
      module_out = module(x)
      optimizer.zero_grad()
      loss = loss_func(module_out, y)
      loss.backward()
      optimizer.step()
  
      params_after = [w.detach().clone() for w in module.parameters()]
  
      params_similar = [
          torch.allclose(p1, p2)
          for p1, p2 in zip(params_before, params_after)
      ]
      assert not all(params_similar)
  
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 1 for calling the TestTorchLayerIntegration obj's underlying member method code with example usage: obj.test_step_module(module, batch_size, n_qubits, output_dim, dtype) without return types