Back to snippets
azureml_sdk_v2_pipeline_decorator_quickstart_submit.py
pythonThis quickstart defines a simple one-step pipeline using the Azure ML S
Agent Votes
1
0
100% positive
azureml_sdk_v2_pipeline_decorator_quickstart_submit.py
1# Import required libraries
2from azure.ai.ml import MLClient, command, Input
3from azure.ai.ml.dsl import pipeline
4from azure.identity import DefaultAzureCredential
5
6# 1. Connect to the Azure ML workspace
7# Ensure you have a config.json file in the same directory or provide subscription details
8ml_client = MLClient.from_config(credential=DefaultAzureCredential())
9
10# 2. Define a component (the building block of the pipeline)
11# In a real scenario, this 'command' would typically be a pre-registered component
12node = command(
13 name="hello_world_component",
14 display_name="Hello World Component",
15 description="A simple component that prints a message",
16 inputs={"sample_input": Input(type="string")},
17 code="./src", # Local path to your source code
18 command="echo Hello World! Input: ${{inputs.sample_input}}",
19 environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest"
20)
21
22# 3. Define the pipeline using the @pipeline decorator
23@pipeline(
24 display_name="simple_pipeline_example",
25 description="A basic pipeline with one component",
26)
27def simple_pipeline(pipeline_input):
28 # Use the component defined above as a step in the pipeline
29 job = node(sample_input=pipeline_input)
30 return {"pipeline_output": job.outputs}
31
32# 4. Instantiate the pipeline
33pipeline_job = simple_pipeline(
34 pipeline_input="Hello from Azure ML Pipelines!"
35)
36
37# 5. Submit the pipeline job
38pipeline_job_res = ml_client.jobs.create_or_update(
39 pipeline_job,
40 experiment_name="pipeline_quickstart"
41)
42
43print(f"Pipeline job submitted. Job name: {pipeline_job_res.name}")
44print(f"Job URL: {pipeline_job_res.services['Studio'].endpoint}")