class_docstr: PPOTuner, the implementation inherits the main logic of the implementation
  `ppo2 from openai <https://github.com/openai/baselines/tree/master/baselines/ppo2>`__ and is adapted for NAS scenario.
  It uses ``lstm`` for its policy network and value network, policy and value share the same network.
  
  Parameters
  ----------
  optimize_mode : str
      maximize or minimize
  trials_per_update : int
      Number of trials to have for each model update
  epochs_per_update : int
      Number of epochs to run for each model update
  minibatch_size : int
      Minibatch size (number of trials) for the update
  ent_coef : float
      Policy entropy coefficient in the optimization objective
  lr : float
      Learning rate of the model (lstm network), constant
  vf_coef : float
      Value function loss coefficient in the optimization objective
  max_grad_norm : float
      Gradient norm clipping coefficient
  gamma : float
      Discounting factor
  lam : float
      Advantage estimation discounting factor (lambda in the paper)
  cliprange : float
      Cliprange in the PPO algorithm, constant
class_docstr_tok: ["PPOTuner",",","the","implementation","inherits","the","main","logic","of","the","implementation","`","ppo2","from","openai","<","https",":","\/\/github.com\/openai\/baselines\/tree\/master\/baselines\/ppo2",">","`","__","and","is","adapted","for","NAS","scenario",".","It","uses","``","lstm","``","for","its","policy","network","and","value","network",",","policy","and","value","share","the","same","network",".","Parameters","--","--","--","--","--","optimize_mode",":","str","maximize","or","minimize","trials_per_update",":","int","Number","of","trials","to","have","for","each","model","update","epochs_per_update",":","int","Number","of","epochs","to","run","for","each","model","update","minibatch_size",":","int","Minibatch","size","(","number","of","trials",")","for","the","update","ent_coef",":","float","Policy","entropy","coefficient","in","the","optimization","objective","lr",":","float","Learning","rate","of","the","model","(","lstm","network",")",",","constant","vf_coef",":","float","Value","function","loss","coefficient","in","the","optimization","objective","max_grad_norm",":","float","Gradient","norm","clipping","coefficient","gamma",":","float","Discounting","factor","lam",":","float","Advantage","estimation","discounting","factor","(","lambda","in","the","paper",")","cliprange",":","float","Cliprange","in","the","PPO","algorithm",",","constant"]
docstr: To deal with trial failure. If a trial fails, it is popped out from ``self.running_trials``,
  and the final result of this trial is assigned with the average of the finished trials.
  
  Parameters
  ----------
  parameter_id : int
      Unique identifier for hyper-parameters used by this trial.
  success : bool
      True if the trial successfully completed; False if failed or terminated.
  **kwargs
      Not used
docstr_tok: ["To","deal","with","trial","failure",".","If","a","trial","fails",",","it","is","popped","out","from","``","self.running_trials","``",",","and","the","final","result","of","this","trial","is","assigned","with","the","average","of","the","finished","trials",".","Parameters","--","--","--","--","--","parameter_id",":","int","Unique","identifier","for","hyper-parameters","used","by","this","trial",".","success",":","bool","True","if","the","trial","successfully","completed",";","False","if","failed","or","terminated",".","*","*","kwargs","Not","used"]
code: def trial_end(self, parameter_id, success, **kwargs):
      """
      To deal with trial failure. If a trial fails, it is popped out from ``self.running_trials``,
      and the final result of this trial is assigned with the average of the finished trials.
  
      Parameters
      ----------
      parameter_id : int
          Unique identifier for hyper-parameters used by this trial.
      success : bool
          True if the trial successfully completed; False if failed or terminated.
      **kwargs
          Not used
      """
      if not success:
          if parameter_id not in self.running_trials:
              logger.warning(
                  "The trial is failed, but self.running_trial does not have this trial"
              )
              return
          trial_info_idx = self.running_trials.pop(parameter_id, None)
          assert trial_info_idx is not None
          # use mean of finished trials as the result of this failed trial
          values = [
              val for val in self.trials_result if val is not None
          ]
          logger.warning("In trial_end, values: %s", values)
          self.trials_result[trial_info_idx] = (
              (np.mean(values)) if values else 0
          )
          self.finished_trials += 1
          if self.finished_trials == self.inf_batch_size:
              logger.debug("Start next round inference in trial_end")
              self._next_round_inference()
  
imports: import copy
  import logging
  import numpy
  from gym import spaces
  from schema import Schema, Optional
  import nni
  from nni import ClassArgsValidator
  from nni.tuner import Tuner
  from nni.utils import OptimizeMode, extract_scalar_reward
  from .model import Model
  from .util import set_global_seeds
  from .policy import build_lstm_policy
label_desc: Use image node_id 10 for calling the PPOTuner obj's underlying member method code with example usage: obj.trial_end(parameter_id, success) without return types