class_docstr: Hamiltonian VAE.
  
  Args:
      model_config (HVAEConfig): A model configuration setting the main parameters of the model.
  
      encoder (BaseEncoder): An instance of BaseEncoder (inheriting from `torch.nn.Module` which
          plays the role of encoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
      decoder (BaseDecoder): An instance of BaseDecoder (inheriting from `torch.nn.Module` which
          plays the role of decoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
  .. note::
      For high dimensional data we advice you to provide you own network architectures. With the
      provided MLP you may end up with a ``MemoryError``.
class_docstr_tok: ["Hamiltonian","VAE",".","Args",":","model_config","(","HVAEConfig",")",":","A","model","configuration","setting","the","main","parameters","of","the","model",".","encoder","(","BaseEncoder",")",":","An","instance","of","BaseEncoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","encoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","decoder","(","BaseDecoder",")",":","An","instance","of","BaseDecoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","decoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","..","note",":",":","For","high","dimensional","data","we","advice","you","to","provide","you","own","network","architectures",".","With","the","provided","MLP","you","may","end","up","with","a","``","MemoryError","``","."]
docstr: The input data is first encoded. The reparametrization is used to produce a sample
  :math:`z_0` from the approximate posterior :math:`q_{\phi}(z|x)`. Then
  Hamiltonian equations are solved using the leapfrog integrator.
  
  Args:
      inputs (BaseDataset): The training data with labels
  
  Returns:
      output (ModelOutput): An instance of ModelOutput containing all the relevant parameters
docstr_tok: ["The","input","data","is","first","encoded",".","The","reparametrization","is","used","to","produce","a","sample",":","math",":","`","z_0","`","from","the","approximate","posterior",":","math",":","`","q_","{","\\phi","}","(","z|x",")","`",".","Then","Hamiltonian","equations","are","solved","using","the","leapfrog","integrator",".","Args",":","inputs","(","BaseDataset",")",":","The","training","data","with","labels","Returns",":","output","(","ModelOutput",")",":","An","instance","of","ModelOutput","containing","all","the","relevant","parameters"]
code: def forward(self, inputs: BaseDataset, **kwargs) -> ModelOutput:
      r"""
      The input data is first encoded. The reparametrization is used to produce a sample
      :math:`z_0` from the approximate posterior :math:`q_{\phi}(z|x)`. Then
      Hamiltonian equations are solved using the leapfrog integrator.
  
      Args:
          inputs (BaseDataset): The training data with labels
  
      Returns:
          output (ModelOutput): An instance of ModelOutput containing all the relevant parameters
      """
  
      x = inputs["data"]
      encoder_output = self.encoder(x)
      mu, log_var = (
          encoder_output.embedding,
          encoder_output.log_covariance,
      )
  
      std = F.softplus(log_var)
      z0, eps0 = self._sample_gauss(mu, std)
      gamma = torch.randn_like(z0, device=x.device)
      rho = gamma / self.beta_zero_sqrt
  
      z = z0
      beta_sqrt_old = self.beta_zero_sqrt
  
      for k in range(self.n_lf):
          # perform leapfrog steps
  
          # 1st leapfrog step
          rho_ = rho - (self.eps_lf / 2) * self._dU_dz(z, x)
  
          # 2nd leapfrog step
          z_ = z + self.eps_lf * rho
  
          # 3rd leapfrog step
          rho__ = rho_ - (self.eps_lf / 2) * self._dU_dz(z_, x)
  
          # tempering steps
          beta_sqrt = self._tempering(k + 1, self.n_lf)
          rho = (beta_sqrt_old / beta_sqrt) * rho__
          beta_sqrt_old = beta_sqrt
  
          z = z_
          rho = rho__
  
      recon_x = self.decoder(z)["reconstruction"].reshape_as(x)
  
      loss = self.loss_function(x, z, rho, z0, mu, log_var)
  
      output = ModelOutput(
          loss=loss,
          recon_x=recon_x,
          z=z,
          z0=z0,
          rho=rho,
          eps0=eps0,
          gamma=gamma,
          mu=mu,
          log_var=log_var,
      )
  
      return output
  
imports: import warnings
  from typing import Optional
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.autograd import grad
  from ...data.datasets import BaseDataset
  from ..base.base_utils import ModelOutput
  from ..nn import BaseDecoder, BaseEncoder
  from ..vae import VAE
  from .hvae_config import HVAEConfig
label_desc: Use image node_id 2 for calling the HVAE obj's underlying member method code with example usage: obj.forward(inputs) and returns: output