Esempio n. 1
0
def get_ml_client(workspace_name: str) -> MLClient:
    cred = DefaultAzureCredential()

    if workspace_name == "Alexander256V100":
        rv = MLClient(cred, "79f57c16-00fe-48da-87d4-5192e86cd047",
                      "Alexander256", workspace_name)
    elif workspace_name == "aml1p-ml-wus2":
        rv = MLClient(cred, "48bbc269-ce89-4f6f-9a12-c6f91fcb772d", "aml1p-rg",
                      workspace_name)
    else:
        raise ValueError(f"Workspace {workspace_name} is not known")

    return rv
Esempio n. 2
0
def ml_datastore_attach_blob(
    cmd,
    resource_group_name,
    workspace_name,
    account_name,
    container_name,
    name,
    account_key=None,
    sas_token=None,
    protocol=None,
    endpoint=None,
):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    return ml_client.datastores.attach_azure_blob_storage(
        name,
        container_name,
        account_name,
        account_key=account_key,
        sas_token=sas_token,
        protocol=protocol,
        endpoint=endpoint,
    )
Esempio n. 3
0
def ml_model_create(cmd,
                    resource_group_name,
                    workspace_name,
                    name=None,
                    version=None,
                    file=None,
                    path=None,
                    params_override=[]):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    if name is not None:
        params_override.append({"name": name})
    if version is not None:
        params_override.append({"version": version})
    if path is not None:
        params_override.append({"asset_path": path})
    try:
        return ml_client.model.create_or_update(
            file=file, params_override=params_override)
    except Exception as err:
        print_error_and_exit(str(err))
Esempio n. 4
0
def ml_workspace_list(cmd, resource_group_name):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(subscription_id=subscription_id,
                         resource_group_name=resource_group_name,
                         credential=AzureCliCredential())
    return ml_client.workspaces.list()
Esempio n. 5
0
def client() -> MLClient:
    """return a machine learning client using default e2e testing workspace"""
    subscription_id = "4faaaf21-663f-4391-96fd-47197c630979"
    resource_group_name = "static_sdk_cli_v2_test_e2e"
    workspace_name = "sdk_vnext_cli"
    return MLClient(subscription_id,
                    resource_group_name,
                    default_workspace_name=workspace_name)
Esempio n. 6
0
def mock_machinelearning_client() -> MLClient:
    yield MLClient(
        subscription_id=Test_Subscription,
        resource_group_name=Test_Resource_Group,
        default_workspace_name=Test_Workspace_Name,
        base_url=Test_Base_Url,
        credential=Mock(spec_set=DefaultAzureCredential),
    )
Esempio n. 7
0
def ml_data_delete(cmd, resource_group_name, workspace_name, name, version):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    return ml_client.data.delete(name=name, version=version)
Esempio n. 8
0
def ml_data_list(cmd, resource_group_name, workspace_name, name=None):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    return ml_client.data.list(name=name)
Esempio n. 9
0
def ml_compute_show(cmd, resource_group_name, workspace_name, name):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    return ml_client.computes.get(name=name)
Esempio n. 10
0
def ml_datastore_detach(cmd, resource_group_name, workspace_name,
                        datastore_name):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    return ml_client.datastores.delete(datastore_name)
Esempio n. 11
0
def ml_environment_list(cmd, resource_group_name, workspace_name):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    return ml_client.environments.list()
Esempio n. 12
0
def ml_datastore_show(cmd,
                      resource_group_name,
                      workspace_name,
                      datastore_name,
                      include_secrets=False):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(subscription_id=subscription_id,
                         resource_group_name=resource_group_name,
                         default_workspace_name=workspace_name)
    return ml_client.datastores.show(datastore_name,
                                     include_secrets=include_secrets)
Esempio n. 13
0
def ml_endpoint_list(cmd,
                     resource_group_name,
                     workspace_name,
                     type=ONLINE_ENDPOINT_TYPE):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    return ml_client.endpoints.list(type=type)
Esempio n. 14
0
def ml_job_stream(cmd, resource_group_name, workspace_name, name):

    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    try:
        ml_client.jobs.stream_logs(job_name=name)
    except Exception as err:
        print_error_and_exit(str(err))
Esempio n. 15
0
def ml_job_show(cmd, resource_group_name, workspace_name, name):

    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    try:
        job_yaml = ml_client.jobs.get(name)
        return dump_with_warnings(job_yaml)
    except Exception as err:
        print_error_and_exit(str(err))
Esempio n. 16
0
def ml_job_list(cmd, resource_group_name, workspace_name):

    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    try:
        job_list = ml_client.jobs.list()
        return list(map(lambda x: dump_with_warnings(ml_client, x), job_list))
    except Exception as err:
        print_error_and_exit(str(err))
Esempio n. 17
0
def ml_data_create(cmd,
                   resource_group_name,
                   workspace_name,
                   name=None,
                   version=None,
                   file=None):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    return ml_client.data.create_or_update(name=name,
                                           version=version,
                                           yaml_path=file)
Esempio n. 18
0
def _ml_job_update(cmd,
                   resource_group_name,
                   workspace_name,
                   parameters: Dict = None):

    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(subscription_id=subscription_id,
                         resource_group_name=resource_group_name,
                         default_workspace_name=workspace_name,
                         credential=AzureCliCredential())

    try:
        rest_obj = ml_client.jobs._submit(yaml_job=parameters)
        return rest_obj
    except Exception as err:
        print_error_and_exit(str(err))
Esempio n. 19
0
def ml_datastore_list(
    cmd,
    resource_group_name,
    workspace_name,
    include_secrets=False,
    skip_token=None,
    count=None,
    is_default=None,
    names=None,
    search_text=None,
    order_by=None,
    order_by_asc=None,
):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(subscription_id=subscription_id,
                         resource_group_name=resource_group_name,
                         default_workspace_name=workspace_name)
    return ml_client.datastores.list(include_secrets=include_secrets)
Esempio n. 20
0
def ml_environment_show(cmd,
                        resource_group_name,
                        workspace_name,
                        environment_name,
                        environment_version=None):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    if environment_version is None:
        return ml_client.environments.get_latest_version(
            environment_name=environment_name)
    return ml_client.environments.get(environment_name=environment_name,
                                      environment_version=environment_version)
Esempio n. 21
0
def ml_endpoint_get_deployment_logs(cmd,
                                    resource_group_name,
                                    workspace_name,
                                    name,
                                    deployment,
                                    tail,
                                    type=ONLINE_ENDPOINT_TYPE,
                                    container=None):
    subscription_id = get_subscription_id(cmd.cli_ctx)
    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )
    return ml_client.endpoints.get_deployment_logs(type=type,
                                                   endpoint_name=name,
                                                   deployment_name=deployment,
                                                   tail=tail,
                                                   container_type=container)
Esempio n. 22
0
def ml_data_upload(cmd,
                   resource_group_name,
                   workspace_name,
                   name,
                   version,
                   path,
                   datastore=None,
                   description=None):
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    return ml_client.data.upload(name=name,
                                 version=version,
                                 description=description,
                                 local_path=path,
                                 linked_service_name=datastore)
Esempio n. 23
0
def ml_job_create(cmd,
                  resource_group_name,
                  workspace_name,
                  name=None,
                  file=None,
                  save_as=None,
                  stream=False,
                  params_override=[]):

    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    try:
        if name is not None:
            params_override.append({"name": name})
        job = ml_client.jobs.submit(job_name=name,
                                    save_as_name=save_as,
                                    file=file,
                                    params_override=params_override)
        if stream:
            ml_client.jobs.stream_logs(job)
        return dump_with_warnings(ml_client, job)

    except Exception as err:
        if str(
                err
        ) is not None and "Only tags and properties can be updated." in str(
                err):
            print_error_and_exit(
                "(User error) A job with that name already exists. Use the --name option to provide a new name."
            )
        else:
            print_error_and_exit(str(err))
Esempio n. 24
0
def ml_environment_create(cmd,
                          resource_group_name,
                          workspace_name,
                          file,
                          environment_name=None,
                          params_override=None):
    # TODO : Once EMS supports accepting a version will enable it
    # environment_version=None
    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    return ml_client.environments.create_or_update(
        environment_name=environment_name,
        environment_version=None,
        file=file,
        params_override=params_override)
Esempio n. 25
0
def ml_code_create(cmd,
                   resource_group_name,
                   workspace_name,
                   name,
                   directory,
                   datastore_name=None,
                   version=None,
                   show_progress=True):

    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    return ml_client.code.create(name=name,
                                 directory=directory,
                                 version=version,
                                 datastore_name=datastore_name,
                                 show_progress=show_progress)
Esempio n. 26
0
def ml_job_download(cmd,
                    resource_group_name,
                    workspace_name,
                    name,
                    outputs=False,
                    download_path=None):

    subscription_id = get_subscription_id(cmd.cli_ctx)

    ml_client = MLClient(
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
        default_workspace_name=workspace_name,
        credential=AzureCliCredential(),
    )

    try:
        if not download_path:
            download_path = cmd.cli_ctx.local_context.current_dir
        return ml_client.jobs.download(job_name=name,
                                       logs_only=not outputs,
                                       download_path=download_path)
    except Exception as err:
        print_error_and_exit(str(err))
Esempio n. 27
0
 def test_set_default_workspace_name(self, mock_machinelearning_client: MLClient) -> None:
     default_ws = "default"
     mock_machinelearning_client.default_workspace_name = default_ws
     assert default_ws == mock_machinelearning_client.default_workspace_name