original_docstring: r"""Saves an agent state. Raises an error if the directory exists and 
      overwrite=False. Saves all further results like losses and accuracies as
      .npy files.
      
docstring: r"""Saves an agent state. Raises an error if the directory exists and
  overwrite=False. Saves all further results like losses and accuracies as
  .npy files.
docstring_tokens: r " " " Saves an agent state . Raises an error if the directory exists and overwrite = False . Saves all further results like losses and accuracies as . npy files .
code: def save_state(self, states_path, state_name, optimizer=None, overwrite=False,
                 losses_train=None, losses_cum_train=None, losses_val=None, 
                 losses_cum_val=None, accuracy_train=None, accuracy_det_train=None,
                 accuracy_val=None, accuracy_det_val=None):
      r"""Saves an agent state. Raises an error if the directory exists and 
      overwrite=False. Saves all further results like losses and accuracies as
      .npy files.
      """
      if states_path is not None:
          state_full_path = os.path.join(states_path, state_name)
          if os.path.exists(state_full_path):
              if not overwrite:
                  raise FileExistsError
              shutil.rmtree(state_full_path)
          os.makedirs(state_full_path)
          save_model_state(self.model, 'model_state_dict', state_full_path)
          pkl_dump(self.agent_state_dict, 'agent_state_dict', state_full_path)
          if optimizer is not None:
              save_optimizer_state(optimizer, 'optimizer', state_full_path)
          if losses_train is not None and len(losses_train) != 0:
              np.save(os.path.join(state_full_path, 'losses_train.npy'), np.array(losses_train))
          if losses_cum_train is not None and len(losses_cum_train) != 0:
              np.save(os.path.join(state_full_path, 'losses_cum_train.npy'), np.array(losses_cum_train))
          if losses_val is not None and len(losses_val) != 0:
              np.save(os.path.join(state_full_path, 'losses_validation.npy'), np.array(losses_val))
          if losses_cum_val is not None and len(losses_cum_val) != 0:
              np.save(os.path.join(state_full_path, 'losses_cum_validation.npy'), np.array(losses_cum_val))
          if accuracy_train is not None and len(accuracy_train) != 0:
              np.save(os.path.join(state_full_path, 'accuracy_train.npy'), np.array(accuracy_train))
          if accuracy_det_train is not None and len(accuracy_det_train) != 0:
              np.save(os.path.join(state_full_path, 'accuracy_detailed_train.npy'), np.array(accuracy_det_train))
          if accuracy_val is not None and len(accuracy_val) != 0:
              np.save(os.path.join(state_full_path, 'accuracy_validation.npy'), np.array(accuracy_val))
          if accuracy_det_val is not None and len(accuracy_det_val) != 0:
              np.save(os.path.join(state_full_path, 'accuracy_detailed_validation.npy'), np.array(accuracy_det_val))
code_tokens: def save_state ( self , states_path , state_name , optimizer = None , overwrite = False , losses_train = None , losses_cum_train = None , losses_val = None , losses_cum_val = None , accuracy_train = None , accuracy_det_train = None , accuracy_val = None , accuracy_det_val = None ) : if states_path is not None : state_full_path = os . path . join ( states_path , state_name ) if os . path . exists ( state_full_path ) : if not overwrite : raise FileExistsError shutil . rmtree ( state_full_path ) os . makedirs ( state_full_path ) save_model_state ( self . model , 'model_state_dict' , state_full_path ) pkl_dump ( self . agent_state_dict , 'agent_state_dict' , state_full_path ) if optimizer is not None : save_optimizer_state ( optimizer , 'optimizer' , state_full_path ) if losses_train is not None and len ( losses_train ) != 0 : np . save ( os . path . join ( state_full_path , 'losses_train.npy' ) , np . array ( losses_train ) ) if losses_cum_train is not None and len ( losses_cum_train ) != 0 : np . save ( os . path . join ( state_full_path , 'losses_cum_train.npy' ) , np . array ( losses_cum_train ) ) if losses_val is not None and len ( losses_val ) != 0 : np . save ( os . path . join ( state_full_path , 'losses_validation.npy' ) , np . array ( losses_val ) ) if losses_cum_val is not None and len ( losses_cum_val ) != 0 : np . save ( os . path . join ( state_full_path , 'losses_cum_validation.npy' ) , np . array ( losses_cum_val ) ) if accuracy_train is not None and len ( accuracy_train ) != 0 : np . save ( os . path . join ( state_full_path , 'accuracy_train.npy' ) , np . array ( accuracy_train ) ) if accuracy_det_train is not None and len ( accuracy_det_train ) != 0 : np . save ( os . path . join ( state_full_path , 'accuracy_detailed_train.npy' ) , np . array ( accuracy_det_train ) ) if accuracy_val is not None and len ( accuracy_val ) != 0 : np . save ( os . path . join ( state_full_path , 'accuracy_validation.npy' ) , np . array ( accuracy_val ) ) if accuracy_det_val is not None and len ( accuracy_det_val ) != 0 : np . save ( os . path . join ( state_full_path , 'accuracy_detailed_validation.npy' ) , np . array ( accuracy_det_val ) )
short_docstring: r"""Saves an agent state.
short_docstring_tokens: r " " " Saves an agent state .
comment: r"""Saves an agent state. Raises an error if the directory exists and 
      overwrite=False. Saves all further results like losses and accuracies as
      .npy files.
      """