Skip to content

Commit

Permalink
Update workspace sample notebook (#1929)
Browse files Browse the repository at this point in the history
* Update workspace sample notebook

* Fix errors in the sample notebook

* Update workspace.ipynb

* Update workspace.ipynb

fix code formatting

* update formatting>

* Update the sdk_helper to clear the hacks

* revert sdk_helper hacks

* Update workspace.ipynb

update ws name in the last cell for cleanup

* Update black formatting :*(

* Update kernelspec

* change to python310-sdkv2

Co-authored-by: Yisheng Yao <yishyao@microsoft.com>
  • Loading branch information
seanyao1 and Yisheng Yao committed Nov 30, 2022
1 parent ada2ad2 commit 2c82a35
Showing 1 changed file with 62 additions and 21 deletions.
83 changes: 62 additions & 21 deletions sdk/python/resources/workspace/workspace.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
" hbi_workspace=False,\n",
" tags=dict(purpose=\"demo\"),\n",
")\n",
"ml_client.workspaces.begin_create(ws_basic)"
"\n",
"ws_basic = ml_client.workspaces.begin_create(ws_basic).result()\n",
"print(ws_basic)"
]
},
{
Expand Down Expand Up @@ -160,20 +162,42 @@
" \"%Y%m%d%H%M\"\n",
")\n",
"\n",
"ws_with_existing = Workspace(\n",
"# Change the following variables to resource ids of your existing storage account, key vault, application insights\n",
"# and container registry. Here we reuse the ones we just created for the basic workspace\n",
"existing_storage_account = (\n",
" # e.g. \"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Storage/storageAccounts/<STORAGE_ACCOUNT>\"\n",
" ws_basic.storage_account\n",
")\n",
"existing_container_registry = (\n",
" # e.g. \"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerRegistry/registries/<CONTAINER_REGISTRY>\"\n",
" ws_basic.container_registry\n",
")\n",
"existing_key_vault = (\n",
" # e.g. \"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.KeyVault/vaults/<KEY_VAULT>\"\n",
" ws_basic.key_vault\n",
")\n",
"existing_application_insights = (\n",
" # e.g. \"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.insights/components/<APP_INSIGHTS>\"\n",
" ws_basic.application_insights\n",
")\n",
"\n",
"ws_with_existing_resources = Workspace(\n",
" name=basic_ex_workspace_name,\n",
" location=\"eastus\",\n",
" display_name=\"Bring your own dependent resources-example\",\n",
" description=\"This sample specifies a workspace configuration with existing dependent resources\",\n",
" storage_account=\"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Storage/storageAccounts/<STORAGE_ACCOUNT>\",\n",
" container_registry=\"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerRegistry/registries/<CONTAINER_REGISTRY>\",\n",
" key_vault=\"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.KeyVault/vaults/<KEY_VAULT>\",\n",
" application_insights=\"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.insights/components/<APP_INSIGHTS>\",\n",
" storage_account=existing_storage_account,\n",
" container_registry=existing_container_registry,\n",
" key_vault=existing_key_vault,\n",
" application_insights=existing_application_insights,\n",
" tags=dict(purpose=\"demonstration\"),\n",
")\n",
"\n",
"# uncomment this line after providing details of subscription, resource group and other details above\n",
"# ml_client.begin_create_or_update(ws_with_existing).result()"
"ws_with_existing_resources = ml_client.begin_create_or_update(\n",
" ws_with_existing_resources\n",
").result()\n",
"\n",
"print(ws_with_existing_resources)"
]
},
{
Expand All @@ -200,7 +224,7 @@
" \"mlw-privatelink-prod-\" + datetime.datetime.now().strftime(\"%Y%m%d%H%M\")\n",
")\n",
"\n",
"ws_private_link = Workspace(\n",
"ws_private = Workspace(\n",
" name=basic_private_link_workspace_name,\n",
" location=\"eastus\",\n",
" display_name=\"Private Link endpoint workspace-example\",\n",
Expand All @@ -210,7 +234,7 @@
" tags=dict(purpose=\"demonstration\"),\n",
")\n",
"\n",
"ml_client.workspaces.begin_create(ws_private_link)"
"ml_client.workspaces.begin_create(ws_private).result()"
]
},
{
Expand Down Expand Up @@ -307,8 +331,13 @@
"from azure.ai.ml.entities import Workspace\n",
"from azure.identity import DefaultAzureCredential\n",
"\n",
"# uncomment this line after providing details of subscription, resource group and workspace name\n",
"# ws = MLClient(DefaultAzureCredential(), subscription_id='<SUBSCRIPTION_ID>', resource_group_name='<RESOURCE_GROUP>', workspace_name='<AML_WORKSPACE_NAME>')"
"ws = MLClient(\n",
" DefaultAzureCredential(),\n",
" subscription_id=\"<SUBSCRIPTION_ID>\",\n",
" resource_group_name=\"<RESOURCE_GROUP>\",\n",
" workspace_name=\"<AML_WORKSPACE_NAME>\",\n",
")\n",
"print(ws)"
]
},
{
Expand All @@ -329,15 +358,25 @@
},
"outputs": [],
"source": [
"import json\n",
"from azure.ai.ml import MLClient\n",
"from azure.identity import DefaultAzureCredential\n",
"\n",
"# read the config from the current directory\n",
"# ws_from_config = MLClient.from_config()\n",
"# print(ws_from_config.workspace_name)\n",
"# create a demo config file \"my_config.json\" to be used in this example\n",
"# Data to be written\n",
"wsconfig = {\n",
" \"subscription_id\": subscription_id,\n",
" \"resource_group\": resource_group,\n",
" \"workspace_name\": ws_basic.name,\n",
"}\n",
"with open(\"my_config.json\", \"w\") as outfile:\n",
" json.dump(wsconfig, outfile)\n",
"\n",
"# read the config file from a specific directory\n",
"# ws_from_config_1 = MLClient.from_config(\"config/my_config.json\")\n",
"# print(ws_from_config_1.workspace_name)"
"# read the config from the current directory\n",
"ws_from_config = MLClient.from_config(\n",
" DefaultAzureCredential(), file_name=\"my_config.json\"\n",
")\n",
"print(ws_from_config.workspace_name)"
]
},
{
Expand All @@ -357,8 +396,10 @@
"outputs": [],
"source": [
"ml_client.workspaces.begin_delete(name=ws_basic.name, delete_dependent_resources=True)\n",
"# ml_client.workspaces.begin_delete(name=ws_with_existing.name, delete_dependent_resources=False)\n",
"# ml_client.workspaces.begin_delete(name=ws_private_link.name, delete_dependent_resources=True)"
"ml_client.workspaces.begin_delete(\n",
" name=ws_with_existing_resources.name, delete_dependent_resources=False\n",
")\n",
"ml_client.workspaces.begin_delete(name=ws_private.name, delete_dependent_resources=True)"
]
}
],
Expand All @@ -384,7 +425,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.12"
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 2c82a35

Please sign in to comment.