Esempio n. 1
0
def update(ctx, name, description, tags, private):
    """Update project.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Example:

    \b
    ```bash
    $ polyaxon update foobar --description="Image Classification with DL using TensorFlow"
    ```

    \b
    ```bash
    $ polyaxon update mike1/foobar --description="Image Classification with DL using TensorFlow"
    ```

    \b
    ```bash
    $ polyaxon update --tags="foo, bar"
    ```
    """
    user, project_name = get_project_or_local(ctx.obj.get('project'))

    update_dict = {}
    if name:
        update_dict['name'] = name

    if description:
        update_dict['description'] = description

    if private is not None:
        update_dict['is_public'] = not private

    tags = validate_tags(tags)
    if tags:
        update_dict['tags'] = tags

    if not update_dict:
        Printer.print_warning(
            'No argument was provided to update the project.')
        sys.exit(1)

    try:
        response = PolyaxonClient().project.update_project(
            user, project_name, update_dict)
    except (PolyaxonHTTPError, PolyaxonShouldExitError,
            PolyaxonClientException) as e:
        Printer.print_error(
            'Could not update project `{}`.'.format(project_name))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    Printer.print_success("Project updated.")
    get_project_details(response)
Esempio n. 2
0
def update(ctx, name, description, tags):
    """Update experiment group.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Example:

    \b
    ```bash
    $ polyaxon group -g 2 update --description="new description for this group"
    ```

    \b
    ```bash
    $ polyaxon update --tags="foo, bar"
    ```
    """
    user, project_name, _group = get_project_group_or_local(
        ctx.obj.get('project'), ctx.obj.get('group'))
    update_dict = {}

    if name:
        update_dict['name'] = name

    if description:
        update_dict['description'] = description

    tags = validate_tags(tags)
    if tags:
        update_dict['tags'] = tags

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

    try:
        response = PolyaxonClient().experiment_group.update_experiment_group(
            user, project_name, _group, update_dict)
    except (PolyaxonHTTPError, PolyaxonShouldExitError,
            PolyaxonClientException) 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)
Esempio n. 3
0
def update(ctx, name, description, tags):
    """Update experiment.

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

    Examples:

    \b
    ```bash
    $ polyaxon experiment -xp 2 update --description="new description for my experiments"
    ```

    \b
    ```bash
    $ polyaxon experiment -xp 2 update --tags="foo, bar" --name="unique-name"
    ```
    """
    user, project_name, _experiment = get_project_experiment_or_local(
        ctx.obj.get('project'), ctx.obj.get('experiment'))
    update_dict = {}

    if name:
        update_dict['name'] = name

    if description:
        update_dict['description'] = description

    tags = validate_tags(tags)
    if tags:
        update_dict['tags'] = tags

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

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

    Printer.print_success("Experiment updated.")
    get_experiment_details(response)
Esempio n. 4
0
def update(ctx, name, description, tags):
    """Update job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Example:

    \b
    ```bash
    $ polyaxon job -j 2 update --description="new description for my job"
    ```
    """
    user, project_name, _job = get_job_or_local(ctx.obj.get('project'),
                                                ctx.obj.get('job'))
    update_dict = {}

    if name:
        update_dict['name'] = name

    if description:
        update_dict['description'] = description

    tags = validate_tags(tags)
    if tags:
        update_dict['tags'] = tags

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

    try:
        response = PolyaxonClient().job.update_job(user, project_name, _job,
                                                   update_dict)
    except (PolyaxonHTTPError, PolyaxonShouldExitError,
            PolyaxonClientException) as e:
        Printer.print_error('Could not update job  `{}`.'.format(_job))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    Printer.print_success("Job updated.")
    get_job_details(response)
Esempio n. 5
0
def update(ctx, name, description, tags):
    """Update build.

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

    Example:

    \b
    ```bash
    $ polyaxon build -b 2 update --description="new description for my build"
    ```
    """
    user, project_name, _build = get_build_or_local(ctx.obj.get('project'),
                                                    ctx.obj.get('build'))
    update_dict = {}

    if name:
        update_dict['name'] = name

    if description:
        update_dict['description'] = description

    tags = validate_tags(tags)
    if tags:
        update_dict['tags'] = tags

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

    try:
        response = PolyaxonClient().build_job.update_build(
            user, project_name, _build, update_dict)
    except (PolyaxonHTTPError, PolyaxonShouldExitError,
            PolyaxonClientException) as e:
        Printer.print_error('Could not update build `{}`.'.format(_build))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    Printer.print_success("Build updated.")
    get_build_details(response)
Esempio n. 6
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]))
Esempio n. 7
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)
Esempio n. 8
0
 def test_validate_tags(self):
     assert ['foo', 'bar'] == validate_tags('foo,bar')
     assert ['foo', 'bar'] == validate_tags('  , foo,    bar,   ')
     assert ['foo', 'bar'] == validate_tags(['foo', 'bar'])
     assert ['foo', 'bar'] == validate_tags(['foo', 'bar', 1, 2])
     assert [] == validate_tags([{}, {}, 1, 2])