original_docstring: Apply action and return new time_step.
docstring: Apply action and return new time_step.
docstring_tokens: Apply action and return new time_step .
code: def _step(self, action):
          """Apply action and return new time_step."""
  
          if self._episode_ended:
              return self.reset()
  
          # 计算action
          action_num     = int(action % len(self.action_list))
          action_layer   = int(action / len(self.action_list))
  
          self._state[action_layer] += self.action_list[action_num]
  
          if self.debug:
              print(f'Round {self.round} 薄膜结构: {self._state}, 前序观测: {self.pre_observation}')
          if self.save_log:
              self.logger.log_record_csv(self._state)
  
          # print(f'仿真的状态:{self._state}')
          self.opticalModel.RunSim(self._state)
          
  
          # 计算observation
          observation_loss = self.opticalModel.simulation_result
          observation_loss = film_loss(aim          = self.target, 
                                  weight       = self.weight,
                                  observation  = observation_loss,
                                  average      = True,
                                  debug        = self.debug,
                                  betterfgood  = False)
  
          observation = copy.copy(self._state)
          observation.append(observation_loss)
  
          #print(self._state, observation)
          # print(observation)
  
          # Exit Rule I: Exit Env When Structure Out of Bound.
          error_structure = False
          for s in self._state:
              if s < 0:
                  error_structure = True
                  self._episode_ended = True
  
          # Exit Rule II: Exit Env When Film Satisfied Aim Performance.
          reach_performance_threshold = False
          if observation_loss >= self.end_threshold:
              reach_performance_threshold = True
              self._episode_ended = True
  
          # Exit Rule III: Exit Env When Film not Prove in Threshold Round.
          reach_round_threshold = False
          if self.round >= self.round_threshold:
              reach_round_threshold = True
              self._episode_ended = True
          
          # Exit Term
          if self._episode_ended:
              if error_structure:
                  reward = -1
              elif reach_performance_threshold:
                  reward = 1
              elif reach_round_threshold:
                  reward = -0.1
  
              if self.debug:
                  self.logger.log_record_run([reward, observation_loss])
  
              return ts.termination(observation = np.array(observation, dtype=np.float32),
                          reward      = reward)
              
          # 更新条件
          elif observation_loss < self.pre_observation:
              reward = (self.pre_observation - observation_loss) * 100
              self.pre_observation = min(observation_loss, self.pre_observation)
              self.round = 0
              
              if self.debug:
                  self.logger.log_record_run([reward, observation_loss])
  
              return ts.transition(observation = np.array(observation, dtype=np.float32),
                                   reward      = reward,
                                   discount    = 1.0)
          else:
              self.round += 1
              reward = -0.01
  
              if self.debug:
                  self.logger.log_record_run([reward, observation_loss])
  
              return ts.transition(observation = np.array(observation, dtype=np.float32),
                                   reward      = reward,
                                   discount    = 1.0)
code_tokens: def _step ( self , action ) : if self . _episode_ended : return self . reset ( ) action_num = int ( action % len ( self . action_list ) ) action_layer = int ( action / len ( self . action_list ) ) self . _state [ action_layer ] += self . action_list [ action_num ] if self . debug : print ( f'Round {self.round} 薄膜结构: {self._state}, 前序观测: {self.pre_observation}')  if self . save_log : self . logger . log_record_csv ( self . _state ) self . opticalModel . RunSim ( self . _state ) observation_loss = self . opticalModel . simulation_result observation_loss = film_loss ( aim = self . target , weight = self . weight , observation = observation_loss , average = True , debug = self . debug , betterfgood = False ) observation = copy . copy ( self . _state ) observation . append ( observation_loss ) error_structure = False for s in self . _state : if s < 0 : error_structure = True self . _episode_ended = True reach_performance_threshold = False if observation_loss >= self . end_threshold : reach_performance_threshold = True self . _episode_ended = True reach_round_threshold = False if self . round >= self . round_threshold : reach_round_threshold = True self . _episode_ended = True if self . _episode_ended : if error_structure : reward = - 1 elif reach_performance_threshold : reward = 1 elif reach_round_threshold : reward = - 0.1 if self . debug : self . logger . log_record_run ( [ reward , observation_loss ] ) return ts . termination ( observation = np . array ( observation , dtype = np . float32 ) , reward = reward ) elif observation_loss < self . pre_observation : reward = ( self . pre_observation - observation_loss ) * 100 self . pre_observation = min ( observation_loss , self . pre_observation ) self . round = 0 if self . debug : self . logger . log_record_run ( [ reward , observation_loss ] ) return ts . transition ( observation = np . array ( observation , dtype = np . float32 ) , reward = reward , discount = 1.0 ) else : self . round += 1 reward = - 0.01 if self . debug : self . logger . log_record_run ( [ reward , observation_loss ] ) return ts . transition ( observation = np . array ( observation , dtype = np . float32 ) , reward = reward , discount = 1.0 )
short_docstring: Apply action and return new time_step.
short_docstring_tokens: Apply action and return new time_step .
comment: """Apply action and return new time_step."""$SEP$# 计算action$SEP$# print(f'仿真的状态:{self._state}')$SEP$# 计算observation$SEP$#print(self._state, observation)$SEP$# print(observation)$SEP$# Exit Rule I: Exit Env When Structure Out of Bound.$SEP$# Exit Rule II: Exit Env When Film Satisfied Aim Performance.$SEP$# Exit Rule III: Exit Env When Film not Prove in Threshold Round.$SEP$# Exit Term$SEP$# 更新条件