class_docstr: ## Trainer
class_docstr_tok: ["#","#","Trainer"]
docstr: ### Sample data
docstr_tok: ["#","#","#","Sample","data"]
code: def sample(self, exploration_coefficient: float):
      """### Sample data"""
  
      # This doesn't need gradients
      with torch.no_grad():
          # Sample `worker_steps`
          for t in range(self.worker_steps):
              # Get Q_values for the current observation
              q_value = self.model(obs_to_torch(self.obs))
              # Sample actions
              actions = self._sample_action(
                  q_value, exploration_coefficient
              )
  
              # Run sampled actions on each worker
              for w, worker in enumerate(self.workers):
                  worker.child.send(("step", actions[w]))
  
              # Collect information from each worker
              for w, worker in enumerate(self.workers):
                  # Get results after executing the actions
                  next_obs, reward, done, info = worker.child.recv()
  
                  # Add transition to replay buffer
                  self.replay_buffer.add(
                      self.obs[w], actions[w], reward, next_obs, done
                  )
  
                  # update episode information.
                  # collect episode info, which is available if an episode finished;
                  #  this includes total reward and length of the episode -
                  #  look at `Game` to see how it works.
                  if info:
                      tracker.add("reward", info["reward"])
                      tracker.add("length", info["length"])
  
                  # update current observation
                  self.obs[w] = next_obs
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/rl/dqn/experiment.py
imports: import numpy
  import torch
  from labml import tracker, experiment, logger, monit
  from labml.internal.configs.dynamic_hyperparam import FloatDynamicHyperParam
  from labml_helpers.schedule import Piecewise
  from labml_nn.rl.dqn import QFuncLoss
  from labml_nn.rl.dqn.model import Model
  from labml_nn.rl.dqn.replay_buffer import ReplayBuffer
  from labml_nn.rl.game import Worker
label_desc: Use image node_id 3 for calling the Trainer obj's underlying member method code with example usage: obj.sample(exploration_coefficient) without return types