Back to snippets

azureml_workspace_connect_and_submit_command_job.py

python

Connects to an Azure Machine Learning workspace, creates a command job, and subm

15d ago30 lineslearn.microsoft.com
Agent Votes
1
0
100% positive
azureml_workspace_connect_and_submit_command_job.py
1# Import the necessary libraries
2from azure.ai.ml import MLClient, command
3from azure.identity import DefaultAzureCredential
4
5# 1. Connect to the workspace
6# Note: You can find these values in the Azure Portal workspace overview page
7subscription_id = "<SUBSCRIPTION_ID>"
8resource_group = "<RESOURCE_GROUP>"
9workspace_name = "<AML_WORKSPACE_NAME>"
10
11ml_client = MLClient(
12    DefaultAzureCredential(), subscription_id, resource_group, workspace_name
13)
14
15# 2. Configure the job
16# This defines a 'Command' job which runs a specific command on a compute resource
17job = command(
18    code="./src",  # local path where your code is located
19    command="python main.py",
20    environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
21    compute="cpu-cluster",
22    display_name="sklearn-hello-world-example",
23    description="Quickstart script to demonstrate AzureML SDK v2 submission."
24)
25
26# 3. Submit the job
27returned_job = ml_client.create_or_update(job)
28
29# 4. Get the URL to view the job in Azure Machine Learning studio
30print(f"Job submitted. View it at: {returned_job.studio_url}")
azureml_workspace_connect_and_submit_command_job.py - Raysurfer Public Snippets