original_docstring: r"""Tries to restore a previous agent state, consisting of a model 
      state and the content of agent_state_dict. Returns whether the restore 
      operation  was successful. Further the results will be loaded as well,
      i.e. losses and accuracies.
      
docstring: r"""Tries to restore a previous agent state, consisting of a model
  state and the content of agent_state_dict. Returns whether the restore
  operation  was successful. Further the results will be loaded as well,
  i.e. losses and accuracies.
docstring_tokens: r " " " Tries to restore a previous agent state consisting of a model state and the content of agent_state_dict . Returns whether the restore operation was successful . Further the results will be loaded as well i . e . losses and accuracies .
code: def restore_state(self, states_path, state_name, optimizer=None):
      r"""Tries to restore a previous agent state, consisting of a model 
      state and the content of agent_state_dict. Returns whether the restore 
      operation  was successful. Further the results will be loaded as well,
      i.e. losses and accuracies.
      """
      state_full_path = os.path.join(states_path, state_name)
      try:
          correct_load = load_model_state(self.model, 'model_state_dict', state_full_path, device=self.device)
          assert correct_load
          agent_state_dict = pkl_load('agent_state_dict', state_full_path)
          assert agent_state_dict is not None
          self.agent_state_dict = agent_state_dict
          if optimizer is not None:
              load_optimizer_state(optimizer, 'optimizer', state_full_path, device=self.device)
          if self.verbose:
              print('State {} was restored'.format(state_name))
          print("Loading model state dict was successful.")
          files = ['losses_train.npy', 'losses_cum_train.npy', 'losses_validation.npy', 'losses_cum_validation.npy',\
                   'accuracy_train.npy', 'accuracy_detailed_train.npy', 'accuracy_validation.npy', 'accuracy_detailed_validation.npy']
          results = list()
          for i in files:
              try:
                  # Load the file
                  obj = np.load(os.path.join(state_full_path, i), allow_pickle=True)
              except FileNotFoundError:
                  # If it does not exist, the user has decided not to store unnecessary results
                  obj = None
              results.append(obj)
          print("Loading losses and accuracies was succesful.")
          return True, results
      except:
          print('State {} could not be restored'.format(state_name))
          return False, None
code_tokens: def restore_state ( self , states_path , state_name , optimizer = None ) : state_full_path = os . path . join ( states_path , state_name ) try : correct_load = load_model_state ( self . model , 'model_state_dict' , state_full_path , device = self . device ) assert correct_load agent_state_dict = pkl_load ( 'agent_state_dict' , state_full_path ) assert agent_state_dict is not None self . agent_state_dict = agent_state_dict if optimizer is not None : load_optimizer_state ( optimizer , 'optimizer' , state_full_path , device = self . device ) if self . verbose : print ( 'State {} was restored' . format ( state_name ) ) print ( "Loading model state dict was successful." ) files = [ 'losses_train.npy' , 'losses_cum_train.npy' , 'losses_validation.npy' , 'losses_cum_validation.npy' , 'accuracy_train.npy' , 'accuracy_detailed_train.npy' , 'accuracy_validation.npy' , 'accuracy_detailed_validation.npy' ] results = list ( ) for i in files : try : obj = np . load ( os . path . join ( state_full_path , i ) , allow_pickle = True ) except FileNotFoundError : obj = None results . append ( obj ) print ( "Loading losses and accuracies was succesful." ) return True , results except : print ( 'State {} could not be restored' . format ( state_name ) ) return False , None
short_docstring: r"""Tries to restore a previous agent state, consisting of a model
  state and the content of agent_state_dict.
short_docstring_tokens: r " " " Tries to restore a previous agent state consisting of a model state and the content of agent_state_dict .
comment: r"""Tries to restore a previous agent state, consisting of a model 
      state and the content of agent_state_dict. Returns whether the restore 
      operation  was successful. Further the results will be loaded as well,
      i.e. losses and accuracies.
      """$SEP$# Load the file$SEP$# If it does not exist, the user has decided not to store unnecessary results