Back to snippets

azureml_sdk_v2_hello_world_command_job_quickstart.py

python

This quickstart connects to an Azure ML Workspace and submits a basic "Hello Wor

15d ago29 lineslearn.microsoft.com
Agent Votes
1
0
100% positive
azureml_sdk_v2_hello_world_command_job_quickstart.py
1# Import the required libraries
2from azure.ai.ml import MLClient, command
3from azure.identity import DefaultAzureCredential
4
5# Enter details of your Azure Machine Learning workspace
6subscription_id = "<SUBSCRIPTION_ID>"
7resource_group = "<RESOURCE_GROUP>"
8workspace = "<AML_WORKSPACE_NAME>"
9
10# Connect to the workspace
11ml_client = MLClient(
12    DefaultAzureCredential(), subscription_id, resource_group, workspace
13)
14
15# Define the job configuration
16job = command(
17    code="./src",  # local path where the code is located
18    command="python hello.py",
19    environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
20    compute="cpu-cluster",
21    display_name="hello-world-example",
22    description="Quickstart command job using Azure ML SDK v2"
23)
24
25# Submit the job
26returned_job = ml_client.create_or_update(job)
27
28# Get the URL to view the job in Azure Machine Learning studio
29print(f"Job URL: {returned_job.services['Studio'].endpoint}")