class_docstr: The base script for running different 3DGN methods.
class_docstr_tok: ["The","base","script","for","running","different","3DGN","methods","."]
docstr: The script for validation/test.
  
  Args:
      model: Which 3DGN model to use. Should be one of the SchNet, DimeNetPP, and SphereNet.
      data_loader (Dataloader): Dataloader for validation or test.
      energy_and_force (bool, optional): If set to :obj:`True`, will predict energy and take the minus derivative of the energy with respect to the atomic positions as predicted forces. (default: :obj:`False`)    
      p (int, optinal): The forces’ weight for a joint loss of forces and conserved energy. (default: :obj:`100`)
      evaluation (function): The used funtion for evaluation.
      device (torch.device, optional): The device where the model is deployed.
  
  :rtype: Evaluation result. ( :obj:`mae`)
docstr_tok: ["The","script","for","validation\/test",".","Args",":","model",":","Which","3DGN","model","to","use",".","Should","be","one","of","the","SchNet",",","DimeNetPP",",","and","SphereNet",".","data_loader","(","Dataloader",")",":","Dataloader","for","validation","or","test",".","energy_and_force","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","will","predict","energy","and","take","the","minus","derivative","of","the","energy","with","respect","to","the","atomic","positions","as","predicted","forces",".","(","default",":",":","obj",":","`","False","`",")","p","(","int",",","optinal",")",":","The","forces","\u2019","weight","for","a","joint","loss","of","forces","and","conserved","energy",".","(","default",":",":","obj",":","`","100","`",")","evaluation","(","function",")",":","The","used","funtion","for","evaluation",".","device","(","torch.device",",","optional",")",":","The","device","where","the","model","is","deployed",".",":","rtype",":","Evaluation","result",".","(",":","obj",":","`","mae","`",")"]
code: def val(
      self, model, data_loader, energy_and_force, p, evaluation, device
  ):
      r"""
      The script for validation/test.
  
      Args:
          model: Which 3DGN model to use. Should be one of the SchNet, DimeNetPP, and SphereNet.
          data_loader (Dataloader): Dataloader for validation or test.
          energy_and_force (bool, optional): If set to :obj:`True`, will predict energy and take the minus derivative of the energy with respect to the atomic positions as predicted forces. (default: :obj:`False`)
          p (int, optinal): The forces’ weight for a joint loss of forces and conserved energy. (default: :obj:`100`)
          evaluation (function): The used funtion for evaluation.
          device (torch.device, optional): The device where the model is deployed.
  
      :rtype: Evaluation result. ( :obj:`mae`)
  
      """
      model.eval()
  
      preds = torch.Tensor([]).to(device)
      targets = torch.Tensor([]).to(device)
  
      if energy_and_force:
          preds_force = torch.Tensor([]).to(device)
          targets_force = torch.Tensor([]).to(device)
  
      for step, batch_data in enumerate(tqdm(data_loader)):
          batch_data = batch_data.to(device)
          out = model(batch_data)
          if energy_and_force:
              force = -grad(
                  outputs=out,
                  inputs=batch_data.pos,
                  grad_outputs=torch.ones_like(out),
                  create_graph=True,
                  retain_graph=True,
              )[0]
              preds_force = torch.cat(
                  [preds_force, force.detach_()], dim=0
              )
              targets_force = torch.cat(
                  [targets_force, batch_data.force], dim=0
              )
          preds = torch.cat([preds, out.detach_()], dim=0)
          targets = torch.cat(
              [targets, batch_data.y.unsqueeze(1)], dim=0
          )
  
      input_dict = {"y_true": targets, "y_pred": preds}
  
      if energy_and_force:
          input_dict_force = {
              "y_true": targets_force,
              "y_pred": preds_force,
          }
          energy_mae = evaluation.eval(input_dict)["mae"]
          force_mae = evaluation.eval(input_dict_force)["mae"]
          print({"Energy MAE": energy_mae, "Force MAE": force_mae})
          return energy_mae + p * force_mae
  
      return evaluation.eval(input_dict)["mae"]
  
file_path: DIG/dig/threedgraph/method/run.py
imports: import time
  import os
  import torch
  from torch.optim import Adam
  from torch_geometric.data import DataLoader
  import numpy
  from torch.autograd import grad
  from torch.utils.tensorboard import SummaryWriter
  from torch.optim.lr_scheduler import StepLR
  from tqdm import tqdm
label_desc: Use image node_id 4 for calling the run obj's underlying member method code with example usage: obj.val(model, data_loader, energy_and_force, p, evaluation, device) and returns: evaluation, unknown