Пример #1
0
def get(project):
    """Get info for current project, by project_name, or user/project_name.

    Examples:

         To get current project:
    ```
    polyaxon project get
    ```

        To get a project by uuid
    ```
    polyaxon project get user/project
    ```
    """
    user, project_name = get_project_or_local(project)

    try:
        response = PolyaxonClients().project.get_project(user, project_name)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get project `{}`.'.format(project))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    response = response.to_dict()
    Printer.print_header("Project info:")
    dict_tabulate(response)
Пример #2
0
def get(experiment, project):
    """Get experiment by uuid.

    Examples:
    ```
    polyaxon experiment get 1
    ```

    ```
    polyaxon experiment get 1 --project=cats-vs-dogs
    ```

     ```
    polyaxon experiment get 1 --project=alain/cats-vs-dogs
    ```
    """
    user, project_name = get_project_or_local(project)
    try:
        response = PolyaxonClients().experiment.get_experiment(
            user, project_name, experiment)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error(
            'Could not load experiment `{}` info.'.format(experiment))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    response = response.to_dict()
    Printer.print_header("Experiment info:")
    dict_tabulate(response)
Пример #3
0
def version(cli, platform):
    """Print the current version of the cli and platform."""
    version_client = PolyaxonClients().version
    cli = cli or not any([cli, platform])
    if cli:
        try:
            server_version = version_client.get_cli_version()
        except AuthorizationError:
            session_expired()
            sys.exit(1)
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not get cli version.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
        cli_version = get_version(PROJECT_CLI_NAME)
        Printer.print_header('Current cli version: {}.'.format(cli_version))
        Printer.print_header('Supported cli versions:')
        dict_tabulate(server_version.to_dict())

    if platform:
        try:
            platform_version = version_client.get_platform_version()
        except AuthorizationError:
            session_expired()
            sys.exit(1)
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not get platform version.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
        chart_version = version_client.get_chart_version()
        Printer.print_header('Current platform version: {}.'.format(
            chart_version.version))
        Printer.print_header('Supported platform versions:')
        dict_tabulate(platform_version.to_dict())
Пример #4
0
def update(group, project, description):
    """Update experiement group.

    Example:

    ```
    polyaxon group update 2 --description="new description for my experiments"
    ```
    """
    user, project_name = get_project_or_local(project)
    update_dict = {}

    if description:
        update_dict['description'] = description

    if not update_dict:
        Printer.print_warning(
            'No argument was provided to update the experiment group.')
        sys.exit(0)

    try:
        response = PolyaxonClients().experiment_group.update_experiment_group(
            user, project_name, group, update_dict)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error(
            'Could not update experiment group `{}`.'.format(group))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    Printer.print_success("Experiment group updated.")
    response = response.to_dict()
    Printer.print_header("Experiment group info:")
    dict_tabulate(response)
Пример #5
0
def whoami():
    """Show current logged Polyaxon user."""
    try:
        user = PolyaxonClients().auth.get_user()
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not load user info.')
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)
    click.echo(
        "\nUsername: {username}, Email: {email}\n".format(**user.to_dict()))
Пример #6
0
def restart(experiment, project):
    """Delete experiment group."""
    user, project_name = get_project_or_local(project)
    try:
        response = PolyaxonClients().experiment.restart(
            user, project_name, experiment)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error(
            'Could not restart experiment `{}`.'.format(experiment))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    response = response.to_dict()
    Printer.print_header("Experiment info:")
    dict_tabulate(response)
Пример #7
0
def update(ctx, description):
    """Update experiment group.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Example:

    \b
    ```bash
    $ polyaxon group -g 2 update --description="new description for my experiments"
    ```
    """
    user, project_name, _group = get_group_or_local(ctx.obj['project'], ctx.obj['group'])
    update_dict = {}

    if description:
        update_dict['description'] = description

    if not update_dict:
        Printer.print_warning('No argument was provided to update the experiment group.')
        sys.exit(0)

    try:
        response = PolyaxonClients().experiment_group.update_experiment_group(
            user, project_name, _group, update_dict)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not update experiment group `{}`.'.format(_group))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    Printer.print_success("Experiment group updated.")
    get_group_details(response)
Пример #8
0
def check_cli_version():
    """Check if the current cli version satisfies the server requirements"""
    try:
        server_version = PolyaxonClients().version.get_cli_version()
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get cli version.')
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    current_version = pkg_resources.get_distribution(PROJECT_CLI_NAME).version
    if LooseVersion(current_version) < LooseVersion(
            server_version.min_version):
        click.echo(
            """Your version of CLI ({}) is no longer compatible with server."""
            .format(current_version))
        if click.confirm("Do you want to upgrade to "
                         "version {} now?".format(
                             server_version.latest_version)):
            pip_upgrade()
            sys.exit(0)
        else:
            clint.textui.puts("Your can manually run:")
            with clint.textui.indent(4):
                clint.textui.puts("pip install -U polyaxon-cli")
            clint.textui.puts("to upgrade to the latest version `{}`".format(
                server_version.latest_version))

            sys.exit(0)
    elif LooseVersion(current_version) < LooseVersion(
            server_version.latest_version):
        clint.textui.puts(
            "New version of CLI ({}) is now available. To upgrade run:".format(
                server_version.latest_version))
        with clint.textui.indent(4):
            clint.textui.puts("pip install -U polyaxon-cli")
Пример #9
0
def resources(ctx, gpu):
    """Get experiment resources.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Example:

    \b
    ```bash
    $ polyaxon experiment -xp 19 resources
    ```

    For GPU resources

    \b
    ```bash
    $ polyaxon experiment -xp 19 resources --gpu
    ```
    """
    user, project_name, _experiment = get_experiment_or_local(ctx.obj['project'],
                                                              ctx.obj['experiment'])
    try:
        message_handler = Printer.gpu_resources if gpu else Printer.resources
        PolyaxonClients().experiment.resources(
            user, project_name, _experiment, message_handler=message_handler)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get resources for experiment `{}`.'.format(_experiment))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)
Пример #10
0
def resume(ctx, file, u):  # pylint:disable=redefined-builtin
    """Resume experiment.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Examples:

    \b
    ```bash
    $ polyaxon experiment --experiment=1 resume
    ```
    """
    config = None
    update_code = None
    if file:
        config = reader.read(file)

    # Check if we need to upload
    if u:
        ctx.invoke(upload, async=False)
        update_code = True

    user, project_name, _experiment = get_experiment_or_local(ctx.obj['project'],
                                                              ctx.obj['experiment'])
    try:
        response = PolyaxonClients().experiment.resume(
            user, project_name, _experiment, config=config, update_code=update_code)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not resume experiment `{}`.'.format(_experiment))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    get_experiment_details(response)
Пример #11
0
def delete(ctx):
    """Delete experiment.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Example:

    \b
    ```bash
    $ polyaxon experiment delete
    ```
    """
    user, project_name, _experiment = get_experiment_or_local(ctx.obj['project'],
                                                              ctx.obj['experiment'])
    if not click.confirm("Are sure you want to delete experiment `{}`".format(_experiment)):
        click.echo('Existing without deleting experiment.')
        sys.exit(1)

    try:
        response = PolyaxonClients().experiment.delete_experiment(
            user, project_name, _experiment)
        # Purge caching
        ExperimentManager.purge()
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not delete experiment `{}`.'.format(_experiment))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    if response.status_code == 204:
        Printer.print_success("Experiment `{}` was delete successfully".format(_experiment))
Пример #12
0
def list(page):
    """List projects."""
    user = AuthConfigManager.get_value('username')
    if not user:
        Printer.print_error('Please login first. `polyaxon login --help`')

    page = page or 1
    try:
        response = PolyaxonClients().project.list_projects(user, page=page)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get list of projects.')
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header('Projects for current user')
        Printer.print_header('Navigation:')
        dict_tabulate(meta)
    else:
        Printer.print_header('No projects found for current user')

    objects = list_dicts_to_tabulate(
        [o.to_dict() for o in response['results']])
    if objects:
        Printer.print_header("Projects:")
        dict_tabulate(objects, is_list_dict=True)
Пример #13
0
def experiments(ctx, page, metrics):
    """List experiments for this experiment group

    Uses [Caching](/polyaxon_cli/introduction#Caching)
    """
    user, project_name, _group = get_group_or_local(ctx.obj['project'], ctx.obj['group'])
    page = page or 1
    try:
        response = PolyaxonClients().experiment_group.list_experiments(
            user, project_name, _group, page=page)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get experiments for group `{}`.'.format(_group))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header('Experiments for experiment group `{}`.'.format(_group))
        Printer.print_header('Navigation:')
        dict_tabulate(meta)
    else:
        Printer.print_header('No experiments found for experiment group `{}`.'.format(_group))

    if metrics:
        objects = get_experiments_with_metrics(response)
    else:
        objects = [Printer.add_status_color(o.to_light_dict(humanize_values=True))
                   for o in response['results']]
    objects = list_dicts_to_tabulate(objects)
    if objects:
        Printer.print_header("Experiments:")
        objects.pop('experiment_group', None)
        objects.pop('experiment_group_name', None)
        objects.pop('project_name', None)
        dict_tabulate(objects, is_list_dict=True)
Пример #14
0
def logs(ctx):
    """Get job logs.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Examples:

    \b
    ```bash
    $ polyaxon job -xp 3 -j 2 logs
    ```

    \b
    ```bash
    $ polyaxon job logs
    ```
    """
    user, project_name, experiment, _job = get_job_or_local(
        ctx.obj['project'], ctx.obj['experiment'], ctx.obj['job'])

    def message_handler(log_line):
        Printer.log(log_line['log_line'])

    try:
        PolyaxonClients().job.logs(user,
                                   project_name,
                                   experiment,
                                   _job,
                                   message_handler=message_handler)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get logs for job `{}`.'.format(_job))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)
Пример #15
0
def start(ctx, file):  # pylint:disable=redefined-builtin
    """Start a tensorboard deployment for this project.

    It will show a tensorboard with all experiments under the project.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Example: using the default tensorflow image 1.4.1.

    \b
    ```bash
    $ polyaxon tensorboard start
    ```

    Example: with custom image and resources

    \b
    ```bash
    $ polyaxon tensorboard start -f file -f file_override ...
    ```
    """
    specification = None
    plugin_job = None
    if file:
        specification = check_polyaxonfile(file, log=False).specification

    if specification:
        # pylint:disable=protected-access
        check_polyaxonfile_kind(specification=specification,
                                kind=specification._PLUGIN)
        plugin_job = PluginJobConfig(config=specification.parsed_data)

    user, project_name = get_project_or_local(ctx.obj['project'])
    try:
        response = PolyaxonClients().project.start_tensorboard(
            user, project_name, plugin_job)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error(
            'Could not start tensorboard project `{}`.'.format(project_name))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    if response.status_code == 200:
        Printer.print_header(
            "A notebook for this project is already running on:")
        click.echo(get_tensorboard_url(user, project_name))
        sys.exit(0)

    if response.status_code != 201:
        Printer.print_error(
            'Something went wrong, Tensorboard was not created.')
        sys.exit(1)

    Printer.print_success(
        'Tensorboard is being deployed for project `{}`'.format(project_name))
    clint.textui.puts(
        "It may take some time before you can access tensorboard.\n")
    clint.textui.puts("Your tensorboard will be available on:\n")
    with clint.textui.indent(4):
        clint.textui.puts(get_tensorboard_url(user, project_name))
Пример #16
0
def url(ctx):
    """Prints the tensorboard url for this project.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Example:

    \b
    ```bash
    $ polyaxon tensorboard url
    ```
    """
    user, project_name = get_project_or_local(ctx.obj['project'])
    try:
        response = PolyaxonClients().project.get_project(user, project_name)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get project `{}`.'.format(project_name))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    if response.has_tensorboard:
        click.echo(get_tensorboard_url(user, project_name))
    else:
        Printer.print_warning(
            'This project `{}` does not have a running tensorboard.'.format(
                project_name))
        click.echo(
            'You can start tensorboard with this command: polyaxon tensorboard start'
        )
Пример #17
0
def statuses(experiment, job, project):
    """Get job status.

    Examples:
    ```
    polyaxon job status 50c62372137940ca8c456d8596946dd7
    ```
    """
    user, project_name = get_project_or_local(project)
    try:
        response = PolyaxonClients().job.get_statuses(user, project_name,
                                                      experiment, job)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get status for job `{}`.'.format(job))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header('Statuses for Job `{}`.'.format(job))
        Printer.print_header('Navigation:')
        dict_tabulate(meta)
    else:
        Printer.print_header('No statuses found for job `{}`.'.format(job))

    objects = list_dicts_to_tabulate(
        [o.to_dict() for o in response['results']])
    if objects:
        Printer.print_header("Statuses:")
        objects.pop('job')
        dict_tabulate(objects, is_list_dict=True)
Пример #18
0
def get(ctx):
    """Get experiment group by uuid.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Examples:

    \b
    ```bash
    $ polyaxon group -g 13 get
    ```
    """
    user, project_name, _group = get_group_or_local(ctx.obj['project'], ctx.obj['group'])
    try:
        response = PolyaxonClients().experiment_group.get_experiment_group(
            user, project_name, _group)
        # Set caching only if we have an initialized project
        if ProjectManager.is_initialized():
            GroupManager.set_config(response)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get experiment group `{}`.'.format(_group))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    get_group_details(response)
Пример #19
0
def stop(ctx, yes):
    """Stop experiment.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Examples:

    \b
    ```bash
    $ polyaxon experiment stop
    ```

    \b
    ```bash
    $ polyaxon experiment -xp 2 stop
    ```
    """
    user, project_name, _experiment = get_experiment_or_local(ctx.obj['project'],
                                                              ctx.obj['experiment'])
    if not yes and not click.confirm("Are sure you want to stop "
                                     "experiment `{}`".format(_experiment)):
        click.echo('Existing without stopping experiment.')
        sys.exit(0)

    try:
        PolyaxonClients().experiment.stop(user, project_name, _experiment)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not stop experiment `{}`.'.format(_experiment))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    Printer.print_success("Experiment is being stopped.")
Пример #20
0
def start(ctx, file, u):  # pylint:disable=redefined-builtin
    """Start a notebook deployment for this project.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Example:

    \b
    ```bash
    $ polyaxon notebook start -f file -f file_override ...
    ```

    Example: upload before running

    \b
    ```bash
    $ polyaxon -p user12/mnist notebook start -f file -u
    ```
    """
    specification = None
    plugin_job = None
    if file:
        specification = check_polyaxonfile(file, log=False).specification

    # Check if we need to upload
    if u:
        ctx.invoke(upload, async=False)

    if specification:
        # pylint:disable=protected-access
        check_polyaxonfile_kind(specification=specification,
                                kind=specification._PLUGIN)
        plugin_job = PluginJobConfig(config=specification.parsed_data)
    user, project_name = get_project_or_local(ctx.obj['project'])
    try:
        response = PolyaxonClients().project.start_notebook(
            user, project_name, plugin_job)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error(
            'Could not start notebook project `{}`.'.format(project_name))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    if response.status_code == 200:
        Printer.print_header(
            "A notebook for this project is already running on:")
        click.echo(get_notebook_url(user, project_name))
        sys.exit(0)

    if response.status_code != 201:
        Printer.print_error('Something went wrong, Notebook was not created.')
        sys.exit(1)

    Printer.print_success(
        'Notebook is being deployed for project `{}`'.format(project_name))
    clint.textui.puts(
        "It may take some time before you can access the notebook.\n")
    clint.textui.puts("Your notebook will be available on:\n")
    with clint.textui.indent(4):
        clint.textui.puts(get_notebook_url(user, project_name))
Пример #21
0
def create(name, description):
    """Create a new project.

    Example:

    ```
    polyaxon project create --name=cats-vs-dogs --description=Image Classification with Deep Learning
    ```
    """
    try:
        project_config = ProjectConfig.from_dict(
            dict(name=name, description=description))
    except ValidationError:
        Printer.print_error(
            'Project name should contain only alpha numerical, "-", and "_".')
        sys.exit(1)

    try:
        project = PolyaxonClients().project.create_project(project_config)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not create project `{}`.'.format(name))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    Printer.print_success(
        "Project `{}` was created successfully with uuid `{}`.".format(
            project.name, project.uuid.hex))
Пример #22
0
def experiments(group, project, page):
    """List experiments for this experiment group"""
    user, project_name = get_project_or_local(project)
    page = page or 1
    try:
        response = PolyaxonClients().experiment_group.list_experiments(
            user, project_name, group, page=page)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error(
            'Could not get experiments for group `{}`.'.format(group))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header(
            'Experiments for experiment group `{}`.'.format(group))
        Printer.print_header('Navigation:')
        dict_tabulate(meta)
    else:
        Printer.print_header(
            'No experiments found for experiment group `{}`.'.format(group))

    objects = list_dicts_to_tabulate(
        [o.to_dict() for o in response['results']])
    if objects:
        Printer.print_header("Experiments:")
        objects.pop('group')
        dict_tabulate(objects, is_list_dict=True)
Пример #23
0
def cluster(node):
    """Get cluster and nodes info."""
    cluster_client = PolyaxonClients().cluster
    if node:
        try:
            node_config = cluster_client.get_node(node)
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not load node `{}` info.'.format(node))
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
        get_node_info(node_config)
    else:
        try:
            cluster_config = cluster_client.get_cluster()
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not load cluster info.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
        get_cluster_info(cluster_config)
Пример #24
0
def run(file, description):
    """Command for running polyaxonfile specification.

    Example:

    ```
    polyaxon run -f file -f file_override ...
    ```
    """
    file = file or 'polyaxonfile.yml'
    plx_file = check_polyaxonfile(file)
    num_experiments, concurrency = plx_file.experiments_def
    project = get_current_project_or_exit()
    project_client = PolyaxonClients().project
    if num_experiments == 1:
        click.echo('Creating an independent experiment.')
        experiment = ExperimentConfig(
            description=description,
            content=plx_file._data,
            config=plx_file.experiment_specs[0].parsed_data)
        try:
            response = project_client.create_experiment(
                project.user, project.name, experiment)
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not create experiment.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
        Printer.print_success('Experiment was created')
    else:
        click.echo('Creating an experiment group with {} experiments.'.format(
            num_experiments))
        experiment_group = ExperimentGroupConfig(description=description,
                                                 content=plx_file._data)
        try:
            response = project_client.create_experiment_group(
                project.user, project.name, experiment_group)
            Printer.print_success('Experiment group was created')
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not create experiment group.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
    response = response.to_dict()
    dict_tabulate(response)
Пример #25
0
def get_log_handler():
    try:
        return PolyaxonClients().version.get_log_handler()
    except AuthorizationError:
        session_expired()
        sys.exit(1)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get cli version.')
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)
Пример #26
0
def init(project, run, model):
    """Initialize a new polyaxonfile specification."""
    user, project_name = get_project_or_local(project)
    try:
        project_config = PolyaxonClients().project.get_project(user, project_name)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Make sure you have a project with this name `{}`'.format(project))
        Printer.print_error('You can a new project with this command: '
                            'polyaxon project create --name={} --description=...'.format(project))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    if not any([model, run]) and not all([model, run]):
        Printer.print_error("You must specify which an init option, "
                            "possible values: `--model` or `--run`.")
        sys.exit(1)

    result = False
    if model:
        result = create_init_file(constants.INIT_FILE_MODEL)

    elif run:
        result = create_init_file(constants.INIT_FILE_RUN)

    if result:
        ProjectManager.set_config(project_config, init=True)
        IgnoreManager.init_config()
        Printer.print_success(
            "Project `{}` was initialized and Polyaxonfile was created successfully `{}`".format(
                project, constants.INIT_FILE))
        sys.exit(1)

    # if we are here the file was not created
    if not os.path.isfile(constants.INIT_FILE):
        Printer.print_error(
            "Something went wrong, init command did not create a file.\n"
            "Possible reasons: you don't have the write to create the file.")
        sys.exit(1)

    # file was already there, let's check if the project passed correspond to this file
    try:
        PolyaxonFile(constants.INIT_FILE).specification
    except (PolyaxonfileError, ValidationError) as e:
        Printer.print_error(
            "Something went wrong, init command did not create a file.\n"
            "Another file already exist with.")
        Printer.print_error('Error message: `{}`.'.format(e))
        sys.exit(1)

    # At this point we check if we need to re init configurations
    ProjectManager.set_config(project_config, init=True)
    IgnoreManager.init_config()
    Printer.print_success(
        "Project `{}` was initialized and Polyaxonfile was created successfully `{}`".format(
            project, constants.INIT_FILE))
Пример #27
0
def get(experiment, job, project):
    """Get job by uuid.

    Examples:
    ```
    polyaxon job get 50c62372137940ca8c456d8596946dd7
    ```
    """
    user, project_name = get_project_or_local(project)
    try:
        response = PolyaxonClients().job.get_job(user, project_name,
                                                 experiment, job)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get job `{}`.'.format(job))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    response = response.to_dict()
    Printer.print_header("Job info:")
    dict_tabulate(response)
Пример #28
0
def dashboard(yes, url):
    """Open dashboard in browser."""
    dashboard_url = "{}".format(PolyaxonClients().auth.http_host)
    if url:
        click.echo(dashboard_url)
        sys.exit(0)
    if not yes:
        click.confirm('Dashboard page will now open in your browser. Continue?',
                      abort=True, default=True)

    click.launch(dashboard_url)
Пример #29
0
def get(ctx):
    """Get job.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Examples:

    \b
    ```bash
    $ polyaxon job --job=1 --experiment=1 get
    ```

    \b
    ```bash
    $ polyaxon job --job=1 --project=project_name get
    ```
    """
    user, project_name, experiment, _job = get_job_or_local(
        ctx.obj['project'], ctx.obj['experiment'], ctx.obj['job'])
    try:
        response = PolyaxonClients().job.get_job(user, project_name,
                                                 experiment, _job)
        # Set caching only if we have an initialized project
        if ProjectManager.is_initialized():
            JobManager.set_config(response)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error('Could not get job `{}`.'.format(_job))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    if response.resources:
        get_resources(response.resources.to_dict(), header="Job resources:")

    response = Printer.add_status_color(
        response.to_light_dict(humanize_values=True,
                               exclude_attrs=[
                                   'uuid', 'definition', 'experiment',
                                   'unique_name', 'resources'
                               ]))
    Printer.print_header("Job info:")
    dict_tabulate(response)
Пример #30
0
def get(group, project):
    """Get experiment group by uuid.

    Examples:
    ```
    polyaxon group get 13
    ```
    """
    user, project_name = get_project_or_local(project)
    try:
        response = PolyaxonClients().experiment_group.get_experiment_group(
            user, project_name, group)
    except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
        Printer.print_error(
            'Could not get experiment group `{}`.'.format(group))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    response = response.to_dict()
    Printer.print_header("Experiment group info:")
    dict_tabulate(response)