This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
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:
Create, enumerate, and cancel quantum jobs
Enumerate provider status and quotas
Source code |API reference documentation |Product documentation |Samples
This section includes everything a developer needs to install and create their first client connectionvery quickly.
Install the Azure Quantum Jobs client library for Javascript withnpm
:
npm install @azure/quantum-jobs
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.
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.
Create an instance of the QuantumJobClient by passing in these parameters:
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" } );
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();
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));
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);
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);
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(); }
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.
All Quantum Jobs service operations will throw a RequestFailedException on failure with helpful ErrorCodes. Many of these errors are recoverable.
Was this page helpful?
Was this page helpful?