Beispiel #1
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))
Beispiel #2
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))
Beispiel #3
0
def run(ctx, file, description, u):  # pylint:disable=redefined-builtin
    """Run polyaxonfile specification.

    Example:

    \b
    ```bash
    $ polyaxon run -f file -f file_override ...
    ```

    Example: upload before running

    \b
    ```bash
    $ polyaxon run -f file -u
    ```

    """
    file = file or 'polyaxonfile.yml'
    specification = check_polyaxonfile(file, log=False).specification

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

    project = ProjectManager.get_config_or_raise()
    project_client = PolyaxonClients().project

    if specification.is_experiment:
        click.echo('Creating an independent experiment.')
        experiment = ExperimentConfig(
            description=description,
            config=specification.parsed_data)
        try:
            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 the following definition:')
        experiments_def = specification.experiments_def
        get_group_experiments_info(**experiments_def)
        experiment_group = ExperimentGroupConfig(
            description=description,
            content=specification._data)  # pylint:disable=protected-access
        try:
            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)
Beispiel #4
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)
Beispiel #5
0
def run(
        ctx,
        project,
        file,  # pylint:disable=redefined-builtin
        name,
        tags,
        description,
        ttl,
        debug,
        upload,
        log,
        local,
        conda_env,
        params):
    """Run polyaxonfile specification.

    Examples:

    \b
    ```bash
    $ polyaxon run -f file -f file_override ...
    ```

    Upload before running

    \b
    ```bash
    $ polyaxon run -f file -u
    ```

    Run and set description and tags for this run

    \b
    ```bash
    $ polyaxon run -f file -u --description="Description of the current run" --tags="foo, bar, moo"
    ```
    Run and set a unique name for this run

    \b
    ```bash
    polyaxon run --name=foo
    ```

    Run for a specific project

    \b
    ```bash
    $ polyaxon run -p project1 -f file.yaml
    ```

    Run with updated params

    \b
    ```bash
    $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu
    ```
    """
    if not file:
        file = PolyaxonFile.check_default_path(path='.')
    if not file:
        file = ''

    if debug and not ttl:
        Printer.print_error(
            'Debug mode requires a ttl to properly set a sleep time.')
        sys.exit(1)

    debug_ttl = None
    if debug and ttl:
        debug_ttl = ttl
        ttl = None

    specification = check_polyaxonfile(file,
                                       params=params,
                                       debug_ttl=debug_ttl,
                                       log=False).specification

    spec_cond = (specification.is_experiment or specification.is_group
                 or specification.is_job or specification.is_build)
    if not spec_cond:
        Printer.print_error(
            'This command expects an experiment, a group, a job, or a build specification,'
            'received instead a `{}` specification'.format(specification.kind))
        if specification.is_notebook:
            click.echo(
                'Please check "polyaxon notebook --help" to start a notebook.')
        elif specification.is_tensorboard:
            click.echo(
                'Please check: "polyaxon tensorboard --help" to start a tensorboard.'
            )
        sys.exit(1)

    user, project_name = get_project_or_local(project)
    tags = validate_tags(tags)

    if local:
        try:
            specification.apply_context()
        except PolyaxonSchemaError:
            Printer.print_error(
                'Could not run this polyaxonfile locally, '
                'a context is required to resolve it dependencies.')
        if conda_env:
            conda_run(ctx=ctx,
                      name=name,
                      user=user,
                      project_name=project_name,
                      description=description,
                      tags=tags,
                      specification=specification,
                      log=log,
                      conda_env=conda_env)
        else:
            docker_run(ctx=ctx,
                       name=name,
                       user=user,
                       project_name=project_name,
                       description=description,
                       tags=tags,
                       specification=specification,
                       log=log)
    else:
        platform_run(ctx=ctx,
                     name=name,
                     user=user,
                     project_name=project_name,
                     description=description,
                     tags=tags,
                     specification=specification,
                     ttl=ttl,
                     upload=upload,
                     log=log,
                     can_upload=all([upload, project]))
Beispiel #6
0
def run(ctx, project, file, name, tags, description, ttl, u, l):  # pylint:disable=redefined-builtin
    """Run polyaxonfile specification.

    Examples:

    \b
    ```bash
    $ polyaxon run -f file -f file_override ...
    ```

    Upload before running

    \b
    ```bash
    $ polyaxon run -f file -u
    ```

    Run and set description and tags for this run

    \b
    ```bash
    $ polyaxon run -f file -u --description="Description of the current run" --tags="foo, bar, moo"
    ```
    Run and set a unique name for this run

    \b
    ```bash
    polyaxon run --name=foo
    ```

    Run for a specific project

    \b
    ```bash
    $ polyaxon run -p project1 -f file.yaml
    ```
    """
    if not file:
        file = PolyaxonFile.check_default_path(path='.')
    if not file:
        file = ''
    specification = check_polyaxonfile(file, log=False).specification

    spec_cond = (specification.is_experiment or
                 specification.is_group or
                 specification.is_job or
                 specification.is_build)
    if not spec_cond:
        Printer.print_error(
            'This command expects an experiment, a group, a job, or a build specification,'
            'received instead a `{}` specification'.format(specification.kind))
        if specification.is_notebook:
            click.echo('Please check "polyaxon notebook --help" to start a notebook.')
        elif specification.is_tensorboard:
            click.echo('Please check: "polyaxon tensorboard --help" to start a tensorboard.')
        sys.exit(1)

    # Check if we need to upload
    if u:
        if project:
            Printer.print_error('Uploading is not supported when switching project context!')
            click.echo('Please, either omit the `-u` option or `-p` / `--project=` option.')
            sys.exit(1)
        ctx.invoke(upload, sync=False)

    user, project_name = get_project_or_local(project)
    project_client = PolyaxonClient().project

    tags = validate_tags(tags)

    def run_experiment():
        click.echo('Creating an independent experiment.')
        experiment = ExperimentConfig(
            name=name,
            description=description,
            tags=tags,
            config=specification.parsed_data,
            ttl=ttl)
        try:
            response = PolyaxonClient().project.create_experiment(user,
                                                                  project_name,
                                                                  experiment)
            cache.cache(config_manager=ExperimentManager, response=response)
            Printer.print_success('Experiment `{}` was created'.format(response.id))
        except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:
            Printer.print_error('Could not create experiment.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)

    def run_group():
        click.echo('Creating an experiment group with the following definition:')
        experiments_def = specification.experiments_def
        get_group_experiments_info(**experiments_def)
        experiment_group = ExperimentGroupConfig(
            name=name,
            description=description,
            tags=tags,
            content=specification._data)  # pylint:disable=protected-access
        try:
            response = project_client.create_experiment_group(user,
                                                              project_name,
                                                              experiment_group)
            cache.cache(config_manager=GroupManager, response=response)
            Printer.print_success('Experiment group {} was created'.format(response.id))
        except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:
            Printer.print_error('Could not create experiment group.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)

    def run_job():
        click.echo('Creating a job.')
        job = JobConfig(
            name=name,
            description=description,
            tags=tags,
            config=specification.parsed_data,
            ttl=ttl)
        try:
            response = project_client.create_job(user,
                                                 project_name,
                                                 job)
            cache.cache(config_manager=JobManager, response=response)
            Printer.print_success('Job {} was created'.format(response.id))
        except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:
            Printer.print_error('Could not create job.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)

    def run_build():
        click.echo('Creating a build.')
        job = JobConfig(
            name=name,
            description=description,
            tags=tags,
            config=specification.parsed_data,
            ttl=ttl)
        try:
            response = project_client.create_build(user,
                                                   project_name,
                                                   job)
            cache.cache(config_manager=BuildJobManager, response=response)
            Printer.print_success('Build {} was created'.format(response.id))
        except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:
            Printer.print_error('Could not create build.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)

    logs = None
    if specification.is_experiment:
        run_experiment()
        logs = experiment_logs
    elif specification.is_group:
        run_group()
    elif specification.is_job:
        run_job()
        logs = job_logs
    elif specification.is_build:
        run_build()
        logs = build_logs

    # Check if we need to invoke logs
    if l and logs:
        ctx.obj = {'project': '{}/{}'.format(user, project_name)}
        ctx.invoke(logs)
Beispiel #7
0
def start(ctx, file):  # pylint:disable=redefined-builtin
    """Start a tensorboard deployment for project/experiment/experiment group.

    Project tensorboard will aggregate all experiments under the project.

    Experiment group tensorboard will aggregate all experiments under the group.

    Experiment tensorboard will show all metrics for an experiment.

    Uses [Caching](/references/polyaxon-cli/#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 ...
    ```

    Example: starting a tensorboard for an experiment group

    \b
    ```bash
    $ polyaxon tensorboard -g 1 start -f file
    ```

    Example: starting a tensorboard for an experiment

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

    if specification:
        # pylint:disable=protected-access
        check_polyaxonfile_kind(specification=specification,
                                kind=kinds.TENSORBOARD)
        job_content = specification.raw_data

    user, project_name = get_project_or_local(ctx.obj.get('project'))
    group = ctx.obj.get('group')
    experiment = ctx.obj.get('experiment')
    if experiment:
        try:
            response = PolyaxonClient().experiment.start_tensorboard(
                username=user,
                project_name=project_name,
                experiment_id=experiment,
                content=job_content,
                is_managed=True,
            )
            obj = 'experiment `{}`'.format(experiment)
        except (PolyaxonHTTPError, PolyaxonShouldExitError,
                PolyaxonClientException) as e:
            Printer.print_error(
                'Could not start tensorboard experiment `{}`.'.format(
                    experiment))
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
    elif group:
        try:
            response = PolyaxonClient().experiment_group.start_tensorboard(
                username=user,
                project_name=project_name,
                group_id=group,
                content=job_content,
                is_managed=True,
            )
            obj = 'group `{}`'.format(group)
        except (PolyaxonHTTPError, PolyaxonShouldExitError,
                PolyaxonClientException) as e:
            Printer.print_error(
                'Could not start tensorboard group `{}`.'.format(group))
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
    else:
        try:
            response = PolyaxonClient().project.start_tensorboard(
                username=user,
                project_name=project_name,
                content=job_content,
                is_managed=True,
            )
            obj = 'project `{}`'.format(project_name)
        except (PolyaxonHTTPError, PolyaxonShouldExitError,
                PolyaxonClientException) 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 tensorboard for this {} is already running on:".format(obj))
        click.echo(
            get_tensorboard_url(user=user,
                                project_name=project_name,
                                experiment=experiment,
                                group=group))
        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 {}'.format(obj))
    indentation.puts(
        "It may take some time before you can access tensorboard.\n")
    indentation.puts("Your tensorboard will be available on:\n")
    with indentation.indent(4):
        indentation.puts(
            get_tensorboard_url(user, project_name, experiment, group))
Beispiel #8
0
def start(ctx, file, u):  # pylint:disable=redefined-builtin
    """Start a notebook deployment for this project.

    Uses [Caching](/references/polyaxon-cli/#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
    job_content = None
    if file:
        specification = check_polyaxonfile(file, log=False).specification

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

    if specification:
        # pylint:disable=protected-access
        check_polyaxonfile_kind(specification=specification,
                                kind=kinds.NOTEBOOK)
        job_content = specification.raw_data
    user, project_name = get_project_or_local(ctx.obj.get('project'))
    try:
        response = PolyaxonClient().project.start_notebook(
            username=user,
            project_name=project_name,
            content=job_content,
            is_managed=True,
        )
    except (PolyaxonHTTPError, PolyaxonShouldExitError,
            PolyaxonClientException) 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))
    indentation.puts(
        "It may take some time before you can access the notebook.\n")
    indentation.puts("Your notebook will be available on:\n")
    with indentation.indent(4):
        indentation.puts(get_notebook_url(user, project_name))