Skip to content

Commit f86284e

Browse files
Additional operations and test cases for Azure Quantum SDK (Azure#18239)
Co-authored-by: Victor XField <vxfield@outlook.com>
1 parent 2a0bbe9 commit f86284e

19 files changed

+4215
-96
lines changed

sdk/quantum/Azure.Quantum.Jobs/Azure.Quantum.Jobs.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Stress", "..\..\
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{0ED9C8A0-9A19-4750-8DD3-61D086288283}"
1515
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Quantum.Jobs.Samples", "samples\Azure.Quantum.Jobs.Samples.csproj", "{C48526E9-7F6A-494F-8193-3C050BD8E32E}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
3941
{0ED9C8A0-9A19-4750-8DD3-61D086288283}.Debug|Any CPU.Build.0 = Debug|Any CPU
4042
{0ED9C8A0-9A19-4750-8DD3-61D086288283}.Release|Any CPU.ActiveCfg = Release|Any CPU
4143
{0ED9C8A0-9A19-4750-8DD3-61D086288283}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Release|Any CPU.Build.0 = Release|Any CPU
4248
EndGlobalSection
4349
GlobalSection(SolutionProperties) = preSolution
4450
HideSolutionNode = FALSE

sdk/quantum/Azure.Quantum.Jobs/README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,71 @@ Each example in the *Examples* section starts with an H3 that describes the exam
5656

5757
The `get_thing` method retrieves a Thing from the service. The `id` parameter is the unique ID of the Thing, not its "name" property.
5858

59+
```C# Snippet:Azure_Quantum_Jobs_CreateClient
60+
// Create a QuantumJobClient
61+
var subscriptionId = "your_subscription_id";
62+
var resourceGroupName = "your_resource_group_name";
63+
var workspaceName = "your_quantum_workspace_name";
64+
var location = "your_location";
65+
var storageContainerName = "your_container_name";
66+
var credential = new DefaultAzureCredential(true);
67+
68+
var quantumJobClient =
69+
new QuantumJobClient(
70+
subscriptionId,
71+
resourceGroupName,
72+
workspaceName,
73+
location,
74+
credential);
75+
```
76+
77+
```C# Snippet:Azure_Quantum_Jobs_GetContainerSasUri
78+
// Get container Uri with SAS key
79+
var containerUri = (quantumJobClient.GetStorageSasUri(
80+
new BlobDetails(storageContainerName))).Value.SasUri;
81+
```
82+
83+
```C# Snippet:Azure_Quantum_Jobs_UploadInputData
84+
// Get input data blob Uri with SAS key
85+
string blobName = $"myjobinput.json";
86+
var inputDataUri = (quantumJobClient.GetStorageSasUri(
87+
new BlobDetails(storageContainerName)
88+
{
89+
BlobName = blobName,
90+
})).Value.SasUri;
91+
92+
// Upload input data to blob
93+
var blobClient = new BlobClient(new Uri(inputDataUri));
94+
var problemFilename = "problem.json";
95+
blobClient.Upload(problemFilename, overwrite: true);
96+
```
97+
98+
```C# Snippet:Azure_Quantum_Jobs_CreateJob
99+
// Submit job
100+
var jobId = $"job-{Guid.NewGuid():N}";
101+
var jobName = $"jobName-{Guid.NewGuid():N}";
102+
var inputDataFormat = "microsoft.qio.v2";
103+
var outputDataFormat = "microsoft.qio-results.v2";
104+
var providerId = "microsoft";
105+
var target = "microsoft.paralleltempering-parameterfree.cpu";
106+
var createJobDetails = new JobDetails(containerUri, inputDataFormat, providerId, target)
107+
{
108+
Id = jobId,
109+
InputDataUri = inputDataUri,
110+
Name = jobName,
111+
OutputDataFormat = outputDataFormat
112+
};
113+
JobDetails createdJob = (quantumJobClient.CreateJob(jobId, createJobDetails)).Value;
114+
```
115+
116+
```C# Snippet:Azure_Quantum_Jobs_GetJob
117+
// Get the job that we've just created based on its jobId
118+
JobDetails myJob = (quantumJobClient.GetJob(jobId)).Value;
119+
```
120+
59121
```C# Snippet:Azure_Quantum_Jobs_GetJobs
60-
var client = new QuantumJobClient("subscriptionId", "resourceGroupName", "workspaceName", "location");
61-
var jobs = client.GetJobs();
122+
// Get all jobs from the workspace (.ToList() will force all pages to be fetched)
123+
var allJobs = quantumJobClient.GetJobs().ToList();
62124
```
63125

64126
## Troubleshooting

sdk/quantum/Azure.Quantum.Jobs/api/Azure.Quantum.Jobs.netstandard2.0.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ public partial class QuantumJobClient
1616
{
1717
protected QuantumJobClient() { }
1818
public QuantumJobClient(string subscriptionId, string resourceGroupName, string workspaceName, string location, Azure.Core.TokenCredential credential = null, Azure.Quantum.QuantumJobClientOptions options = null) { }
19-
public virtual Azure.Response Cancel(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
20-
public virtual System.Threading.Tasks.Task<Azure.Response> CancelAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
21-
public virtual Azure.Response<Azure.Quantum.Jobs.Models.JobDetails> Create(string jobId, Azure.Quantum.Jobs.Models.JobDetails job, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
22-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Quantum.Jobs.Models.JobDetails>> CreateAsync(string jobId, Azure.Quantum.Jobs.Models.JobDetails job, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
19+
public virtual Azure.Response CancelJob(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
20+
public virtual System.Threading.Tasks.Task<Azure.Response> CancelJobAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
21+
public virtual Azure.Response<Azure.Quantum.Jobs.Models.JobDetails> CreateJob(string jobId, Azure.Quantum.Jobs.Models.JobDetails job, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
22+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Quantum.Jobs.Models.JobDetails>> CreateJobAsync(string jobId, Azure.Quantum.Jobs.Models.JobDetails job, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2323
public virtual Azure.Response<Azure.Quantum.Jobs.Models.JobDetails> GetJob(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2424
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Quantum.Jobs.Models.JobDetails>> GetJobAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2525
public virtual Azure.Pageable<Azure.Quantum.Jobs.Models.JobDetails> GetJobs(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2626
public virtual Azure.AsyncPageable<Azure.Quantum.Jobs.Models.JobDetails> GetJobsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
27+
public virtual Azure.Pageable<Azure.Quantum.Jobs.Models.ProviderStatus> GetProviderStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
28+
public virtual Azure.AsyncPageable<Azure.Quantum.Jobs.Models.ProviderStatus> GetProviderStatusAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29+
public virtual Azure.Pageable<Azure.Quantum.Jobs.Models.QuantumJobQuota> GetQuotas(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
30+
public virtual Azure.AsyncPageable<Azure.Quantum.Jobs.Models.QuantumJobQuota> GetQuotasAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
31+
public virtual Azure.Response<Azure.Quantum.Jobs.Models.SasUriResponse> GetStorageSasUri(Azure.Quantum.Jobs.Models.BlobDetails blobDetails, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
32+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Quantum.Jobs.Models.SasUriResponse>> GetStorageSasUriAsync(Azure.Quantum.Jobs.Models.BlobDetails blobDetails, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2733
}
2834
}
2935
namespace Azure.Quantum.Jobs.Models
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>Azure Quantum Jobs library samples</Description>
5+
<AssemblyTitle>Azure Quantum Jobs Samples</AssemblyTitle>
6+
<Version>1.0.0-beta.1</Version>
7+
<PackageTags>Azure;Quantum;Quantum Jobs</PackageTags>
8+
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
9+
<OutputType>Exe</OutputType>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\src\Azure.Quantum.Jobs.csproj" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Azure.Identity" />
18+
<PackageReference Include="Azure.Storage.Blobs" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<None Update="problem.json">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Linq;
6+
using Azure.Identity;
7+
using Azure.Quantum.Jobs.Models;
8+
using Azure.Storage.Blobs;
9+
10+
namespace Azure.Quantum.Jobs.Samples
11+
{
12+
public static class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
#region Snippet:Azure_Quantum_Jobs_CreateClient
17+
// Create a QuantumJobClient
18+
var subscriptionId = "your_subscription_id";
19+
var resourceGroupName = "your_resource_group_name";
20+
var workspaceName = "your_quantum_workspace_name";
21+
var location = "your_location";
22+
var storageContainerName = "your_container_name";
23+
var credential = new DefaultAzureCredential(true);
24+
25+
var quantumJobClient =
26+
new QuantumJobClient(
27+
subscriptionId,
28+
resourceGroupName,
29+
workspaceName,
30+
location,
31+
credential);
32+
#endregion
33+
34+
Console.WriteLine($@"Created QuantumJobClient for:
35+
SubscriptionId: {subscriptionId}
36+
ResourceGroup: {resourceGroupName}
37+
workspaceName: {workspaceName}
38+
location: {location}
39+
");
40+
41+
Console.WriteLine($@"Getting Container Uri with SAS key...");
42+
43+
#region Snippet:Azure_Quantum_Jobs_GetContainerSasUri
44+
// Get container Uri with SAS key
45+
var containerUri = (quantumJobClient.GetStorageSasUri(
46+
new BlobDetails(storageContainerName))).Value.SasUri;
47+
#endregion
48+
49+
Console.WriteLine($@"Container Uri with SAS key:
50+
{containerUri}
51+
");
52+
53+
Console.WriteLine($@"Creating Container if not exist...");
54+
55+
// Create container if not exists
56+
var containerClient = new BlobContainerClient(new Uri(containerUri));
57+
containerClient.CreateIfNotExists();
58+
59+
Console.WriteLine($@"Uploading data into a blob...");
60+
61+
#region Snippet:Azure_Quantum_Jobs_UploadInputData
62+
// Get input data blob Uri with SAS key
63+
string blobName = $"myjobinput.json";
64+
var inputDataUri = (quantumJobClient.GetStorageSasUri(
65+
new BlobDetails(storageContainerName)
66+
{
67+
BlobName = blobName,
68+
})).Value.SasUri;
69+
70+
// Upload input data to blob
71+
var blobClient = new BlobClient(new Uri(inputDataUri));
72+
var problemFilename = "problem.json";
73+
blobClient.Upload(problemFilename, overwrite: true);
74+
#endregion
75+
76+
Console.WriteLine($@"Input data Uri with SAS key:
77+
{inputDataUri}
78+
");
79+
80+
Console.WriteLine($@"Creating Quantum job...");
81+
82+
#region Snippet:Azure_Quantum_Jobs_CreateJob
83+
// Submit job
84+
var jobId = $"job-{Guid.NewGuid():N}";
85+
var jobName = $"jobName-{Guid.NewGuid():N}";
86+
var inputDataFormat = "microsoft.qio.v2";
87+
var outputDataFormat = "microsoft.qio-results.v2";
88+
var providerId = "microsoft";
89+
var target = "microsoft.paralleltempering-parameterfree.cpu";
90+
var createJobDetails = new JobDetails(containerUri, inputDataFormat, providerId, target)
91+
{
92+
Id = jobId,
93+
InputDataUri = inputDataUri,
94+
Name = jobName,
95+
OutputDataFormat = outputDataFormat
96+
};
97+
JobDetails createdJob = (quantumJobClient.CreateJob(jobId, createJobDetails)).Value;
98+
#endregion
99+
100+
Console.WriteLine($@"Job created:
101+
Id: {createdJob.Id}
102+
Name: {createdJob.Name}
103+
CreationTime: {createdJob.CreationTime}
104+
Status: {createdJob.Status}
105+
");
106+
107+
Console.WriteLine($@"Getting Quantum job...");
108+
109+
#region Snippet:Azure_Quantum_Jobs_GetJob
110+
// Get the job that we've just created based on its jobId
111+
JobDetails myJob = (quantumJobClient.GetJob(jobId)).Value;
112+
#endregion
113+
114+
Console.WriteLine($@"Job obtained:
115+
Id: {myJob.Id}
116+
Name: {myJob.Name}
117+
CreationTime: {myJob.CreationTime}
118+
Status: {myJob.Status}
119+
BeginExecutionTime: {myJob.BeginExecutionTime}
120+
EndExecutionTime: {myJob.EndExecutionTime}
121+
CancellationTime: {myJob.CancellationTime}
122+
OutputDataFormat: {myJob.OutputDataFormat}
123+
OutputDataUri: {myJob.OutputDataUri}
124+
");
125+
126+
Console.WriteLine($@"Getting list of Quantum jobs...");
127+
128+
#region Snippet:Azure_Quantum_Jobs_GetJobs
129+
// Get all jobs from the workspace (.ToList() will force all pages to be fetched)
130+
var allJobs = quantumJobClient.GetJobs().ToList();
131+
#endregion
132+
133+
Console.WriteLine($"{allJobs.Count} jobs found. Listing the first 10...");
134+
foreach (JobDetails job in allJobs.Take(10))
135+
{
136+
Console.WriteLine($" {job.Name}");
137+
}
138+
Console.WriteLine();
139+
140+
Console.WriteLine("Press [Enter] to exit...");
141+
Console.ReadLine();
142+
}
143+
}
144+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"cost_function": {
3+
"version": "1.0",
4+
"type": "ising",
5+
"terms": [
6+
{
7+
"c": -3,
8+
"ids": [ 1, 0 ]
9+
},
10+
{
11+
"c": 5,
12+
"ids": [ 2, 0 ]
13+
},
14+
{
15+
"c": 9,
16+
"ids": [ 2, 1 ]
17+
},
18+
{
19+
"c": 2,
20+
"ids": [ 3, 0 ]
21+
},
22+
{
23+
"c": -4,
24+
"ids": [ 3, 1 ]
25+
},
26+
{
27+
"c": 4,
28+
"ids": [ 3, 2 ]
29+
}
30+
]
31+
}
32+
}

sdk/quantum/Azure.Quantum.Jobs/src/Azure.Quantum.Jobs.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Description>Azure Quantum Client library that enables you to execute Quantum Jobs</Description>
4-
<AssemblyTitle>Azure SDK Template</AssemblyTitle>
3+
<Description>Azure Quantum Jobs library that enables you to submit and manage Quantum Jobs on Azure Quantum</Description>
4+
<AssemblyTitle>Azure Quantum Jobs</AssemblyTitle>
55
<Version>1.0.0-beta.1</Version>
66
<PackageTags>Azure;Quantum;Quantum Jobs</PackageTags>
77
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>

0 commit comments

Comments
 (0)