def get_repo(path: Optional[str] = None, experiment_name: Optional[str] = None) -> AimRepo: # Auto commit if os.getenv(AIM_AUTOMATED_EXEC_ENV_VAR): # Get Aim environment variables branch_name = os.getenv(AIM_BRANCH_ENV_VAR) commit_hash = os.getenv(AIM_COMMIT_ENV_VAR) else: commit_hash = AimRepo.generate_commit_hash() if experiment_name is not None: branch_name = experiment_name else: # FIXME: Get active experiment name from given repo # if path is specified. Currently active experiment name of # the highest repo in the hierarchy will be returned. branch_name = AimRepo.get_active_branch_if_exists() \ or AIM_DEFAULT_BRANCH_NAME if path is not None: repo = AimRepo(path) if not repo.exists(): if not repo.init(): raise ValueError('can not create repo `{}`'.format(path)) repo = AimRepo(path, branch_name, commit_hash) else: if AimRepo.get_working_repo() is None: path = os.getcwd() repo = AimRepo(path) if not repo.init(): raise ValueError('can not create repo `{}`'.format(path)) repo = AimRepo(path, branch_name, commit_hash) else: repo = AimRepo.get_working_repo(branch_name, commit_hash) return repo
def init(): """ Initializes new repository in the current working directory: - Creates .aim directory - Adds .aim/config.json file with initial configuration """ repo = AimRepo(os.getcwd()) re_init = False # Check whether repo already exists if repo.exists(): re_init = click.confirm('Aim repository is already initialized. ' + 'Do you want to re-initialize it?') if not re_init: return # Clear old repo repo.rm() # Init repo new_repo = AimRepo(os.getcwd()) if new_repo.init(): if re_init: click.echo( 'Re-initialized empty Aim repository at {}'.format(new_repo)) else: click.echo(('Initialized a new ' + 'Aim repository at {}').format(new_repo))
class Project: DEFAULT_PROJECT_NAME = 'Project' DEFAULT_PROJECT_PATH = '/project' REPO_PATH = '/store' def __init__(self): self.name = os.getenv('PROJECT_NAME') or self.DEFAULT_PROJECT_NAME self.path = os.getenv('PROJECT_PATH') or self.DEFAULT_PROJECT_PATH self.description = '' self.tf_enabled = TFSummaryAdapter.exists() self.repo = AimRepo(repo_full_path=self.REPO_PATH, mode=AimRepo.READING_MODE) def exists(self): return self.repo and self.repo.exists()
def down(repo_inst, repo): check_docker_dependency() repo_path = clean_repo_path(repo) if repo_path: repo_inst = AimRepo(repo_path) if repo_inst is None or not repo_inst.exists(): repo_init_alert() return # Kill all identical running containers cont = AimContainer(repo_inst) if cont.get_container() is not None: click.echo('Shutting down Aim UI at `{}`'.format(repo_inst.path)) cont.kill() click.echo('Done') else: click.echo('No running Aim UI at `{}`'.format(repo_inst.path))
def init(): repo = AimRepo(os.getcwd()) re_init = False # Check whether repo already exists if repo.exists(): re_init = click.confirm('Aim repository is already initialized. ' + 'Do you want to re-initialize it?') if not re_init: return # Clear old repo repo.rm() # Init repo new_repo = AimRepo(os.getcwd()) if new_repo.init(): if re_init: click.echo( 'Re-initialized empty Aim repository in {}'.format(new_repo)) else: click.echo(('Initialized empty ' + 'Aim repository in {}').format(new_repo))
class Project: DEFAULT_PROJECT_NAME = 'Project' DEFAULT_PROJECT_PATH = '/project' REPO_PATH = '/store' def __init__(self): self.name = os.getenv('PROJECT_NAME') or self.DEFAULT_PROJECT_NAME self.path = os.getenv('PROJECT_PATH') or self.DEFAULT_PROJECT_PATH self.description = '' self.tf_enabled = TFSummaryAdapter.exists() self.repo = AimRepo(repo_full_path=self.REPO_PATH, mode=AimRepo.READING_MODE) def exists(self): return self.repo and self.repo.exists() def get_run_config(self, experiment_name, run_hash): config_file_path = os.path.join(self.repo.path, experiment_name, run_hash) config_file_path = os.path.join(config_file_path, AIM_COMMIT_CONFIG_FILE_NAME) if not os.path.isfile(config_file_path): return None with open(config_file_path, 'r+') as config_file: try: configs = json.loads(config_file.read()) except: configs = None return configs def get_modified_runs(self, last_modified=0): updated_runs = {} if not self.repo: return updated_runs experiments = self.repo.list_branches() for experiment in experiments: runs = self.repo.list_branch_commits(experiment) for run in runs: run_path = os.path.join(self.repo.path, experiment, run) run_config_path = os.path.join(run_path, AIM_COMMIT_CONFIG_FILE_NAME) if not os.path.exists(run_config_path): continue run_config_path = Path(run_config_path) if not run_config_path or not run_config_path.exists(): continue run_stats = run_config_path.stat() if not run_stats: continue modified_time = run_config_path.stat().st_mtime if not modified_time or modified_time > last_modified: updated_runs.setdefault(experiment, []) updated_runs[experiment].append((run, modified_time)) return updated_runs
def up(repo_inst, dev, host, port, version, repo, tf_logs, detach): check_docker_dependency() repo_path = clean_repo_path(repo) if repo_path: repo_inst = AimRepo(repo_path) if repo_inst is None or not repo_inst.exists(): repo_init_alert() return # Dev param # 0 => pull and run official image of container # 1 => run production build from local environment # 2 => run in development mode cont = AimContainer(repo_inst, dev=bool(dev)) if tf_logs: cont.mount_volume(tf_logs, AIM_TF_LOGS_PATH) if os.getenv(AIM_CONTAINER_TELEMETRY_FLAG) is not None \ and os.getenv(AIM_CONTAINER_TELEMETRY_FLAG) == '0': cont.turn_telemetry_off() else: cont.turn_telemetry_on() alert_msg = 'Aim UI collects anonymous usage analytics.' opt_out_msg = 'Read how to opt-out here: ' opt_out_url = 'https://github.com/aimhubio/aim#anonymized-telemetry' line_width = max(len(opt_out_msg), len(alert_msg)) + 16 click.echo('┌{}┐'.format('-' * (line_width - 2))) click.echo('{}{}{}'.format(' ' * ((line_width - len(alert_msg)) // 2), alert_msg, ' ' * ((line_width - len(alert_msg)) // 2))) click.echo('{}{}{}'.format( ' ' * ((line_width - len(opt_out_msg)) // 2), opt_out_msg, ' ' * ((line_width - len(opt_out_msg)) // 2))) click.echo('{}{}{}'.format( ' ' * ((line_width - len(opt_out_url)) // 2), opt_out_url, ' ' * ((line_width - len(opt_out_url)) // 2))) click.echo('└{}┘'.format('-' * (line_width - 2))) click.echo( click.style('Running Aim UI on repo `{}`'.format(repo_inst), fg='yellow')) # Check if image exist if dev == 0 and not cont.image_exist(version): click.echo('Pulling Aim UI docker image, please wait...') if not cont.pull(version): docker_image_pull_fail_alert() return else: click.echo('Successfully pulled Aim UI image') if cont.get_container(running_only=True): kill = click.confirm('Aim UI is already running. ' + 'Do you want to restart it?') if not kill: return # Kill all identical running containers cont.kill() # if dev < 2 # cont.bind(port + 1, AIM_CONTAINER_CMD_PORT) cont_id = cont.up(port, host, version) if not cont_id: click.echo('Failed to run Aim UI. Please try again.') return # cont_cmd = AimContainerCommandManager((port + 1) if dev < 2 # else AIM_CONTAINER_CMD_PORT) # cont_cmd.listen() # Kill container after keyboard interruption def graceful_shutdown(): # cont_cmd.kill() click.echo('') click.echo('Shutting down...') try: cont.kill() except Exception: pass click.echo('Done') sys.exit(0) # Add keyboard signal interruption listener # signal.signal(signal.SIGINT, graceful_shutdown) # signal.pause() try: sleep(4) click.echo('Open http://{}:{}'.format(host, port)) if not detach: click.echo('Press Ctrl+C to exit') while True: if cont.get_container() is not None: sleep(0.3) else: click.echo('Exited') return except KeyboardInterrupt: graceful_shutdown() sys.exit(0)
def up(repo_inst, dev, host, port, version, repo, tf_logs, detach): check_docker_dependency() repo_path = clean_repo_path(repo) if repo_path: repo_inst = AimRepo(repo_path) if repo_inst is None or not repo_inst.exists(): repo_init_alert() return # Dev param # 0 => pull and run official image of container # 1 => run production build from local environment # 2 => run in development mode cont = AimContainer(repo_inst, dev=bool(dev)) if tf_logs: cont.mount_volume(tf_logs, AIM_TF_LOGS_PATH) click.echo( click.style('Running Aim UI on repo `{}`'.format(repo_inst), fg='yellow')) # Check if image exist if dev == 0 and not cont.image_exist(version): click.echo('Pulling Aim UI docker image, please wait...') if not cont.pull(version): docker_image_pull_fail_alert() return else: click.echo('Successfully pulled Aim UI image') if cont.get_container(running_only=True): kill = click.confirm('Aim UI is already running. ' + 'Do you want to restart it?') if not kill: return # Kill all identical running containers cont.kill() # if dev < 2 # cont.bind(port + 1, AIM_CONTAINER_CMD_PORT) cont_id = cont.up(port, host, version) if not cont_id: click.echo('Failed to run Aim UI. Please try again.') return # cont_cmd = AimContainerCommandManager((port + 1) if dev < 2 # else AIM_CONTAINER_CMD_PORT) # cont_cmd.listen() # Kill container after keyboard interruption def graceful_shutdown(): # cont_cmd.kill() click.echo('') click.echo('Shutting down...') try: cont.kill() except Exception: pass click.echo('Done') sys.exit(0) # Add keyboard signal interruption listener # signal.signal(signal.SIGINT, graceful_shutdown) # signal.pause() try: sleep(4) click.echo('Open http://{}:{}'.format(host, port)) if not detach: click.echo('Press Ctrl+C to exit') while True: if cont.get_container() is not None: sleep(0.3) else: click.echo('Exited') return except KeyboardInterrupt: graceful_shutdown() sys.exit(0)