Record an observation of the objective function
        parameter_id : int
        parameters : dict of parameters
        value: final metrics of the trial, including reward
483256
def receive_trial_result(self, parameter_id, parameters, value):
        '''
        
        '''
        logger.debug('acquiring lock for param {}'.format(parameter_id))
        self.thread_lock.acquire()
        logger.debug('lock for current acquired')
        reward = extract_scalar_reward(value)
        if self.optimize_mode is OptimizeMode.Minimize:
            reward = -reward

        logger.debug('receive trial result is:\n')
        logger.debug(str(parameters))
        logger.debug(str(reward))

        indiv = Individual(indiv_id=int(os.path.split(parameters['save_dir'])[1]),
                           graph_cfg=graph_loads(parameters['graph']), result=reward)
        self.population.append(indiv)
        logger.debug('releasing lock')
        self.thread_lock.release()
        self.events[indiv.indiv_id].set()
1367762
def observe(self):
        
        for option in self.options:
            if option.number == defines.OptionRegistry.OBSERVE.number:
                # if option.value is None:
                #    return 0
                if option.value is None:
                    return 0
                return option.value
        return None
529461
def _tracker(self, _observer_, _self_, *args, **kwds):
        
        self.track_object(_self_,
                          name=_observer_.name,
                          resolution_level=_observer_.detail,
                          keep=_observer_.keep,
                          trace=_observer_.trace)
        _observer_.init(_self_, *args, **kwds)
1218222
def report_final_result(metric):
    
    assert _params is not None, 'nni.get_next_parameter() needs to be called before report_final_result'
    metric = json_tricks.dumps({
        'parameter_id': _params['parameter_id'],
        'trial_job_id': trial_env_vars.NNI_TRIAL_JOB_ID,
        'type': 'FINAL',
        'sequence': 0,  # TODO: may be unnecessary
        'value': metric
    })
    platform.send_metric(metric)
779398
def _write_metrics(self, iteration:int, last_metrics:MetricsList, start_idx:int=2)->None:
        ""
        recorder = self.learn.recorder
        for i, name in enumerate(recorder.names[start_idx:]):
            if last_metrics is None or len(last_metrics) < i+1: return
            scalar_value = last_metrics[i]
            self._write_scalar(name=name, scalar_value=scalar_value, iteration=iteration)
1096114
def observe_reward_value(self, state_key, action_key):
        '''
        

        '''
        reward_value = 0.0
        if state_key in self.__state_action_list_dict:
            if action_key in self.__state_action_list_dict[state_key]:
                reward_value = 1.0

        return reward_value
709775
def record(self, attr, value):
        
        msg = "Call new_epoch before recording for the first time."
        if not self:
            raise ValueError(msg)
        self[-1][attr] = value
900707
def policy(self, observations):
        
        input_data = self.input_block(observations)
        policy_base_output = self.policy_backbone(input_data)
        policy_params = self.action_head(policy_base_output)
        return policy_params
1298148
def _define_experience(self, agent_indices, observ, action, reward):
    """"""
    update_filters = tf.summary.merge([
        self._observ_filter.update(observ),
        self._reward_filter.update(reward)])
    with tf.control_dependencies([update_filters]):
      if self._config.train_on_agent_action:
        # NOTE: Doesn't seem to change much.
        action = self._last_action
      policy = tools.nested.map(
          lambda x: tf.gather(x, agent_indices), self._last_policy)
      batch = (observ, action, policy, reward)
      append = self._current_episodes.append(batch, agent_indices)
    with tf.control_dependencies([append]):
      norm_observ = self._observ_filter.transform(observ)
      norm_reward = tf.reduce_mean(self._reward_filter.transform(reward))
      # pylint: disable=g-long-lambda
      summary = tf.cond(self._should_log, lambda: tf.summary.merge([
          update_filters,
          self._observ_filter.summary(),
          self._reward_filter.summary(),
          tf.summary.scalar('memory_size', self._num_finished_episodes),
          tf.summary.histogram('normalized_observ', norm_observ),
          tf.summary.histogram('action', self._last_action),
          tf.summary.scalar('normalized_reward', norm_reward)]), str)
      return summary
508224
def value_parameters(self):
        
        return it.chain(self.value_backbone.parameters(), self.critic_head.parameters())
221351
def define_ppo_step(data_points, hparams, action_space, lr):
  """"""
  observation, action, discounted_reward, norm_advantage, old_pdf = data_points

  obs_shape = common_layers.shape_list(observation)
  observation = tf.reshape(
      observation, [obs_shape[0] * obs_shape[1]] + obs_shape[2:]
  )
  (logits, new_value) = get_policy(observation, hparams, action_space)
  logits = tf.reshape(logits, obs_shape[:2] + [action_space.n])
  new_value = tf.reshape(new_value, obs_shape[:2])
  new_policy_dist = tfp.distributions.Categorical(logits=logits)

  new_pdf = new_policy_dist.prob(action)

  ratio = new_pdf / old_pdf
  clipped_ratio = tf.clip_by_value(ratio, 1 - hparams.clipping_coef,
                                   1 + hparams.clipping_coef)

  surrogate_objective = tf.minimum(clipped_ratio * norm_advantage,
                                   ratio * norm_advantage)
  policy_loss = -tf.reduce_mean(surrogate_objective)

  value_error = new_value - discounted_reward
  value_loss = hparams.value_loss_coef * tf.reduce_mean(value_error ** 2)

  entropy = new_policy_dist.entropy()
  entropy_loss = -hparams.entropy_loss_coef * tf.reduce_mean(entropy)

  losses = [policy_loss, value_loss, entropy_loss]
  loss = sum(losses)
  variables = tf.global_variables(hparams.policy_network + "/.*")
  train_op = optimize.optimize(loss, lr, hparams, variables=variables)

  with tf.control_dependencies([train_op]):
    return [tf.identity(x) for x in losses]
1231081
def step(self, observation, argmax_sampling=False):
        
        policy_params, q = self(observation)
        actions = self.action_head.sample(policy_params, argmax_sampling=argmax_sampling)

        # log probability - we can do that, because we support only discrete action spaces
        logprobs = self.action_head.logprob(actions, policy_params)

        return {
            'actions': actions,
            'q': q,
            'logprobs': policy_params,
            'action:logprobs': logprobs
        }
1065236
def has_observation_id(self, observation_id):
        
        self.con.execute('SELECT 1 FROM archive_observations WHERE publicId = %s', (observation_id,))
        return len(self.con.fetchall()) > 0
567622
def runExperiment( self, e ):
        """"""

        # create the parameter space
        ps = self.parameterSpace()

        # run the experiment at each point
        nb = self.notebook()
        for p in ps:
            #print "Running {p}".format(p = p)
            res = e.set(p).run()
            nb.addResult(res)

        # commit the results
        nb.commit()
1121742
def after_epoch(self, epoch_id: int, epoch_data: EpochData) -> None:
        

        super().after_epoch(epoch_id=epoch_id, epoch_data=epoch_data)

        self._saved_loss.append(epoch_data[self._stream][self._variable][OnPlateau._AGGREGATION])

        long_mean = np.mean(self._saved_loss[-self._long_term:])
        short_mean = np.mean(self._saved_loss[-self._short_term:])
        if self._objective == 'min' and long_mean < short_mean:
            self._on_plateau_action(epoch_id=epoch_id, epoch_data=epoch_data)
        elif self._objective == 'max' and long_mean > short_mean:
            self._on_plateau_action(epoch_id=epoch_id, epoch_data=epoch_data)
529407
def save_variation_for_experiment(self, experiment_id, variation_id):
    

    self.experiment_bucket_map.update({
      experiment_id: {
        self.VARIATION_ID_KEY: variation_id
      }
    })
26169
def step(self, observations):
        
        log_histogram = self(observations)
        actions = self.q_head.sample(log_histogram)

        return {
            'actions': actions,
            'log_histogram': log_histogram
        }