Getting Notified when an Azure Quantum Job Completes

Learn how to use Azure Event Grid to trigger actions (e.g. send out an email) as soon as an Azure Quantum job completes.

Jobs that get submitted to Azure Quantum are always queued before a target system processes it. This creates some overhead to the overall runtime of jobs. You’d like to get notified when an Azure Quantum job completes? Or trigger another action? In this blog, I’ll show you how to use Azure Event Grid and Logic Apps to send out an email as soon as an Azure Quantum job completes. All without any coding!

Prerequisites

Fist and foremost, you need an Azure Quantum Workspace in an Azure Subscription accessible to you. If you don’t have any of that, just start with a free account that comes with US$200 Azure credits. When you create an Azure Quantum workspace there, you’ll get an additional US$500 in credits with each Azure Quantum hardware partner.

The approach described in this blog requires that the storage account associated to your quantum workspace is of type ‘general purpose v2’. Unfortunately, older versions don’t support the event management system needed for triggering Logic Apps and the Quick Path for creating a workspace generates a v1-storage account. If you still have a v1-storage account, you’ll need to upgrade it to a v2-storage account. If you followed the guidance for creating workspaces with ARM templates, you should already have the right version.

Step-by-step Guide

The following guide explains step-by-step how to set everything up in the Azure Portal so that you get email notifications when an Azure Quantum job completes.

Create an empty http-triggered Logic App

  1. Navigate to the resource group where your quantum workspace resides.
  2. Click on + Create and enter Logic App in the search field. Select the Logic App-entry click on Create.
  3. Enter basic information for the Logic App.
    Subscription: leave the selected subscription.
    Resource Group: leave the selected group.
    Logic App Name: enter a name for your app.
    Region: select the region of your quantum workspace.
    Enable log analytics: No.
    Plan: Consumption.
  4. Click on Review + Create.
  5. Verify your entries and confirm with Create.
    After a few seconds your Logic App should be provisioned.
  6. Click on Go to resource.
  7. This opens the Logic Apps Designer, which offers you several templates for Logic Apps.
  8. Select When a HTTP request is received.
  9. Click on Save. This not only saves the empty Logic App but also generates the URL the Logic App can be called under.

The empty Logic App with the auto-generated URL
The empty Logic App with the auto-generated URL

  1. Copy the URL to a safe location as you’ll need it later to properly configure Event Grid.

Create an Event Grid System Topic

  1. Navigate back to the resource group where your quantum workspace resides.
  2. Click on + Create and enter Event Grid System Topic in the search field. Select the Event Grid System Topic-entry click on Create.
  3. Enter basic information for the topic.
    Topic Types: Storage Accounts (Blob & GPv2).
    Subscription: selected your subscription.
    Resource Group: leave the selected group.
    Resource: select the storage account associated to the quantum workspace.
    Name: rawOutputData-created
  4. Click on Review + Create
  5. Verify your entries and confirm with Create.
    After a few seconds your System Topic should be provisioned.
  6. Click on Go to resource.

Connect the Event Grid Topic to the Logic App

  1. On the System Topic page click on + Event Subscription
  2. Enter basic information for the subscription.
    Name: send-email
    Event Schema: Event Grid Schema
    Filter to Event Types: select Blob Created and unselect all other event types.
    Endpoint Type: Web Hook
    Endpoint: Fill in the Logic App URL you copied above.
  3. Confirm by clicking on Create.
  4. Click on the send-email subscription and navigate to the Filters-tab.
  5. Check Enable subject filtering and fill in subject data.
    Subject Begins With: /blobServices/default/containers/job-
    Subject Ends With: rawOutputData

Subject filters in the Event Grid subscription
Subject filters in the Event Grid subscription

Configure the Logic App for sending Emails

  1. Return to the Logic App you created above and click on Edit.
  2. Click on + New step to add the fist action that will be performed when the Logic App gets triggered. It will extract the blob-URL from the trigger request.
  3. Choose an Initialize Variable-operation and configure its parameters.
    Name: blobUrl Type: String Value: click on Add dynamic content, select the Expression-tab, and enter triggerBody()[0]['data']['url'].
  4. Confirm with OK.
  5. Click on + New step to add another action. This action will extract the quantum job id from the blob-URL.
  6. Choose an Initialize Variable-operation and configure its parameters.
    Name: blobUrl Type: String Value: click on Add dynamic content, select the Expression-tab, and enter substring(variables('blobUrl'), add(lastIndexOf(variables('blobUrl'), 'job-'), 4), 36).
  7. Confirm with OK.
  8. Click on + New step to add the third and final action. This action will send the email.
  9. Choose the Outlook.com connector and select the Send an email (V2)-operation. The operation will ask you to authenticate to Outlook.com.

Request to sign in to Outlook.com
Request to sign in to Outlook.com

  1. After sign in successfully completes, parameters of the operation will be revealed. Fill in as follows:
    To: email addresses of all recipients of the emails
    Subject: Job completed:, add an expression variables('jobId')
    Body: Congratulations! Your quantum job has completed. ID:, add an expression variables('jobId')

The final step of your Logic App should look similar to the following

Send email operation with all fields filled in
Send email operation with all fields filled in

Test your notifications

That’s it! Setup should be completed. It’s now time to test everything. Just submit a quantum job and watch your email inbox. Both a quantum computing job or an optimization job will do. As soon as the job has completed and has written the result data, you should receive an email similar to the following.

Sample notification email
Sample notification email

Conclusion

The approach described in this article can be reused for different solutions. The Logic Apps approach is very flexible, allowing you to harness the power of all the connectors available there. So you can trigger many other types of systems. For event driven architectures you can use the power of Event Grid as an event distributor. Just register other types of event handlers that react to the creation of quantum job results.