<jupyter_start><jupyter_text>Run published pipeline using its REST endpoint To invoke the run of the preceding pipeline, you need an Azure Active Directory authentication header token, as described in AzureCliAuthentication class.In mlops-publish-pipeline notebook you built and published a pipeline of your experiment, now you in this notebook you would like to execute/invoke this published pipeline via REST endpoint  Imports<jupyter_code>import os
import sys
import requests
import azureml.core
import warnings
warnings.filterwarnings('ignore')

from azureml.core import Experiment, Workspace
from azureml.widgets import RunDetails
from azureml.pipeline.core import PipelineEndpoint, PublishedPipeline
from azureml.pipeline.core import PublishedPipeline, PipelineRun
from azureml.core.authentication import InteractiveLoginAuthentication

sys.path.append(os.path.abspath("../utils"))
from workspace import get_workspace
from pipeline_parameter_builder import PipelineParameterBuilder<jupyter_output><empty_output><jupyter_text>Initialize Workspace Now you're ready to connect to your workspace using the Azure ML SDK.Note: If the authenticated session with your Azure subscription has expired since you completed the previous exercise, you'll be prompted to reauthenticate.<jupyter_code>ws = Workspace.from_config("../notebooks-settings/config.json")
print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep = '\n')<jupyter_output><empty_output><jupyter_text>Pipeline Parameter Builder<jupyter_code>ppb = PipelineParameterBuilder("../utils/params_config/pipeline_parameters.json")
ppb.build()<jupyter_output><empty_output><jupyter_text>Create request pipeline parameters<jupyter_code>pipeline_parameters = {
            "ExperimentName": "heart-disease",
            "RunSource": "",
            "ParameterAssignments": ppb.get_raw_pipeline_parameters()
}
pipeline_parameters<jupyter_output><empty_output><jupyter_text>Create REST request To use the endpoint, client applications need to make a REST call over HTTP. This request must be authenticated, so an authorization header is required. A real application would require a service principal with which to be authenticated, but to test this out, we'll use the authorization header from your current connection to your Azure workspace, which you can get using the following code:<jupyter_code>cli_auth = InteractiveLoginAuthentication()
aad_token = cli_auth.get_authentication_header()

pipeline_endpoint = PipelineEndpoint.get(workspace=ws, name="responsible_ai_v1")

print("The published pipeline REST endpoint is {}".format(pipeline_endpoint))<jupyter_output><empty_output><jupyter_text>Now we're ready to call the REST interface. The pipeline runs asynchronously, so we'll get an identifier back, which we can use to track the pipeline experiment as it runs:<jupyter_code>response = requests.post(pipeline_endpoint.endpoint,
                         headers=aad_token,
                         json=pipeline_parameters
                        )
pipeline_run_id = response.json()["Id"]<jupyter_output><empty_output><jupyter_text>Examine the REST execution runSince we have the run ID, we can use the RunDetails widget. We can examine the run of the pipeline that we just invoked via the REST endpoint.<jupyter_code>pub_pipeline_run = PipelineRun(Experiment(ws, "heart-disease"), pipeline_run_id)
RunDetails(pub_pipeline_run).show()<jupyter_output><empty_output><jupyter_text>Get additonal run detailsIf you wait until the pipeline_run is finished, you may be able to get additional details on the run. **Since this is a blocking call, the following code is commented out.**<jupyter_code>pub_pipeline_run.wait_for_completion()
for step_run in pub_pipeline_run.get_children():
    print("{}: {}".format(step_run.name, step_run.get_metrics()))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07233931824095759, 'fraction_numerical': 0.00026021337496747333, 'mean_word_length': 6.131725417439704, 'pattern_counts': {'":': 3, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '247312', 'license': 'MIT', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1030, 'n_words': 342, 'path': 'src/mlops-pipeline/mlops-submit-pipeline.ipynb', 'repo_name': 'sidcmsft/ResponsibleAI', 'size': '3843'}