Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional operations and test cases for Azure Quantum SDK #18239

Merged
merged 17 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/quantum/Azure.Quantum.Jobs/Azure.Quantum.Jobs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Stress", "..\..\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{0ED9C8A0-9A19-4750-8DD3-61D086288283}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Quantum.Jobs.Samples", "samples\Azure.Quantum.Jobs.Samples.csproj", "{C48526E9-7F6A-494F-8193-3C050BD8E32E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{0ED9C8A0-9A19-4750-8DD3-61D086288283}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0ED9C8A0-9A19-4750-8DD3-61D086288283}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0ED9C8A0-9A19-4750-8DD3-61D086288283}.Release|Any CPU.Build.0 = Release|Any CPU
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C48526E9-7F6A-494F-8193-3C050BD8E32E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
66 changes: 64 additions & 2 deletions sdk/quantum/Azure.Quantum.Jobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,71 @@ Each example in the *Examples* section starts with an H3 that describes the exam

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

```C# Snippet:Azure_Quantum_Jobs_CreateClient
// Create a QuantumJobClient
var subscriptionId = "your_subscription_id";
var resourceGroupName = "your_resource_group_name";
var workspaceName = "your_quantum_workspace_name";
var location = "your_location";
var storageContainerName = "your_container_name";
var credential = new DefaultAzureCredential(true);

var quantumJobClient =
new QuantumJobClient(
subscriptionId,
resourceGroupName,
workspaceName,
location,
credential);
```

```C# Snippet:Azure_Quantum_Jobs_GetContainerSasUri
// Get container Uri with SAS key
var containerUri = (quantumJobClient.GetStorageSasUri(
new BlobDetails(storageContainerName))).Value.SasUri;
```

```C# Snippet:Azure_Quantum_Jobs_UploadInputData
// Get input data blob Uri with SAS key
string blobName = $"myjobinput.json";
var inputDataUri = (quantumJobClient.GetStorageSasUri(
new BlobDetails(storageContainerName)
{
BlobName = blobName,
})).Value.SasUri;

// Upload input data to blob
var blobClient = new BlobClient(new Uri(inputDataUri));
var problemFilename = "problem.json";
blobClient.Upload(problemFilename, overwrite: true);
```

```C# Snippet:Azure_Quantum_Jobs_CreateJob
// Submit job
var jobId = $"job-{Guid.NewGuid():N}";
var jobName = $"jobName-{Guid.NewGuid():N}";
var inputDataFormat = "microsoft.qio.v2";
var outputDataFormat = "microsoft.qio-results.v2";
var providerId = "microsoft";
var target = "microsoft.paralleltempering-parameterfree.cpu";
var createJobDetails = new JobDetails(containerUri, inputDataFormat, providerId, target)
{
Id = jobId,
InputDataUri = inputDataUri,
Name = jobName,
OutputDataFormat = outputDataFormat
};
JobDetails createdJob = (quantumJobClient.CreateJob(jobId, createJobDetails)).Value;
```

```C# Snippet:Azure_Quantum_Jobs_GetJob
// Get the job that we've just created based on its jobId
JobDetails myJob = (quantumJobClient.GetJob(jobId)).Value;
```

```C# Snippet:Azure_Quantum_Jobs_GetJobs
var client = new QuantumJobClient("subscriptionId", "resourceGroupName", "workspaceName", "location");
var jobs = client.GetJobs();
// Get all jobs from the workspace (.ToList() will force all pages to be fetched)
var allJobs = quantumJobClient.GetJobs().ToList();
```

## Troubleshooting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ public partial class QuantumJobClient
{
protected QuantumJobClient() { }
public QuantumJobClient(string subscriptionId, string resourceGroupName, string workspaceName, string location, Azure.Core.TokenCredential credential = null, Azure.Quantum.QuantumJobClientOptions options = null) { }
public virtual Azure.Response Cancel(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> CancelAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
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; }
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; }
public virtual Azure.Response CancelJob(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> CancelJobAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
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; }
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; }
public virtual Azure.Response<Azure.Quantum.Jobs.Models.JobDetails> GetJob(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
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; }
public virtual Azure.Pageable<Azure.Quantum.Jobs.Models.JobDetails> GetJobs(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AsyncPageable<Azure.Quantum.Jobs.Models.JobDetails> GetJobsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Quantum.Jobs.Models.ProviderStatus> GetProviderStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AsyncPageable<Azure.Quantum.Jobs.Models.ProviderStatus> GetProviderStatusAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Quantum.Jobs.Models.QuantumJobQuota> GetQuotas(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AsyncPageable<Azure.Quantum.Jobs.Models.QuantumJobQuota> GetQuotasAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
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; }
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; }
}
}
namespace Azure.Quantum.Jobs.Models
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Azure Quantum Jobs library samples</Description>
<AssemblyTitle>Azure Quantum Jobs Samples</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Azure;Quantum;Quantum Jobs</PackageTags>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\Azure.Quantum.Jobs.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Storage.Blobs" />
</ItemGroup>

<ItemGroup>
<None Update="problem.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
144 changes: 144 additions & 0 deletions sdk/quantum/Azure.Quantum.Jobs/samples/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Linq;
using Azure.Identity;
using Azure.Quantum.Jobs.Models;
using Azure.Storage.Blobs;

namespace Azure.Quantum.Jobs.Samples
{
public static class Program
{
public static void Main(string[] args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't block preview, but these should be changed to unit tests or we'll never run them.

{
#region Snippet:Azure_Quantum_Jobs_CreateClient
// Create a QuantumJobClient
var subscriptionId = "your_subscription_id";
var resourceGroupName = "your_resource_group_name";
var workspaceName = "your_quantum_workspace_name";
var location = "your_location";
var storageContainerName = "your_container_name";
var credential = new DefaultAzureCredential(true);

var quantumJobClient =
new QuantumJobClient(
subscriptionId,
resourceGroupName,
workspaceName,
location,
credential);
#endregion

Console.WriteLine($@"Created QuantumJobClient for:
SubscriptionId: {subscriptionId}
ResourceGroup: {resourceGroupName}
workspaceName: {workspaceName}
location: {location}
");

Console.WriteLine($@"Getting Container Uri with SAS key...");

#region Snippet:Azure_Quantum_Jobs_GetContainerSasUri
// Get container Uri with SAS key
var containerUri = (quantumJobClient.GetStorageSasUri(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the type of containerUri? The naming convention makes me think it's a Uri but the usage elesewhere makes me think it's a string. In the future we'll need to change the type of this property to Uri, but for now let's at least use string instead of var to make the usage clearer to customers.

new BlobDetails(storageContainerName))).Value.SasUri;
#endregion

Console.WriteLine($@"Container Uri with SAS key:
{containerUri}
");

Console.WriteLine($@"Creating Container if not exist...");

// Create container if not exists
var containerClient = new BlobContainerClient(new Uri(containerUri));
containerClient.CreateIfNotExists();

Console.WriteLine($@"Uploading data into a blob...");

#region Snippet:Azure_Quantum_Jobs_UploadInputData
// Get input data blob Uri with SAS key
string blobName = $"myjobinput.json";
var inputDataUri = (quantumJobClient.GetStorageSasUri(
new BlobDetails(storageContainerName)
{
BlobName = blobName,
})).Value.SasUri;
Comment on lines +64 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit - remove all these extra parens around the method calls and change your indentation to look more like

Suggested change
var inputDataUri = (quantumJobClient.GetStorageSasUri(
new BlobDetails(storageContainerName)
{
BlobName = blobName,
})).Value.SasUri;
var inputDataUri = quantumJobClient.GetStorageSasUri(
new BlobDetails(storageContainerName) { BlobName = blobName, })
.Value.SasUri;


// Upload input data to blob
var blobClient = new BlobClient(new Uri(inputDataUri));
var problemFilename = "problem.json";
blobClient.Upload(problemFilename, overwrite: true);
#endregion

Console.WriteLine($@"Input data Uri with SAS key:
{inputDataUri}
");

Console.WriteLine($@"Creating Quantum job...");

#region Snippet:Azure_Quantum_Jobs_CreateJob
// Submit job
var jobId = $"job-{Guid.NewGuid():N}";
var jobName = $"jobName-{Guid.NewGuid():N}";
var inputDataFormat = "microsoft.qio.v2";
var outputDataFormat = "microsoft.qio-results.v2";
var providerId = "microsoft";
var target = "microsoft.paralleltempering-parameterfree.cpu";
var createJobDetails = new JobDetails(containerUri, inputDataFormat, providerId, target)
{
Id = jobId,
InputDataUri = inputDataUri,
Name = jobName,
OutputDataFormat = outputDataFormat
};
JobDetails createdJob = (quantumJobClient.CreateJob(jobId, createJobDetails)).Value;
#endregion

Console.WriteLine($@"Job created:
Id: {createdJob.Id}
Name: {createdJob.Name}
CreationTime: {createdJob.CreationTime}
Status: {createdJob.Status}
");

Console.WriteLine($@"Getting Quantum job...");

#region Snippet:Azure_Quantum_Jobs_GetJob
// Get the job that we've just created based on its jobId
JobDetails myJob = (quantumJobClient.GetJob(jobId)).Value;
#endregion

Console.WriteLine($@"Job obtained:
Id: {myJob.Id}
Name: {myJob.Name}
CreationTime: {myJob.CreationTime}
Status: {myJob.Status}
BeginExecutionTime: {myJob.BeginExecutionTime}
EndExecutionTime: {myJob.EndExecutionTime}
CancellationTime: {myJob.CancellationTime}
OutputDataFormat: {myJob.OutputDataFormat}
OutputDataUri: {myJob.OutputDataUri}
");

Console.WriteLine($@"Getting list of Quantum jobs...");

#region Snippet:Azure_Quantum_Jobs_GetJobs
// Get all jobs from the workspace (.ToList() will force all pages to be fetched)
var allJobs = quantumJobClient.GetJobs().ToList();
matusthemostlygreat marked this conversation as resolved.
Show resolved Hide resolved
#endregion

Console.WriteLine($"{allJobs.Count} jobs found. Listing the first 10...");
foreach (JobDetails job in allJobs.Take(10))
{
Console.WriteLine($" {job.Name}");
}
Console.WriteLine();

Console.WriteLine("Press [Enter] to exit...");
Console.ReadLine();
}
}
}
32 changes: 32 additions & 0 deletions sdk/quantum/Azure.Quantum.Jobs/samples/problem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"cost_function": {
"version": "1.0",
"type": "ising",
"terms": [
{
"c": -3,
"ids": [ 1, 0 ]
},
{
"c": 5,
"ids": [ 2, 0 ]
},
{
"c": 9,
"ids": [ 2, 1 ]
},
{
"c": 2,
"ids": [ 3, 0 ]
},
{
"c": -4,
"ids": [ 3, 1 ]
},
{
"c": 4,
"ids": [ 3, 2 ]
}
]
}
}
4 changes: 2 additions & 2 deletions sdk/quantum/Azure.Quantum.Jobs/src/Azure.Quantum.Jobs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Azure Quantum Client library that enables you to execute Quantum Jobs</Description>
<AssemblyTitle>Azure SDK Template</AssemblyTitle>
<Description>Azure Quantum Jobs library that enables you to submit and manage Quantum Jobs on Azure Quantum</Description>
<AssemblyTitle>Azure Quantum Jobs</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Azure;Quantum;Quantum Jobs</PackageTags>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
Expand Down
Loading