class_docstr: Population class
      
class_docstr_tok: ["Population","class"]
code: def append(self, individual, fitness):
      if self.opt_mode == "minimize":
          fitness = -1 * fitness
  
      self.population.append(individual)
  
      if self.max_reward < fitness:
          self.max_reward = fitness
          self.config = individual
  
      if self.collect:
          idx = self.collect.index(individual)
          self.waiting_rewards[idx] = fitness
          del self.collect[idx]
      else:
          raise RuntimeError("Received unexpected trials.")
  
      if not self.collect:
          self.rewards.extend(self.waiting_rewards)
  
          self.ac_optimizer.zero_grad()
          gradient_loss = 0
          value_loss = 0
          for i in range(len(self.values)):
              advantage = self.rewards[i] - self.values[i]
              gradient_loss += self.log_probs[i] * advantage
              value_loss += torch.pow(advantage, 2)
          loss = gradient_loss + value_loss
          loss.backward()
          self.ac_optimizer.step()
  
          self.rewards = []
          self.values = []
          self.log_probs = []
          self.collect = []
  
imports: import math
  import random
  import logging
  import copy
  import torch
  from torch import optim
  from torch import nn
  import torch.nn.functional
  import numpy
  import nni
  from nni.tuner import Tuner
label_desc: Use image node_id 2 for calling the Population obj's underlying member method code with example usage: obj.append(individual, fitness) without return types