def reindex(repo, finalize_only): """ Process runs left in 'in progress' state. """ repo_path = clean_repo_path(repo) or Repo.default_repo_path() repo_status = Repo.check_repo_status(repo_path) if repo_status != RepoStatus.UPDATED: click.echo(f'\'{repo_path}\' is not updated. Cannot run indexing.') repo_inst = Repo.from_path(repo_path) runs_in_progress_dir = os.path.join(repo_inst.path, 'meta', 'progress') runs_in_progress = set(os.listdir(runs_in_progress_dir)) if finalize_only: if not runs_in_progress: click.echo('Index is up to date.') return confirmed = click.confirm(f'This command will try to finalize all pending runs in aim repo located at ' f'\'{repo_path}\'. Do you want to proceed?') if not confirmed: return else: confirmed = click.confirm(f'This command will try to reindex all runs in aim repo located at ' f'\'{repo_path}\'. This process might take a while. Do you want to proceed?') if not confirmed: return finalize_stalled_runs(repo_inst, runs=runs_in_progress) if not finalize_only: run_flushes_and_compactions(repo_inst, runs_to_skip=runs_in_progress)
def server(host, port, workers, repo, ssl_keyfile, ssl_certfile): # TODO [MV, AT] remove code duplication with aim up cmd implementation repo_path = clean_repo_path(repo) or Repo.default_repo_path() repo_status = Repo.check_repo_status(repo_path) if repo_status == RepoStatus.MISSING: init_repo = click.confirm( f'\'{repo_path}\' is not a valid Aim repository. Do you want to initialize it?' ) if not init_repo: click.echo('To initialize repo please run the following command:') click.secho('aim init', fg='yellow') return repo_inst = Repo.from_path(repo_path, init=True) elif repo_status == RepoStatus.UPDATE_REQUIRED: upgrade_repo = click.confirm( f'\'{repo_path}\' requires upgrade. Do you want to run upgrade automatically?' ) if upgrade_repo: from aim.cli.upgrade.utils import convert_2to3 repo_inst = convert_2to3(repo_path, drop_existing=False, skip_failed_runs=False, skip_checks=False) else: click.echo('To upgrade repo please run the following command:') click.secho(f'aim upgrade --repo {repo_path} 2to3', fg='yellow') return else: repo_inst = Repo.from_path(repo_path) if repo_status == RepoStatus.PATCH_REQUIRED: repo_inst.structured_db.run_upgrades() os.environ[AIM_SERVER_MOUNTED_REPO_PATH] = repo_inst.path click.echo( click.style('Running Aim Server on repo `{}`'.format(repo_inst), fg='yellow')) click.echo('Server is mounted on {}:{}'.format(host, port), err=True) click.echo('Press Ctrl+C to exit') try: run_server(host, port, workers, ssl_keyfile, ssl_certfile) except Exception: click.echo('Failed to run Aim Tracking Server. ' 'Please see the logs for details.') return
def _set_repo(self, repo): if repo is None: from aim.sdk.repo import Repo repo = Repo.default_repo_path() if isinstance(repo, str): from aim.sdk.repo import Repo, RepoStatus repo_status = Repo.check_repo_status(repo) if repo_status == RepoStatus.UPDATE_REQUIRED: logger.error( f'Trying to start Run on repository {repo}, which is out of date. ' f'Please upgrade repository with the following command: ' f'`aim upgrade --repo {repo} 2to3`.') raise RuntimeError() elif repo_status == RepoStatus.MISSING: repo = Repo.from_path(repo, init=True) else: repo = Repo.from_path(repo) self.repo = repo
def up(dev, host, port, workers, repo, tf_logs, ssl_keyfile, ssl_certfile, base_path, force_init): if dev: os.environ[AIM_ENV_MODE_KEY] = 'dev' else: os.environ[AIM_ENV_MODE_KEY] = 'prod' if base_path: # process `base_path` as ui requires leading slash if base_path.endswith('/'): base_path = base_path[:-1] if base_path and not base_path.startswith('/'): base_path = f'/{base_path}' os.environ[AIM_UI_BASE_PATH] = base_path repo_path = clean_repo_path(repo) or Repo.default_repo_path() repo_status = Repo.check_repo_status(repo_path) if repo_status == RepoStatus.MISSING: init_repo = None if not force_init: init_repo = click.confirm( f'\'{repo_path}\' is not a valid Aim repository. Do you want to initialize it?' ) else: init_repo = True if not init_repo: click.echo('To initialize repo please run the following command:') click.secho('aim init', fg='yellow') return repo_inst = Repo.from_path(repo_path, init=True) elif repo_status == RepoStatus.UPDATE_REQUIRED: upgrade_repo = click.confirm( f'\'{repo_path}\' requires upgrade. Do you want to run upgrade automatically?' ) if upgrade_repo: from aim.cli.upgrade.utils import convert_2to3 repo_inst = convert_2to3(repo_path, drop_existing=False, skip_failed_runs=False, skip_checks=False) else: click.echo('To upgrade repo please run the following command:') click.secho(f'aim upgrade --repo {repo_path} 2to3', fg='yellow') return else: repo_inst = Repo.from_path(repo_path) if repo_status == RepoStatus.PATCH_REQUIRED: repo_inst.structured_db.run_upgrades() os.environ[AIM_UI_MOUNTED_REPO_PATH] = repo_inst.path if tf_logs: os.environ[AIM_TF_LOGS_PATH_KEY] = tf_logs try: db_cmd = build_db_upgrade_command() exec_cmd(db_cmd, stream_output=True) except ShellCommandException: click.echo('Failed to initialize Aim DB. ' 'Please see the logs above for details.') return if dev or (os.getenv(AIM_UI_TELEMETRY_KEY) is not None and os.getenv(AIM_UI_TELEMETRY_KEY) == '0'): os.environ[AIM_UI_TELEMETRY_KEY] = '0' else: os.environ[AIM_UI_TELEMETRY_KEY] = '1' alert_msg = 'Aim UI collects anonymous usage analytics.' opt_out_msg = 'Read how to opt-out here: ' opt_out_url = 'https://aimstack.readthedocs.io/en/latest/community/telemetry.html' line_width = max(len(opt_out_msg), len(alert_msg), len(opt_out_url)) + 8 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')) scheme = 'https' if ssl_keyfile or ssl_certfile else 'http' click.echo('Open {}://{}:{}{}'.format(scheme, host, port, base_path), err=True) click.echo('Press Ctrl+C to exit') try: server_cmd = build_uvicorn_command(host, port, workers, ssl_keyfile, ssl_certfile) exec_cmd(server_cmd, stream_output=True) except ShellCommandException: click.echo('Failed to run Aim UI. ' 'Please see the logs above for details.') return