Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
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
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"msbuild-sdks": {
"Microsoft.Quantum.Sdk": "0.16.2105143425-alpha"
"Microsoft.Quantum.Sdk": "0.17.2106145735-alpha"
}
}
9 changes: 6 additions & 3 deletions src/Azure/Azure.Quantum.Client.Test/Helpers/Problem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -54,12 +57,12 @@ public void Add(int i, float c)

public void Add(int i, int j, float c)
{
terms.Add(new Term( new int[] { i, j }, c));
terms.Add(new Term(new int[] { i, j }, c));
}

public void Add(int i, int j, int k, float c)
{
terms.Add(new Term( new int[] { i, j, k }, c));
terms.Add(new Term(new int[] { i, j, k }, c));
}

public void AddRange(IEnumerable<Term> collection)
Expand Down
15 changes: 0 additions & 15 deletions src/Azure/Azure.Quantum.Client.Test/Helpers/TestConstants.cs

This file was deleted.

70 changes: 59 additions & 11 deletions src/Azure/Azure.Quantum.Client.Test/WorkspaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -21,8 +22,20 @@ namespace Microsoft.Azure.Quantum.Test
[TestClass]
public class WorkspaceTest
{
private const string SETUP = @"
Live tests require you to configure your environment with these variables:
* E2E_WORKSPACE_NAME: the name of an Azure Quantum workspace to use for live testing.
* E2E_SUBSCRIPTION_ID: the Azure Quantum workspace's Subscription Id.
* E2E_WORKSPACE_RG: the Azure Quantum workspace's resource group.
* E2E_WORKSPACE_LOCATION: the Azure Quantum workspace's location (region).

You'll also need to authenticate with Azure using any of the methods listed in:
https://docs.microsoft.com/en-us/dotnet/api/overview/azure/identity-readme#authenticate-the-client

Tests will be marked as Inconclusive if the pre-reqs are not correctly setup.";

[TestMethod]
[Ignore]
[TestCategory("Live")]
public async Task SubmitJobTest()
{
// Create Job
Expand All @@ -41,7 +54,7 @@ public async Task SubmitJobTest()
}

[TestMethod]
[Ignore]
[TestCategory("Live")]
public async Task GetJobTest()
{
IWorkspace workspace = GetLiveWorkspace();
Expand All @@ -61,7 +74,7 @@ public async Task GetJobTest()
}

[TestMethod]
[Ignore]
[TestCategory("Live")]
public async Task CancelJobTest()
{
// Create Job
Expand All @@ -82,7 +95,7 @@ public async Task CancelJobTest()
}

[TestMethod]
[Ignore]
[TestCategory("Live")]
public async Task ListJobsTest()
{
IWorkspace workspace = GetLiveWorkspace();
Expand Down Expand Up @@ -110,7 +123,7 @@ public async Task ListJobsTest()
}

[TestMethod]
[Ignore]
[TestCategory("Live")]
public async Task ListQuotasTest()
{
IWorkspace workspace = GetLiveWorkspace();
Expand All @@ -121,8 +134,35 @@ public async Task ListQuotasTest()
await foreach (var q in workspace.ListQuotasAsync())
{
Assert.IsNotNull(q);
Assert.IsNotNull(q.Quota);
Assert.IsNotNull(q.Quota.Dimension);
Assert.IsNotNull(q.ProviderId);
Assert.IsNotNull(q.Dimension);

max--;
if (max <= 0)
{
break;
}
}

// Make sure we iterated through all the expected jobs:
Assert.AreEqual(0, max);
}

[TestMethod]
[TestCategory("Live")]
public async Task ListProviderStatusTest()
{
IWorkspace workspace = GetLiveWorkspace();
int max = 1;

// Since this is a live workspace, we don't have much control about what quotas are in there
// Just make sure there is more than one.
await foreach (var s in workspace.ListProvidersStatusAsync())
{
Assert.IsNotNull(s);
Assert.IsNotNull(s.ProviderId);
Assert.IsNotNull(s.Targets);
Assert.IsTrue(s.Targets.Any());

max--;
if (max <= 0)
Expand All @@ -146,14 +186,22 @@ private static void AssertJob(CloudJob job)

private IWorkspace GetLiveWorkspace()
{
if (string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("E2E_SUBSCRIPTION_ID")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_RG")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_NAME")) ||
string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("E2E_SUBSCRIPTION_ID")))
{
Assert.Inconclusive(SETUP);
}

var options = new QuantumJobClientOptions();
options.Diagnostics.ApplicationId = "ClientTests";

return new Workspace(
subscriptionId: System.Environment.GetEnvironmentVariable("E2E_SUBSCRIPTION_ID") ?? TestConstants.LiveSubscriptionId,
resourceGroupName: System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_RG") ?? TestConstants.LiveResourceGroupName,
workspaceName: System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_NAME") ?? TestConstants.LiveWorkspaceName,
location: System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_LOCATION") ?? TestConstants.LiveLocation,
subscriptionId: System.Environment.GetEnvironmentVariable("E2E_SUBSCRIPTION_ID"),
resourceGroupName: System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_RG"),
workspaceName: System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_NAME"),
location: System.Environment.GetEnvironmentVariable("E2E_WORKSPACE_LOCATION"),
options: options);
}

Expand Down
29 changes: 28 additions & 1 deletion src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public CloudJob(IWorkspace workspace, JobDetails jobDetails)
/// </summary>
public virtual string Id => Details.Id;

/// <summary>
/// Gets the job id.
/// </summary>
public virtual string Name => Details.Name;

/// <summary>
/// Gets whether the job execution has completed.
/// </summary>
Expand Down Expand Up @@ -70,7 +75,29 @@ public CloudJob(IWorkspace workspace, JobDetails jobDetails)
public virtual IWorkspace Workspace { get; private set; }

/// <summary>
/// Gets the job details.
/// Gets or sets the unique identifier for the provider.
/// </summary>
public virtual string ProviderId => this.Details?.ProviderId;

/// <summary>
/// Gets or sets the target identifier to run the job.
/// </summary>
public string Target => this.Details.Target;

/// <summary>
/// If available, returns Uri with the results of the execution.
/// </summary>>
public virtual Uri OutputDataUri => (this.Details?.OutputDataUri != null)
? new Uri(this.Details.OutputDataUri)
: null;

/// <summary>
/// If available, returns the data format of the execution results.
/// </summary>
public virtual string OutputDataFormat => this.Details?.OutputDataFormat;

/// <summary>
/// Gets the underlying job details.
/// </summary>
public virtual JobDetails Details { get; private set; }

Expand Down
48 changes: 41 additions & 7 deletions src/Azure/Azure.Quantum.Client/JobManagement/IWorkspace.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Quantum.Runtime;

namespace Microsoft.Azure.Quantum
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using global::Azure.Quantum.Jobs;

/// <summary>
/// IWorkspace interface.
/// </summary>
public interface IWorkspace
{
/// <summary>
/// The Workspace's Azure Subscription.
/// </summary>
string SubscriptionId { get; }

/// <summary>
/// The Workspace's resource group in Azure.
/// </summary>
string ResourceGroupName { get; }

/// <summary>
/// The Workspace's location (region) in Azure.
/// </summary>
string Location { get; }

/// <summary>
/// The Workspace's name.
/// </summary>
string WorkspaceName { get; }

/// <summary>
/// The low-level client used to communicate with the service.
/// </summary>
public QuantumJobClient Client { get; }

/// <summary>
/// Submits the job.
/// </summary>
Expand Down Expand Up @@ -47,18 +73,26 @@ Task<CloudJob> GetJobAsync(
/// Lists the jobs.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>List of jobs</returns>
/// <returns>List of jobs.</returns>
IAsyncEnumerable<CloudJob> ListJobsAsync(
CancellationToken cancellationToken = default);

/// <summary>
/// Returns the list of quotas for a workspace.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>List of jobs</returns>
/// <returns>List of quotas.</returns>
IAsyncEnumerable<QuotaInfo> ListQuotasAsync(
CancellationToken cancellationToken = default);

/// <summary>
/// Returns a list with the status of each of the Providers in a workspace
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>List of provider status.</returns>
IAsyncEnumerable<ProviderStatusInfo> ListProvidersStatusAsync(
CancellationToken cancellationToken = default);

/// <summary>
/// Gets as SAS Uri for the storage account associated with the workspace.
/// </summary>
Expand Down
78 changes: 78 additions & 0 deletions src/Azure/Azure.Quantum.Client/JobManagement/ProviderStatusInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable enable

namespace Microsoft.Azure.Quantum
{
using System.Collections.Generic;

using Microsoft.Azure.Quantum.Utility;

using Models = global::Azure.Quantum.Jobs.Models;

/// <summary>
/// Wrapper for Azure.Quantum.Jobs.Models.ProviderStatus.
/// </summary>
public class ProviderStatusInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="ProviderStatusInfo"/> class.
/// </summary>
/// <param name="workspace">The workspace.</param>
/// <param name="status">The provider status details.</param>
public ProviderStatusInfo(IWorkspace workspace, Models.ProviderStatus status)
{
Ensure.NotNull(workspace, nameof(workspace));
Ensure.NotNull(status, nameof(status));

Workspace = workspace;
Details = status;
}

/// <summary>
/// Initializes a new instance of the <see cref="ProviderStatusInfo"/> class.
/// Use only for testing.
/// </summary>
protected ProviderStatusInfo()
{
}

/// <summary>
/// Gets the workspace.
/// </summary>
public virtual IWorkspace? Workspace { get; }

/// <summary>
/// Provider id.
/// </summary>
public virtual string? ProviderId => this.Details?.Id;

/// <summary>
/// Provider availability.
/// </summary>
public virtual Models.ProviderAvailability? CurrentAvailability => this.Details?.CurrentAvailability;

/// <summary>
/// List of all available targets for this provider.
/// </summary>
public virtual IEnumerable<TargetStatusInfo>? Targets
{
get
{
if (this.Details != null)
{
foreach (var ps in this.Details.Targets)
{
yield return new TargetStatusInfo(ps);
}
}
}
}

/// <summary>
/// Gets the provider status information.
/// </summary>
protected Models.ProviderStatus? Details { get; private set; }
}
}
Loading