Workspace class

Definition

Workspace class manages the interactions with Azure Machine Learning Workspaces.

This class provides convenient methods for manipulating workspace resources and enumerating objects within. To see an example of creating a Workspace, viewing details, and writing a config file, follow the tutorial: https://docs.microsoft.com/en-us/azure/machine-learning/service/quickstart-create-workspace-with-python

Workspace(subscription_id, resource_group, workspace_name, auth=None, _location=None, _disable_service_check=False)
Inheritance
builtins.object
Workspace

Methods

create(name, auth=None, subscription_id=None, resource_group=None, location=None, create_resource_group=True, friendly_name=None, storage_account=None, key_vault=None, app_insights=None, container_registry=None, default_cpu_compute_target=<azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>, default_gpu_compute_target=<azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>, exist_ok=False, show_output=True)

Create a new Azure Machine Learning Workspace.

Throws an exception if the workspace already exists or any of the workspace requirements are not satisfied.

delete(delete_dependent_resources=False, no_wait=False)

Delete the Azure Workspace resource.

from_config(path=None, auth=None, _logger=None, _file_name=None)

Return a workspace object for an existing Azure Machine Learning Workspace.

Reads workspace configuration from a file.

The method provides a simple way of reusing the same workspace across multiple python notebooks or projects. Users can save the workspace ARM properties using the write_config function, and use this method to load the same workspace in different python notebooks or projects without retyping the workspace ARM properties.

get(name, auth=None, subscription_id=None, resource_group=None)

Return a workspace object for an existing Azure Machine Learning Workspace.

Throws an exception if the workspace doesn't exist or the required fields doesn't leads to a uniquely identifiable workspace.

get_default_compute_target(type)

Get the default compute target for the workspace.

get_default_datastore()

Get the default datastore for the workspace.

get_details()

Return details of this workspace.

list(subscription_id, auth=None, resource_group=None)

List all workspaces that the user has access to in the specified subscription_id parameter.

The list of workspaces can be filtered based on the resource group.

set_default_datastore(name)

Set the default datastore for the workspace.

setup()

Create a new workspace or retrieves an existing workspace.

write_config(path=None, file_name=None)

Write out the Workspace ARM properties to a config file.

Worspace ARM properties it can be loaded later using from_config. The path defaults to '.azureml/' in the current working directory and file_name defaults to 'config.json'.

The method provides a simple way of reusing the same workspace across multiple python notebooks or projects. Users can save the workspace ARM properties using this function, and use from_config to load the same workspace in different python notebooks or projects without retyping the workspace ARM properties.

create(name, auth=None, subscription_id=None, resource_group=None, location=None, create_resource_group=True, friendly_name=None, storage_account=None, key_vault=None, app_insights=None, container_registry=None, default_cpu_compute_target=<azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>, default_gpu_compute_target=<azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>, exist_ok=False, show_output=True)

Create a new Azure Machine Learning Workspace.

Throws an exception if the workspace already exists or any of the workspace requirements are not satisfied.

create(name, auth=None, subscription_id=None, resource_group=None, location=None, create_resource_group=True, friendly_name=None, storage_account=None, key_vault=None, app_insights=None, container_registry=None, default_cpu_compute_target=<azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>, default_gpu_compute_target=<azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>, exist_ok=False, show_output=True)

Parameters

name
str

The new workspace name. Workspace name has to be between 2 and 32 characters of letters and numbers.

auth
ServicePrincipalAuthentication or InteractiveLoginAuthentication

Authentication object. For more details refer to https://aka.ms/aml-notebook-auth. If None the default Azure CLI credentials will be used or the API will prompt for credentials.

default value: None
subscription_id
str

The subscription ID of the containing subscription for the new workspace. The parameter is required if the user has access to more than one subscription.

default value: None
resource_group
str

The Azure resource group that is containing the workspace. The parameter defaults to a mutation of the workspace name.

default value: None
location
str

The location of the workspace. The parameter defaults to the resource group location. The location has to be a supported region for Azure Machine Learning Services.

default value: None
create_resource_group
bool

When true the resource group will be created if it doesn't exist.

default value: True
friendly_name
str

A friendly name for the workspace that can be displayed in the UI.

default value: None
storage_account
str

An existing storage account in the Azure resource ID format. The storage will be used by the workspace to save run outputs, code, logs etc. If None a new storage will be created.

default value: None
key_vault
str

An existing key vault in the Azure resource ID format. The Key vault will be used by the workspace to store credentials added to the workspace by the users. If None a new key vault will be created.

default value: None
app_insights
str

An existing Application Insights in the Azure resource ID format. The Application Insights will be used by the workspace to log webservices events. If None a new Application Insights will be created.

default value: None
container_registry
str

An existing Container registery in the Azure resource ID format. The Container registery will be used by the workspace to pull and push both experimentation and webservices images. If None a new Container registery will be created only when needed and not along with workspace creation.

default value: None
default_cpu_compute_target
azureml.core.AmlCompute.AmlComputeProvisioningConfiguration

A configuration that will be used to create a CPU compute. The parameter defaults to {min_nodes=0, max_nodes=2, vm_size="STANDARD_DS2_V2", vm_priority="dedicated"} If None, no compute will be created.

default_gpu_compute_target
azureml.core.AmlCompute.AmlComputeProvisioningConfiguration

A configuration that will be used to create a GPU compute. The parameter defaults to {min_nodes=0, max_nodes=2, vm_size="STANDARD_NC6", vm_priority="dedicated"} If None, no compute will be created.

exist_ok
bool

If True the method will not fail if the workspace already exists.

default value: False
show_output
bool

If True the method will print out incremental progress of method

default value: True

Returns

The workspace object.

Return type

Remarks

This first example requires only minimal specification, and all dependent resources as well as the resource group will be created automatically.


   from azureml.core import Workspace
   ws = Workspace.create(name='myworkspace',
                         subscription_id='<azure-subscription-id>',
                         resource_group='myresourcegroup',
                         create_resource_group=True,
                         location='eastus2')

The following example shows how to reuse existing Azure resources by making use of all parameters utilizing the Azure resource ID format. The specific Azure resource IDs can be retrieved through the Azure Portal or SDK. This assumes that the resource group, storage account, key vault, App Insights and container registry already exist.


   import os
   from azureml.core import Workspace
   from azureml.core.authentication import ServicePrincipalAuthentication

   service_principal_password = os.environ.get("AZUREML_PASSWORD")

   service_principal_auth = ServicePrincipalAuthentication(
       tenant_id="<tenant-id>",
       username="<application-id>",
       password=service_principal_password)

   ws = Workspace.create(name='myworkspace',
                         auth=service_principal_auth,
                         subscription_id='<azure-subscription-id>',
                         resource_group='myresourcegroup',
                         create_resource_group=False,
                         location='eastus2',
                         friendly_name='My workspace',
                         storage_account='subscriptions/<azure-subscription-id>/resourcegroups/myresourcegroup/providers/microsoft.storage/storageaccounts/mystorageaccount',
                         key_vault='subscriptions/<azure-subscription-id>/resourcegroups/myresourcegroup/providers/microsoft.keyvault/vaults/mykeyvault',
                         app_insights='subscriptions/<azure-subscription-id>/resourcegroups/myresourcegroup/providers/microsoft.insights/components/myappinsights',
                         container_registry='subscriptions/<azure-subscription-id>/resourcegroups/myresourcegroup/providers/microsoft.containerregistry/registries/mycontainerregistry',
                         exist_ok=False)

delete(delete_dependent_resources=False, no_wait=False)

Delete the Azure Workspace resource.

delete(delete_dependent_resources=False, no_wait=False)

Parameters

delete_dependent_resources
bool

Set delete_dependent_resources=True for deleting workspace associated resources, i.e. ACR, storage account, key vault and application insights.

default value: False
no_wait
bool

Do not wait for the workspace deletion to complete.

default value: False

Returns

None if successful, otherwise throws an error.

Return type

from_config(path=None, auth=None, _logger=None, _file_name=None)

Return a workspace object for an existing Azure Machine Learning Workspace.

Reads workspace configuration from a file.

The method provides a simple way of reusing the same workspace across multiple python notebooks or projects. Users can save the workspace ARM properties using the write_config function, and use this method to load the same workspace in different python notebooks or projects without retyping the workspace ARM properties.

from_config(path=None, auth=None, _logger=None, _file_name=None)

Parameters

path
str

Path to the config file or starting directory for search. The parameter defaults to starting the search in the current directory.

default value: None
auth
ServicePrincipalAuthentication or InteractiveLoginAuthentication

Authentication object. For more details refer to https://aka.ms/aml-notebook-auth. If None the default Azure CLI credentials will be used or the API will prompt for credentials.

default value: None
_logger
Logger

optional logger

default value: None
_file_name
str

optional config file name to specify when path is a directory path.

default value: None

Returns

The workspace object for an existing Azure ML Workspace

Return type

get(name, auth=None, subscription_id=None, resource_group=None)

Return a workspace object for an existing Azure Machine Learning Workspace.

Throws an exception if the workspace doesn't exist or the required fields doesn't leads to a uniquely identifiable workspace.

get(name, auth=None, subscription_id=None, resource_group=None)

Parameters

name
str

The workspace name to get.

auth
ServicePrincipalAuthentication or InteractiveLoginAuthentication

Authentication object. For more details refer to https://aka.ms/aml-notebook-auth. If None the default Azure CLI credentials will be used or the API will prompt for credentials.

default value: None
subscription_id
str

The subscription ID to use. The parameter is required if the user has access to more than one subscription.

default value: None
resource_group
str

The resource group to use. If None the method will search all resource groups in the subscription.

default value: None

Returns

The workspace object.

Return type

get_default_compute_target(type)

Get the default compute target for the workspace.

get_default_compute_target(type)

Parameters

type

The type of compute, either CPU or GPU

Returns

The default compute target for given compute type

Return type

get_default_datastore()

Get the default datastore for the workspace.

get_default_datastore()

Returns

The default datastore

Return type

AzureFileDatastore
AzureBlobDatastore

get_details()

Return details of this workspace.

get_details()

Returns

Workspace details in dict format.

Return type

Remarks

The returned dictionary contains the following key-value pairs:

  • id: URI pointing to this workspace resource, containing

    subscription ID, resource group, and workspace name.

  • name: Name of this workspace.

  • location: Workspace region.

  • type: URI of the format "{providerName}/workspaces".

  • workspaceid: ID of this workspace.

  • description

  • friendlyName

  • creationTime: Time this workspace was created, in ISO8601.

  • containerRegistry

  • keyVault

  • applicationInsights

  • identityPrincipalId

  • identityTenantId

  • identityType

  • storageAccount

list(subscription_id, auth=None, resource_group=None)

List all workspaces that the user has access to in the specified subscription_id parameter.

The list of workspaces can be filtered based on the resource group.

list(subscription_id, auth=None, resource_group=None)

Parameters

subscription_id
str

To list workspaces in the specified subscription ID.

auth
ServicePrincipalAuthentication or InteractiveLoginAuthentication

Authentication object. For more details refer to https://aka.ms/aml-notebook-auth. If None the default Azure CLI credentials will be used or the API will prompt for credentials.

default value: None
resource_group
str

To list workspaces in the specified resource group. If None the method will list all the workspaces within the specified subscription.

default value: None

Returns

A dict, where the key is workspace name, and the value is a list of Workspace objects.

Return type

set_default_datastore(name)

Set the default datastore for the workspace.

set_default_datastore(name)

Parameters

name
str

The name of the datastore to be set as default

setup()

Create a new workspace or retrieves an existing workspace.

setup()

Returns

Workspace object

Return type

write_config(path=None, file_name=None)

Write out the Workspace ARM properties to a config file.

Worspace ARM properties it can be loaded later using from_config. The path defaults to '.azureml/' in the current working directory and file_name defaults to 'config.json'.

The method provides a simple way of reusing the same workspace across multiple python notebooks or projects. Users can save the workspace ARM properties using this function, and use from_config to load the same workspace in different python notebooks or projects without retyping the workspace ARM properties.

write_config(path=None, file_name=None)

Parameters

path
str

User provided location to write the config.json file. The parameter defaults to '.azureml/' in the current working directory.

default value: None
file_name
str

Name to use for the config file. The parameter defaults to config.json.

default value: None

Attributes

compute_targets

List all compute targets in the workspace.

Returns

Dict with key as compute target name and value as a ComputeTarget object.

Return type

dict{str:azureml.core.compute.ComputeTarget}

datasets

List all datasets in the workspace.

Returns

Dict with key as dataset name and value as dataset within the workspace.

Return type

dict{str: Dataset}

datastores

List all datastores in the workspace. List operation does not return credentials of the datastores.

Returns

Dict with key as datastore name and value as datastore within the workspace.

Return type

dict{str:(AzureFileDatastore
AzureBlobDatastore
AzureDataLakeDatastore)}

environments

List all environments in the workspace.

Returns

Dict with key as Environment name and value as the Environment object.

Return type

dict{str: azureml.core.environment.Environment}

experiments

List all experiments in the workspace.

Returns

Dict with key as experiment name and value as an Experiment object.

Return type

dict{str: azureml.core.experiment.Experiment}

images

Return a list of images in the Workspace.

Returns

Dict with key as image name and value as an Image object.

Return type

dict{str: azureml.core.image.image.Image}

location

Return the location of this workspace.

Returns

The location of this workspace.

Return type

str

models

Return a dict where the key is model name, and value is a Model object.

Returns

A dict of models.

Return type

dict{str: azureml.core.model.Model}

name

Return the workspace name.

Returns

Workspace name.

Return type

str

resource_group

Return the resource group name for this workspace.

Returns

Resource group name.

Return type

str

service_context

Return the Service Context for this workspace.

Returns

Returns the Service Context object.

Return type

azureml._restclient.service_context.ServiceContext

subscription_id

Return the subscription ID for this workspace.

Returns

Subscription id.

Return type

str

webservices

Return a list of webservices in the Workspace.

Returns

A list of Webservices in the Workspace

Return type

dict{str: azureml.core.webservice.Webservice}

DEFAULT_CPU_CLUSTER_CONFIGURATION

DEFAULT_CPU_CLUSTER_CONFIGURATION = <azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>

DEFAULT_CPU_CLUSTER_NAME

DEFAULT_CPU_CLUSTER_NAME = 'cpu-cluster'

DEFAULT_GPU_CLUSTER_CONFIGURATION

DEFAULT_GPU_CLUSTER_CONFIGURATION = <azureml.core.compute.amlcompute.AmlComputeProvisioningConfiguration object>

DEFAULT_GPU_CLUSTER_NAME

DEFAULT_GPU_CLUSTER_NAME = 'gpu-cluster'