class_docstr: Instrumented function which plays the agent using an environment runner
class_docstr_tok: ["Instrumented","function","which","plays","the","agent","using","an","environment","runner"]
code: def compute(self, **kwargs: np.ndarray) -> float:
      self.agent.load_state_dict(kwargs)
      try:  # safeguard against nans
          with torch.no_grad():
              reward = self.runner.run(self.agent)
  
      except RuntimeError as e:
          warnings.warn(f"Returning 0 after error: {e}")
          reward = 0.0
      assert isinstance(reward, (int, float))
      return self.reward_postprocessing(reward)
  
imports: import warnings
  import operator
  import copy
  import typing
  import gym
  import numpy
  from nevergrad.common.tools import pytorch_import_fix
  from nevergrad.parametrization import parameter
  from ..base import ExperimentFunction
  from .None import base
  from .None import envs
  import torch
  import torch.nn.functional
  from torch import nn
  from torch.utils.data import WeightedRandomSampler
label_desc: Use image node_id 2 for calling the TorchAgentFunction obj's underlying member method code with example usage: obj.compute() and returns: self