Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

Azure Quantum Jobs client library for JavaScript - version 1.0.0-beta.1

  • 2023-10-03
Feedback

In this article

This package contains an isomorphic SDK for QuantumJobClient.

Azure Quantum is a Microsoft Azure service that you can use to run quantum computing programs or solve optimization problems in the cloud. Using the Azure Quantum tools and SDKs, you can create quantum programs and run them against different quantum simulators and machines. You can use the@azure/quantum-jobs client library to:

Getting started

This section includes everything a developer needs to install and create their first client connectionvery quickly.

Install the package

Install the Azure Quantum Jobs client library for Javascript withnpm:

npm install @azure/quantum-jobs

Prerequisites

Authenticate the client

To authenticate with the service, you can useDefaultAzureCredential from the@azure/identity library. This will try different authentication mechanisms based on the environment (e.g. Environment Variables, ManagedIdentity, CachedTokens) and finally, it will fallback to InteractiveBrowserCredential.

The client also allows the user to override the above behavior by passing their own implementations of theTokenCredential.

TokenCredential is the default Authentication mechanism used by Azure SDKs.

Key concepts

QuantumJobClient is the root class to be used to authenticate, and create, enumerate, and cancel jobs.

JobDetails contains all the properties of a job.

ProviderStatus contains status information for a provider.

QuantumJobQuota contains quota properties.

Examples

Create the client

Create an instance of the QuantumJobClient by passing in these parameters:

  • Subscription Id - looks like XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX and can be found in your list of subscriptions on azure
  • Resource Group Name - a container that holds related resources for an Azure solution
  • Workspace Name - a collection of assets associated with running quantum or optimization applications
  • Location - choose the best data center by geographical region
  • Storage Container Name - your blob storage
  • Credential - used to authenticate
    const credential = new DefaultAzureCredential();    // Create a QuantumJobClient    const subscriptionId = "your_subscription_id";    const resourceGroupName = "your_resource_group_name";    const workspaceName = "your_quantum_workspace_name";    const storageContainerName = "mycontainer";    const location = "westus"; //"your_location";    const endpoint = "https://" + location + ".quantum.azure.com";    const quantumJobClient = new QuantumJobClient(      credential,      subscriptionId,      resourceGroupName,      workspaceName,      {        endpoint: endpoint,        credentialScopes: "https://quantum.microsoft.com/.default"      }    );

Get Container SAS URI

Create a storage container to put your data.

    // Get container Uri with SAS key    const containerUri = (      await quantumJobClient.storage.sasUri({        containerName: storageContainerName      })    ).sasUri;    // Create container if not exists    const containerClient = new ContainerClient(containerUri);    await containerClient.createIfNotExists();

Upload Input Data

Using the SAS URI, upload the json input data to the blob client.This contains the parameters to be used withQuantum Inspired Optimizations

    // Get input data blob Uri with SAS key    const blobName = "myjobinput.json";    const inputDataUri = (      await quantumJobClient.storage.sasUri({        containerName: storageContainerName,        blobName: blobName      })    ).sasUri;    // Upload input data to blob    const blobClient = new BlockBlobClient(inputDataUri);    const problemFilename = "problem.json";    const fileContent = fs.readFileSync(problemFilename, "utf8");    await blobClient.upload(fileContent, Buffer.byteLength(fileContent));

Create The Job

Now that you've uploaded your problem definition to Azure Storage, you can usejobs.create to define an Azure Quantum job.

    const randomId = `${Math.floor(Math.random() * 10000 + 1)}`;    // Submit job    const jobId = `job-${randomId}`;    const jobName = `jobName-${randomId}`;    const inputDataFormat = "microsoft.qio.v2";    const outputDataFormat = "microsoft.qio-results.v2";    const providerId = "microsoft";    const target = "microsoft.paralleltempering-parameterfree.cpu";    const createJobDetails = {      containerUri: containerUri,      inputDataFormat: inputDataFormat,      providerId: providerId,      target: target,      id: jobId,      inputDataUri: inputDataUri,      name: jobName,      outputDataFormat: outputDataFormat    };    const createdJob = await quantumJobClient.jobs.create(jobId, createJobDetails);

Get Job

GetJob retrieves a specific job by its id.

    // Get the job that we've just created based on its jobId    const myJob = await quantumJobClient.jobs.get(jobId);

Get Jobs

To enumerate all the jobs in the workspace, use thejobs.list method.

    let jobListResult = await quantumJobClient.jobs.list();    let listOfJobs = await jobListResult.next();    while (!listOfJobs.done) {      let job = listOfJobs.value;      console.log(`  ${job.name}`);      listOfJobs = await jobListResult.next();    }

Next steps

Contributing

See theCONTRIBUTING.md for details on building,testing, and contributing to this library.

This project welcomes contributions and suggestions. Most contributions requireyou to agree to a Contributor License Agreement (CLA) declaring that you havethe right to, and actually do, grant us the rights to use your contribution. Fordetails, visitcla.microsoft.com.

This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQor contactopencode@microsoft.com with anyadditional questions or comments.

Troubleshooting

All Quantum Jobs service operations will throw a RequestFailedException on failure with helpful ErrorCodes. Many of these errors are recoverable.

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo