def branch(self, branch): self._branch = branch if self._branch not in self.list_branches(): self.create_branch(self._branch) self.branch_path = get_experiment_path(self.path, self._branch) self.index_path = get_experiment_run_path(self.path, self._branch, self.active_commit) self.objects_dir_path = get_run_objects_dir_path(self.path, self._branch, self.active_commit) self.media_dir_path = os.path.join(self.objects_dir_path, AIM_MEDIA_DIR_NAME) self.meta_file_content = None self.meta_file_path = get_run_objects_meta_file_path(self.path, self._branch, self.active_commit) if not os.path.isdir(self.index_path): os.makedirs(self.index_path) if self.records_storage: self.records_storage.close() if os.path.exists(self.branch_path): self.records_storage = self.get_records_storage( self.objects_dir_path, self.mode)
def __init__(self, path=None, repo_branch=None, repo_commit=None, repo_full_path=None, mode=WRITING_MODE): self._config = {} path = clean_repo_path(path) self.path = repo_full_path or os.path.join(path, AIM_REPO_NAME) self.config_path = os.path.join(self.path, AIM_CONFIG_FILE_NAME) self.hash = hashlib.md5(self.path.encode('utf-8')).hexdigest() self.active_commit = repo_commit or AIM_COMMIT_INDEX_DIR_NAME if re.match(r'^[A-Za-z0-9_\-]{2,}$', self.active_commit) is None: raise ValueError('run name must be at least 2 characters ' + 'and contain only latin letters, numbers, ' + 'dash and underscore') self.root_path = repo_full_path or path self.name = self.root_path.split(os.sep)[-1] self.branch_path = None self.index_path = None self.objects_dir_path = None self.media_dir_path = None self.records_storage = None self.mode = mode active_exp = self.config.get('active_branch') if repo_branch is not None: experiment = repo_branch elif active_exp is not None: experiment = active_exp else: experiment = None if experiment is not None: run_full_path = get_experiment_run_path(self.path, experiment, self.active_commit) else: run_full_path = None if self.active_commit != AIM_COMMIT_INDEX_DIR_NAME and run_full_path \ and os.path.exists(run_full_path): raise ValueError( ('run `{}` already exists' + '').format(self.active_commit)) if experiment is not None: self.branch = experiment
def is_archived(self, experiment_name: str, run_hash: str) -> Optional[bool]: run_dir_path = get_experiment_run_path(self.path, experiment_name, run_hash) config_file_path = os.path.join(run_dir_path, AIM_COMMIT_CONFIG_FILE_NAME) if not os.path.exists(config_file_path): return None with open(config_file_path, 'r') as config_file: try: config = json.loads(config_file.read()) except: return None return config.get('archived')
def _toggle_archive_flag(self, experiment_name: str, run_hash: str, flag: bool) -> bool: run_dir_path = get_experiment_run_path(self.path, experiment_name, run_hash) config_file_path = os.path.join(run_dir_path, AIM_COMMIT_CONFIG_FILE_NAME) with open(config_file_path, 'r') as config_file: try: config = json.loads(config_file.read()) except: return False config['archived'] = flag with open(config_file_path, 'w') as config_file: try: config_file.write(json.dumps(config)) except: return False return True