Exemple #1
0
def update(component, version, name, description, tags, private):
    """Update component hub.

    Uses /docs/core/cli/#caching

    Example:

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

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

    \b
    $ polyaxon hub update --tags="foo, bar"
    """
    owner, component_hub, component_version, is_version = get_info(
        component, version)
    full_entity = ("{}/{}:{}".format(owner, component_hub, component_version)
                   if is_version else "{}/{}".format(owner, component_hub))

    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 private is not None:
        update_dict["is_public"] = not private

    if not update_dict:
        Printer.print_warning(
            "No argument was provided to update the component {}.".format(
                "version" if is_version else "hub"))
        sys.exit(1)

    try:
        polyaxon_client = PolyaxonClient()
        if is_version:
            response = polyaxon_client.component_hub_v1.patch_component_version(
                owner, component_hub, component_version, body=update_dict)
            Printer.print_success("Component version updated.")
            get_component_version_details(response)
        else:
            response = polyaxon_client.component_hub_v1.patch_component_hub(
                owner, component_hub, body=update_dict)
            Printer.print_success("Component updated.")
            get_entity_details(response, "Component hub")
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e,
            message="Could not update component {} `{}`.".format(
                "version" if is_version else "hub", full_entity),
        )
        sys.exit(1)
Exemple #2
0
 def log_tags(self,
              tags: Union[str, Sequence[str]],
              reset=False,
              async_req=True):
     patch_dict = {"tags": validate_tags(tags)}
     if reset is False:
         patch_dict["merge"] = True
     self._update(patch_dict, async_req=async_req)
Exemple #3
0
def create(ctx, name, description, tags, public, init):
    """Create a new project.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon project create --name=cats-vs-dogs --description="Image Classification with DL"

    \b
    $ polyaxon project create --name=owner/name --description="Project Description"
    """
    if not name:
        Printer.print_error(
            "Please provide a valid name to create a project.",
            command_help="project create",
            sys_exit=True,
        )
    owner, project_name = resolve_entity_info(name or ctx.obj.get("project"),
                                              is_cli=True,
                                              entity_name="project")

    tags = validate_tags(tags)

    if not owner:
        Printer.print_error(
            "Please provide a valid name with an owner namespace: --name=owner/project."
        )
        sys.exit(1)

    try:
        project_config = V1Project(name=project_name,
                                   description=description,
                                   tags=tags,
                                   is_public=public)
        polyaxon_client = ProjectClient(owner=owner)
        _project = polyaxon_client.create(project_config)
        config = polyaxon_client.client.sanitize_for_serialization(_project)
        cache.cache(config_manager=ProjectConfigManager, config=config)
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not create project `{}`.".format(project_name))
        sys.exit(1)

    Printer.print_success("Project `{}` was created successfully.".format(
        _project.name))
    click.echo("You can view this project on Polyaxon UI: {}".format(
        get_dashboard_url(subpath="{}/{}".format(owner, _project.name))))

    if init:
        ctx.obj = {}
        ctx.invoke(
            init_project,
            project="{}/{}".format(owner, project_name),
            polyaxonignore=True,
        )
Exemple #4
0
def create(ctx, name, description, tags, private, init):
    """Create a new project.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon project create --project=cats-vs-dogs --description="Image Classification with DL"

    \b
    $ polyaxon project create --project=owner/name --description="Project Description"
    """
    if not name:
        Printer.print_error(
            "Please login provide a name to create a project.",
            command_help="project create",
            sys_exit=True,
        )
    owner, project_name = get_project_or_local(name or ctx.obj.get("project"),
                                               is_cli=True)
    owner = owner or settings.AUTH_CONFIG.username
    if not owner and (not settings.CLI_CONFIG or settings.CLI_CONFIG.is_ce):
        owner = DEFAULT

    tags = validate_tags(tags)

    if not owner:
        Printer.print_error(
            "Please login first or provide a valid name with owner --name=owner/project. "
            "`polyaxon login --help`")
        sys.exit(1)

    try:
        project_config = V1Project(name=project_name,
                                   description=description,
                                   tags=tags,
                                   is_public=not private)
        polyaxon_client = ProjectClient(owner=owner)
        _project = polyaxon_client.create(project_config)
        config = polyaxon_client.client.sanitize_for_serialization(_project)
        cache.cache(config_manager=ProjectConfigManager, config=config)
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not create project `{}`.".format(project_name))
        sys.exit(1)

    Printer.print_success("Project `{}` was created successfully.".format(
        _project.name))
    click.echo("You can view this project on Polyaxon UI: {}".format(
        get_dashboard_url(subpath="{}/{}".format(owner, _project.name))))

    if init:
        ctx.obj = {}
        ctx.invoke(init_project, project="{}/{}".format(owner, project_name))
Exemple #5
0
def update(ctx, name, description, tags):
    """Update run.

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

    Examples:

    \b
    ```bash
    $ polyaxon runs --uid=8aac02e3a62a4f0aaa257c59da5eab80 update
    --description="new description for my runs"
    ```

    \b
    ```bash
    $ polyaxon runs --project=cats-vs-dogs -id 8aac02e3a62a4f0aaa257c59da5eab80 update
    --tags="foo, bar" --name="unique-name"
    ```
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"), is_cli=True)
    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 run.")
        sys.exit(0)

    try:
        polyaxon_client = RunClient(owner=owner,
                                    project=project_name,
                                    run_uuid=run_uuid)
        response = polyaxon_client.update(update_dict)
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not update run `{}`.".format(run_uuid))
        sys.exit(1)

    Printer.print_success("Run updated.")
    get_run_details(response)
Exemple #6
0
def create(name, description, tags, public):
    """Create a new model.

    Example:

    \b
    $ polyaxon registry create --name=kaniko --description="Tool to build container images"

    \b
    $ polyaxon registry create --name=owner/name --description="Model description"
    """
    if not name:
        Printer.print_error(
            "Please provide a name to create a model registry.",
            command_help="registry create",
            sys_exit=True,
        )
    owner, registry_name, _, _ = get_info(name, None)

    tags = validate_tags(tags)

    if not owner or not registry_name:
        Printer.print_error(
            "Please provide a valid model name with --name=owner/registry-name. "
        )
        sys.exit(1)

    try:
        registry_config = V1ModelRegistry(
            name=registry_name, description=description, tags=tags, is_public=public
        )
        polyaxon_client = PolyaxonClient()
        _registry = polyaxon_client.model_registry_v1.create_model_registry(
            owner, registry_config
        )
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not create model registry `{}`.".format(registry_name)
        )
        sys.exit(1)

    Printer.print_success(
        "Model registry `{}` was created successfully.".format(_registry.name)
    )
    click.echo(
        "You can view this model registry on Polyaxon UI: {}".format(
            get_dashboard_url(subpath="{}/registry/{}".format(owner, _registry.name))
        )
    )
Exemple #7
0
def update(ctx, _project, name, description, tags, private):
    """Update project.

    Uses /docs/core/cli/#caching

    Example:

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

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

    \b
    $ polyaxon update --tags="foo, bar"
    """
    owner, project_name = get_project_or_local(_project
                                               or ctx.obj.get("project"),
                                               is_cli=True)

    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 private is not None:
        update_dict["is_public"] = not private

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

    try:
        polyaxon_client = ProjectClient(owner=owner)
        response = polyaxon_client.update(update_dict)
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not update project `{}`.".format(project_name))
        sys.exit(1)

    Printer.print_success("Project updated.")
    get_entity_details(response, "Project")
Exemple #8
0
def create(name, description, tags, public):
    """Create a new component.

    Example:

    \b
    $ polyaxon hub create --name=kaniko --description="Tool to build container images"

    \b
    $ polyaxon hub create --name=owner/name --description="Component description"
    """
    if not name:
        Printer.print_error(
            "Please provide a name to create a component hub.",
            command_help="hub create",
            sys_exit=True,
        )
    owner, hub_name, _, _ = get_info(name, None)

    tags = validate_tags(tags)

    if not owner or not hub_name:
        Printer.print_error(
            "Please provide a valid component name with --name=owner/hub-name. "
        )
        sys.exit(1)

    try:
        hub_config = V1ComponentHub(
            name=hub_name, description=description, tags=tags, is_public=public
        )
        polyaxon_client = PolyaxonClient()
        _hub = polyaxon_client.component_hub_v1.create_component_hub(owner, hub_config)
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not create component hub `{}`.".format(hub_name)
        )
        sys.exit(1)

    Printer.print_success(
        "Component hub `{}` was created successfully.".format(_hub.name)
    )
    click.echo(
        "You can view this component hub on Polyaxon UI: {}".format(
            get_dashboard_url(subpath="{}/hub/{}".format(owner, _hub.name))
        )
    )
Exemple #9
0
    def log_tags(
        self,
        tags: Union[str, Sequence[str]],
        reset: bool = False,
        async_req: bool = True,
    ):
        """Logs new tags for the current run.

        Args:
            tags: str or List[str], tag or tags to log.
            reset: bool, optional, if True, it will reset the whole tags state.
                Note that Polyaxon will automatically populate the tags based
                on the Polyaxonfile.
            async_req: bool, optional, default: False, execute request asynchronously.
        """
        patch_dict = {"tags": validate_tags(tags)}
        if reset is False:
            patch_dict["merge"] = True
        self._update(patch_dict, async_req=async_req)
Exemple #10
0
def create(ctx, name, owner, description, tags, private, init):
    """Create a new project.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon project create --name=cats-vs-dogs --description="Image Classification with DL"
    """
    owner = owner or AuthConfigManager.get_value("username")
    tags = validate_tags(tags)

    if not owner:
        Printer.print_error(
            "Please login first or provide a valid owner --owner. "
            "`polyaxon login --help`")
        sys.exit(1)

    try:
        project_config = V1Project(name=name,
                                   description=description,
                                   tags=tags,
                                   is_public=not private)
        polyaxon_client = ProjectClient(owner=owner)
        _project = polyaxon_client.create(project_config)
        config = polyaxon_client.client.sanitize_for_serialization(
            _project.project_data)
        cache.cache(config_manager=ProjectManager, config=config)
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not create project `{}`.".format(name))
        sys.exit(1)

    Printer.print_success("Project `{}` was created successfully.".format(
        _project.name))

    if init:
        ctx.obj = {}
        ctx.invoke(init_project, project=name)
Exemple #11
0
def run(
    ctx,
    project,
    polyaxonfile,
    python_module,
    url,
    hub,
    name,
    tags,
    description,
    log,
    watch,
    local,
    params,
    presets,
    queue,
    nocache,
    eager,
    git_preset,
    git_revision,
    ignore_template,
):
    """Run polyaxonfile specification.

    Examples:

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

    Run and set description and tags for this run

    \b
    $ polyaxon run -f file --description="Description of the current run" --tags="foo, bar, moo"

    Run and set a unique name for this run

    \b
    polyaxon run --name=foo

    Run for a specific project

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

    Run with updated params

    \b
    $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu

    If a python file contains a component main, you can run that component

    \b
    polyaxon run -pm path/to/my-component.py


    If a python file contains more than one component, you can specify the component to run

    \b
    polyaxon run -pm path/to/my-component.py:componentA
    """
    git_init = None
    if git_preset:
        # Check that the current path was initialized
        if not GitConfigManager.is_initialized():
            Printer.print_error(
                "You can't use --git-init, "
                "the current path is not initialized with a valid git connection or a git url, "
                "please run `polyaxon init [--git-connection] [--git-url]` "
                "to set a valid git configuration.")
            sys.exit(1)
        git_init = GitConfigManager.get_config()
        if git_revision:
            git_init.git.revision = git_revision
        elif code_reference.is_git_initialized(path="."):
            if code_reference.is_dirty(path="."):
                Printer.print_warning(
                    "Polyaxon detected uncommitted changes in the current git repo!"
                )
            commit_hash = code_reference.get_commit()
            git_init.git.revision = commit_hash
        else:
            Printer.print_warning(
                "Polyaxon could not find a valid git repo, "
                "and will not add the current commit to the git initializer.")

    presets = validate_tags(presets)

    op_spec = check_polyaxonfile(
        polyaxonfile=polyaxonfile,
        python_module=python_module,
        url=url,
        hub=hub,
        params=params,
        presets=presets,
        queue=queue,
        nocache=nocache,
        verbose=False,
        eager=eager,
        git_init=git_init,
        ignore_template=ignore_template,
    )

    if ignore_template:
        op_spec.disable_template()
    if op_spec.is_template():
        click.echo(
            "Please customize the specification or disable the template.")
        sys.exit(1)

    owner, project_name = get_project_or_local(project, is_cli=True)
    tags = validate_tags(tags)

    if local:
        try:
            compiled_operation = OperationSpecification.compile_operation(
                op_spec)
            compiled_operation = CompiledOperationSpecification.apply_operation_contexts(
                compiled_operation)
        except (PolyaxonSchemaError, ValidationError):
            Printer.print_error(
                "Could not run this polyaxonfile locally, "
                "a context is required to resolve it dependencies.")
            sys.exit(1)
        docker_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            compiled_operation=compiled_operation,
            log=log,
        )
    elif settings.CLIENT_CONFIG.no_api:
        k8s_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            op_spec=op_spec,
            log=log,
        )
    else:
        platform_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            op_spec=op_spec,
            log=log,
            watch=watch,
            eager=eager,
        )
Exemple #12
0
def push(polyaxonfile, name, description, tags):
    """Push a new component version.
    If the name corresponds to an existing component version, it will be updated.

    Example:

    \b
    $ polyaxon hub push -f polyaxonfile.yaml --name=kaniko:latest --description="Tool to build container images"

    \b
    $ polyaxon hub push -f polyaxonfile.yaml --name=owner/name:v1 --description="Component description"
    """
    if not name:
        Printer.print_error(
            "Please provide a name to create a component version.",
            command_help="hub push",
            sys_exit=True,
        )
    owner, hub_name, version, is_version = get_info(None, name)
    tags = validate_tags(tags)

    if not polyaxonfile or not os.path.isfile(polyaxonfile):
        Printer.print_error(
            "Please provide a path to a polyaxonfile to create a component version.",
            command_help="hub push",
            sys_exit=True,
        )
    try:
        plx_file = get_specification(data=polyaxonfile)
    except Exception as e:
        handle_cli_error(e, message="Polyaxonfile is not valid.")
        sys.exit(1)

    if not owner or not hub_name or not version:
        Printer.print_error(
            "Please provide a valid component version with --name=owner/hub-name:version. "
        )
        sys.exit(1)

    polyaxon_client = PolyaxonClient()
    try:
        polyaxon_client.component_hub_v1.get_component_version(owner, hub_name, version)
        to_update = True
    except (ApiException, HTTPError):
        to_update = False

    if to_update:
        if not click.confirm(
            "A component version {}/{}:{} already exists. "
            "Do you want to push force this version?".format(owner, hub_name, version)
        ):
            click.echo("Existing without pushing component version.")
            sys.exit(1)

    try:
        hub_config = V1ComponentVersion(
            name=version,
            description=description,
            tags=tags,
            content=plx_file.to_dict(dump=True),
        )
        if to_update:
            _version = polyaxon_client.component_hub_v1.update_component_version(
                owner,
                hub_name,
                version,
                hub_config,
            )
        else:
            _version = polyaxon_client.component_hub_v1.create_component_version(
                owner,
                hub_name,
                hub_config,
            )
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not create component version `{}`.".format(hub_name)
        )
        sys.exit(1)

    Printer.print_success(
        "Component version `{}` was created successfully.".format(_version.name)
    )
    click.echo(
        "You can view this component version on Polyaxon UI: {}".format(
            get_dashboard_url(
                subpath="{}/hub/{}/versions/{}".format(owner, hub_name, _version.name)
            )
        )
    )
Exemple #13
0
def run(
    ctx,
    project,
    polyaxonfile,
    name,
    tags,
    description,
    upload,
    log,
    local,
    conda_env,
    params,
    profile,
    nocache,
):
    """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
    ```
    """
    specification = check_polyaxonfile(polyaxonfile,
                                       params=params,
                                       profile=profile,
                                       nocache=nocache,
                                       log=False)

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

    if local:
        try:
            run_spec = get_specification(specification.generate_run_data())
            run_spec.apply_context()
        except PolyaxonSchemaError:
            Printer.print_error(
                "Could not run this polyaxonfile locally, "
                "a context is required to resolve it dependencies.")
            sys.exit(1)
        if conda_env:
            conda_run(
                ctx=ctx,
                name=name,
                owner=owner,
                project_name=project_name,
                description=description,
                tags=tags,
                specification=run_spec,
                log=log,
                conda_env=conda_env,
            )
        else:
            docker_run(
                ctx=ctx,
                name=name,
                owner=owner,
                project_name=project_name,
                description=description,
                tags=tags,
                specification=run_spec,
                log=log,
            )
    else:
        platform_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            specification=specification,
            upload=upload,
            log=log,
            can_upload=all([upload, project]),
        )
Exemple #14
0
def run(
    ctx,
    project,
    polyaxonfile,
    python_module,
    url,
    hub,
    name,
    tags,
    description,
    upload,
    log,
    watch,
    local,
    conda_env,
    params,
    profile,
    queue,
    nocache,
):
    """Run polyaxonfile specification.

    Examples:

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

    Upload before running

    \b
    $ polyaxon run -f file -u

    Run and set description and tags for this run

    \b
    $ 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
    polyaxon run --name=foo

    Run for a specific project

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

    Run with updated params

    \b
    $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu

    If a python file contains a component main, you can run that component

    \b
    polyaxon run -pm path/to/my-component.py


    If a python file contains more than one component, you can specify the component to run

    \b
    polyaxon run -pm path/to/my-component.py:componentA
    """
    op_spec = check_polyaxonfile(
        polyaxonfile=polyaxonfile,
        python_module=python_module,
        url=url,
        hub=hub,
        params=params,
        profile=profile,
        queue=queue,
        nocache=nocache,
        log=False,
    )

    owner, project_name = get_project_or_local(project, is_cli=True)
    tags = validate_tags(tags)

    if local:
        try:
            compiled_operation = OperationSpecification.compile_operation(op_spec)
            compiled_operation = CompiledOperationSpecification.apply_context(
                compiled_operation
            )
        except (PolyaxonSchemaError, ValidationError):
            Printer.print_error(
                "Could not run this polyaxonfile locally, "
                "a context is required to resolve it dependencies."
            )
            sys.exit(1)
        docker_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            compiled_operation=compiled_operation,
            log=log,
        )
    elif settings.CLIENT_CONFIG.no_api:
        k8s_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            op_spec=op_spec,
            upload=upload,
            log=log,
            can_upload=all([upload, project]),
        )
    else:
        platform_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            op_spec=op_spec,
            upload=upload,
            log=log,
            watch=watch,
            can_upload=all([upload, project]),
        )
Exemple #15
0
 def log_tags(self, tags, reset=False):
     patch_dict = {"tags": validate_tags(tags)}
     if reset is False:
         patch_dict["merge"] = True
     self._update(patch_dict)
Exemple #16
0
def push(name, description, tags, run_uid):
    """Push a new model version.
    If the name corresponds to an existing model version, it will be updated.

    Example:

    \b
    $ polyaxon registry push -f polyaxonfile.yaml --name=kaniko:latest --description="Tool to build container images"

    \b
    $ polyaxon registry push -f polyaxonfile.yaml --name=owner/name:v1 --description="Model description"
    """
    if not name:
        Printer.print_error(
            "Please provide a name to create a model version.",
            command_help="registry push",
            sys_exit=True,
        )
    owner, registry_name, version, is_version = get_info(None, name)
    tags = validate_tags(tags)

    if not owner or not registry_name or not version:
        Printer.print_error(
            "Please provide a valid model version with --name=owner/registry-name:version. "
        )
        sys.exit(1)

    polyaxon_client = PolyaxonClient()
    try:
        polyaxon_client.model_registry_v1.get_model_version(
            owner, registry_name, version
        )
        to_update = True
    except (ApiException, HTTPError):
        to_update = False

    if to_update:
        if not click.confirm(
            "A model version {}/{}:{} already exists. "
            "Do you want to push force this version?".format(
                owner, registry_name, version
            )
        ):
            click.echo("Existing without pushing model version.")
            sys.exit(1)

    try:
        registry_config = V1ModelVersion(
            name=version,
            description=description,
            tags=tags,
            run=run_uid,
        )
        if to_update:
            _version = polyaxon_client.model_registry_v1.update_model_version(
                owner,
                registry_name,
                version,
                registry_config,
            )
        else:
            _version = polyaxon_client.model_registry_v1.create_model_version(
                owner,
                registry_name,
                registry_config,
            )
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not create model version `{}`.".format(registry_name)
        )
        sys.exit(1)

    Printer.print_success(
        "Model version `{}` was created successfully.".format(_version.name)
    )
    click.echo(
        "You can view this model version on Polyaxon UI: {}".format(
            get_dashboard_url(
                subpath="{}/registry/{}/versions/{}".format(
                    owner, registry_name, _version.name
                )
            )
        )
    )
Exemple #17
0
def run(
    ctx,
    project,
    polyaxonfile,
    python_module,
    url,
    hub,
    name,
    tags,
    description,
    log,
    upload,
    upload_from,
    upload_to,
    watch,
    local,
    params,
    presets,
    queue,
    nocache,
    cache,
    eager,
    git_preset,
    git_revision,
    ignore_template,
):
    """Run polyaxonfile specification.

    Examples:

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

    Run and set description and tags for this run

    \b
    $ polyaxon run -f file --description="Description of the current run" --tags="foo, bar, moo"

    Run and set a unique name for this run

    \b
    polyaxon run --name=foo

    Run for a specific project

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

    Run with updated params

    \b
    $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu

    If a python file contains a component main, you can run that component

    \b
    $ polyaxon run -pm path/to/my-component.py


    If a python file contains more than one component, you can specify the component to run

    \b
    $ polyaxon run -pm path/to/my-component.py:componentA


    Uploading from everything in the current folder to the default uploads path

    \b
    $ polyaxon run ... -u


    Uploading from everything in the current folder to a custom path, e.g. code

    \b
    $ polyaxon run ... -u-to code

    Uploading from everything from a sub-folder, e.g. ./code to the a custom path, e.g. new-code

    \b
    $ polyaxon run ... -u-from ./code -u-to new-code
    """
    if cache and nocache:
        Printer.print_error(
            "You can't use `--cache` and `--nocache` at the same.", sys_exit=True
        )
    if (upload_to or upload_from) and not upload:
        upload = True
    if upload and eager:
        Printer.print_error(
            "You can't use `--upload` and `--eager` at the same.", sys_exit=True
        )

    git_init = None
    if git_preset or git_revision:
        # Check that the current path was initialized
        if not GitConfigManager.is_initialized():
            Printer.print_error(
                "You can't use `--git-preset [--git-revision]`, "
                "the current path is not initialized with a valid git connection or a git url, "
                "please run `polyaxon init [--git-connection] [--git-url]` "
                "to set a valid git configuration.",
                sys_exit=True,
            )
        git_init = GitConfigManager.get_config()
        if git_init.git is None:
            GitConfigManager.purge(visibility=GitConfigManager.VISIBILITY_LOCAL)
            Printer.print_error(
                "Polyaxon could not start a new run with the `[--git-preset] or [--git-revision]`. "
                "The current path is initialized with "
                "an invalid git connection or an invalid git url.\n"
                "please run `polyaxon init [--git-connection] [--git-url]` "
                "to properly initialize the current path.",
                sys_exit=True,
            )
        if git_revision:
            git_init.git.revision = git_revision
        elif code_reference.is_git_initialized(path="."):
            if code_reference.is_dirty(path="."):
                Printer.print_warning(
                    "Polyaxon detected uncommitted changes in the current git repo!"
                )
            commit_hash = code_reference.get_commit()
            git_init.git.revision = commit_hash
        else:
            Printer.print_warning(
                "Polyaxon could not find a valid git repo, "
                "and will not add the current commit to the git initializer."
            )

    presets = validate_tags(presets)

    op_spec = check_polyaxonfile(
        polyaxonfile=polyaxonfile,
        python_module=python_module,
        url=url,
        hub=hub,
        params=params,
        presets=presets,
        queue=queue,
        cache=cache,
        nocache=nocache,
        verbose=False,
        eager=eager,
        git_init=git_init,
        ignore_template=ignore_template,
    )

    if ignore_template:
        op_spec.disable_template()
    if op_spec.is_template():
        click.echo("Please customize the specification or disable the template.")
        sys.exit(1)

    owner, project_name = get_project_or_local(project, is_cli=True)
    tags = validate_tags(tags)

    if local:
        try:
            compiled_operation = OperationSpecification.compile_operation(op_spec)
            compiled_operation = (
                CompiledOperationSpecification.apply_operation_contexts(
                    compiled_operation
                )
            )
        except (PolyaxonSchemaError, ValidationError):
            Printer.print_error(
                "Could not run this polyaxonfile locally, "
                "a context is required to resolve it dependencies."
            )
            sys.exit(1)
        docker_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            compiled_operation=compiled_operation,
            log=log,
        )
    elif settings.CLIENT_CONFIG.no_api:
        k8s_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            op_spec=op_spec,
            log=log,
        )
    else:
        platform_run(
            ctx=ctx,
            name=name,
            owner=owner,
            project_name=project_name,
            description=description,
            tags=tags,
            op_spec=op_spec,
            log=log,
            upload=upload,
            upload_to=upload_to,
            upload_from=upload_from,
            watch=watch,
            eager=eager,
        )
Exemple #18
0
def ls(ctx, io, query, sort, limit, offset, columns):
    """List runs for this project.

    Uses /docs/core/cli/#caching

    Examples:

    Get all runs:

    \b

    Get all runs with with status {created or running}, and
    creation date between 2018-01-01 and 2018-01-02, and params activation equal to sigmoid
    and metric loss less or equal to 0.2

    \b
    $ polyaxon ops ls \
    -q "status:created|running, started_at:2018-01-01..2018-01-02, \
    params.activation:sigmoid, metrics.loss:<=0.2"


    Get all runs sorted by update date:

    \b
    $ polyaxon ops ls -s "-updated_at"

    Get all runs of kind job:

    \b
    $ polyaxon ops ls -q "kind: job"

    Get all runs of kind service:

    \b
    $ polyaxon ops ls -q "kind: service"
    """
    owner, project_name = get_project_or_local(ctx.obj.get("project"), is_cli=True)

    try:
        polyaxon_client = RunClient(owner=owner, project=project_name)
        response = polyaxon_client.list(
            limit=limit, offset=offset, query=query, sort=sort
        )
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e, message="Could not get runs for project `{}`.".format(project_name)
        )
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header("Runs for project `{}/{}`.".format(owner, project_name))
        Printer.print_header("Navigation:")
        dict_tabulate(meta)
    else:
        Printer.print_header(
            "No runs found for project `{}/{}`.".format(owner, project_name)
        )

    objects = [Printer.add_status_color(o.to_dict()) for o in response.results]

    if io:
        objects = get_runs_with_keys(objects=objects, params_keys=["inputs", "outputs"])
        objects = list_dicts_to_tabulate(
            objects,
            include_attrs=validate_tags(columns),
            exclude_attrs=[
                "owner",
                "project",
                "description",
                "content",
                "raw_content",
                "deleted",
                "readme",
                "settings",
                "meta_info",
                "original",
                "pipeline",
                "role",
                "status_conditions",
                "is_helper",
            ],
        )
    else:
        objects = list_dicts_to_tabulate(
            objects,
            include_attrs=validate_tags(columns),
            exclude_attrs=[
                "owner",
                "project",
                "description",
                "content",
                "raw_content",
                "deleted",
                "readme",
                "inputs",
                "outputs",
                "settings",
                "meta_info",
                "original",
                "pipeline",
                "role",
                "status_conditions",
                "is_helper",
            ],
        )
    if objects:
        Printer.print_header("Runs:")
        objects.pop("project_name", None)
        dict_tabulate(objects, is_list_dict=True)
Exemple #19
0
def ls(ctx, project, io, to_csv, query, sort, limit, offset, columns, offline,
       offline_path):
    """List runs for this project.

    Uses /docs/core/cli/#caching

    Examples:

    Get all runs:

    \b

    Get all runs with with status {created or running}, and
    creation date between 2018-01-01 and 2018-01-02, and params activation equal to sigmoid
    and metric loss less or equal to 0.2

    \b
    $ polyaxon ops ls \
    -q "status:created|running, started_at:2018-01-01..2018-01-02, \
    params.activation:sigmoid, metrics.loss:<=0.2"


    Get all runs sorted by update date:

    \b
    $ polyaxon ops ls -s "-updated_at"

    Get all runs of kind job:

    \b
    $ polyaxon ops ls -q "kind: job"

    Get all runs of kind service:

    \b
    $ polyaxon ops ls -q "kind: service"
    """
    if offline:
        offline_path = offline_path or container_contexts.CONTEXT_OFFLINE_ROOT
        offline_path_format = "{}/{{}}/run_data.json".format(offline_path)
        if not os.path.exists(offline_path) or not os.path.isdir(offline_path):
            Printer.print_error(
                f"Could not list offline runs, the path `{offline_path}` "
                f"does not exist or is not a directory.")
            sys.exit(1)
        results = []
        for uid in os.listdir(offline_path):
            run_path = offline_path_format.format(uid)
            if os.path.exists(run_path):
                results.append(RunConfigManager.read_from_path(run_path))
            else:
                Printer.print_warning(
                    f"Skipping run {uid}, offline data not found.")
    else:
        owner, project_name = get_project_or_local(project
                                                   or ctx.obj.get("project"),
                                                   is_cli=True)

        try:
            polyaxon_client = RunClient(owner=owner, project=project_name)
            response = polyaxon_client.list(limit=limit,
                                            offset=offset,
                                            query=query,
                                            sort=sort)
        except (ApiException, HTTPError) as e:
            handle_cli_error(
                e,
                message="Could not get runs for project `{}`.".format(
                    project_name))
            sys.exit(1)

        meta = get_meta_response(response)
        if meta:
            Printer.print_header("Runs for project `{}/{}`.".format(
                owner, project_name))
            Printer.print_header("Navigation:")
            dict_tabulate(meta)
        else:
            Printer.print_header("No runs found for project `{}/{}`.".format(
                owner, project_name))

        results = response.results

    objects = [Printer.add_status_color(o.to_dict()) for o in results]
    columns = validate_tags(columns)
    if io:
        objects, prefixed_columns = flatten_keys(
            objects=objects,
            columns=["inputs", "outputs"],
            columns_prefix={
                "inputs": "in",
                "outputs": "out"
            },
        )
        if columns:
            columns = {prefixed_columns.get(col, col) for col in columns}
        if to_csv:
            objects = list_dicts_to_csv(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
            )
        else:
            objects = list_dicts_to_tabulate(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
                humanize_values=True,
                upper_keys=True,
            )
    else:
        if to_csv:
            objects = list_dicts_to_csv(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE + ["inputs", "outputs"],
            )
        else:
            objects = list_dicts_to_tabulate(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE + ["inputs", "outputs"],
                humanize_values=True,
                upper_keys=True,
            )
    if objects:
        if to_csv:
            filename = "./results.csv"
            write_csv(objects, filename=filename)
            Printer.print_success("CSV file generated: `{}`".format(filename))
        else:
            Printer.print_header("Runs:")
            objects.pop("project_name", None)
            dict_tabulate(objects, is_list_dict=True)
 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])
Exemple #21
0
def ls(ctx, io, to_csv, query, sort, limit, offset, columns):
    """List runs for this project.

    Uses /docs/core/cli/#caching

    Examples:

    Get all runs:

    \b

    Get all runs with with status {created or running}, and
    creation date between 2018-01-01 and 2018-01-02, and params activation equal to sigmoid
    and metric loss less or equal to 0.2

    \b
    $ polyaxon ops ls \
    -q "status:created|running, started_at:2018-01-01..2018-01-02, \
    params.activation:sigmoid, metrics.loss:<=0.2"


    Get all runs sorted by update date:

    \b
    $ polyaxon ops ls -s "-updated_at"

    Get all runs of kind job:

    \b
    $ polyaxon ops ls -q "kind: job"

    Get all runs of kind service:

    \b
    $ polyaxon ops ls -q "kind: service"
    """
    owner, project_name = get_project_or_local(ctx.obj.get("project"),
                                               is_cli=True)

    try:
        polyaxon_client = RunClient(owner=owner, project=project_name)
        response = polyaxon_client.list(limit=limit,
                                        offset=offset,
                                        query=query,
                                        sort=sort)
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not get runs for project `{}`.".format(
                             project_name))
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header("Runs for project `{}/{}`.".format(
            owner, project_name))
        Printer.print_header("Navigation:")
        dict_tabulate(meta)
    else:
        Printer.print_header("No runs found for project `{}/{}`.".format(
            owner, project_name))

    objects = [Printer.add_status_color(o.to_dict()) for o in response.results]
    columns = validate_tags(columns)
    if io:
        objects, prefixed_columns = flatten_keys(
            objects=objects,
            columns=["inputs", "outputs"],
            columns_prefix={
                "inputs": "in",
                "outputs": "out"
            },
        )
        if columns:
            columns = {prefixed_columns.get(col, col) for col in columns}
        if to_csv:
            objects = list_dicts_to_csv(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
            )
        else:
            objects = list_dicts_to_tabulate(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
                humanize_values=True,
                upper_keys=True,
            )
    else:
        if to_csv:
            objects = list_dicts_to_csv(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
            )
        else:
            objects = list_dicts_to_tabulate(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
                humanize_values=True,
                upper_keys=True,
            )
    if objects:
        if to_csv:
            write_csv(objects)
        else:
            Printer.print_header("Runs:")
            objects.pop("project_name", None)
            dict_tabulate(objects, is_list_dict=True)