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
Show all changes
44 commits
Select commit Hold shift + click to select a range
0e12f1d
Add command-line options for Azure submission
May 5, 2020
5ee822d
Small code style fixes
May 5, 2020
f4335c4
Use real provider for Azure submission
May 7, 2020
00aa3a0
Remove TODO from the wrong place
May 7, 2020
f8f203e
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha May 7, 2020
102c98c
Use SimulatorMachine based on target name
May 7, 2020
515f969
Merge remote-tracking branch 'origin/samarsha/azure-submit' into sama…
May 7, 2020
89a6932
Add option for number of shots
May 7, 2020
6a780f2
Validate that shots is positive
May 7, 2020
290469c
Use DefaultIfShadowed for Azure settings
May 7, 2020
7702e3a
Simplify adding/defaulting options
May 7, 2020
3a75b78
Make SimulatorOption non-static
May 7, 2020
77e177a
Add AddOptionsIfAvailable method
May 7, 2020
da6efc3
Fix option aliases missing dashes
May 7, 2020
da767f8
Disable command if required options are shadowed
May 7, 2020
c363cc3
Add copyright headers
May 7, 2020
4bda02b
Add histogram option
May 7, 2020
28ba977
Make histogram pretty
May 8, 2020
64188d8
Fix shadowing
May 8, 2020
5c411f7
Update histogram divider dash
May 8, 2020
f5ae08e
Preserve required state of options
May 8, 2020
ed35ff4
Simulator option is not required
May 8, 2020
c4d0bb2
Use SubmitAsync instead of ExecuteAsync
May 8, 2020
4aa57a4
Add access token option
May 8, 2020
7e7007c
Rename ToWorkspace to CreateWorkspace
May 8, 2020
15f5f67
Remove "Azure" from option descriptions
May 8, 2020
a67da46
Print job ID instead of URI for now
May 9, 2020
6568a9e
Add --base-uri option
May 11, 2020
f72feae
Rename --access to --aad-token
May 11, 2020
3b105b0
Rename --id-only to --output
May 11, 2020
ec1b935
Add OptionInfo class
May 11, 2020
9bf31b6
Update --shots validator message
May 11, 2020
44383c3
Update --base-uri description
May 11, 2020
4c2f68f
Add TODO for "submit" tests
May 11, 2020
6cf2873
Replace NotImplementedExceptions with NotSupportedExceptions
May 11, 2020
fbcdf60
More specific TODO for number of shots
May 11, 2020
eca8091
Don't include default value for required options
May 12, 2020
be0e5d7
Hide "submit" command
May 13, 2020
3c66e56
Update help test
May 13, 2020
3f592fc
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha May 13, 2020
e076855
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha May 14, 2020
256ebbd
Update TODO comments
May 14, 2020
3cd4c43
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha May 15, 2020
3845b95
Add reference to Microsoft.Azure.Quantum.Client
May 15, 2020
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: 4 additions & 2 deletions src/Simulation/CsharpGeneration.Tests/EntryPointTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ let ``Supports default custom simulator`` () =
given ["--simulator"; typeof<QuantumSimulator>.FullName; "--use-h"; "false"] |> fails


// TODO: Add tests for the "submit" command.


// Help

[<Fact>]
Expand All @@ -501,8 +504,7 @@ Options:
-?, -h, --help Show help and usage information

Commands:
simulate (default) Run the program using a local simulator.
submit Submit the program to Azure Quantum."
simulate (default) Run the program using a local simulator."

let given = test 31
given ["--help"] |> yields message
Expand Down
152 changes: 152 additions & 0 deletions src/Simulation/EntryPointDriver/Azure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.CommandLine.Parsing;
using System.Threading.Tasks;
using Microsoft.Azure.Quantum;
using Microsoft.Quantum.Runtime;

namespace Microsoft.Quantum.CsharpGeneration.EntryPointDriver
{
/// <summary>
/// Provides entry point submission to Azure Quantum.
/// </summary>
internal static class Azure
{
/// <summary>
/// Submits the entry point to Azure Quantum.
/// </summary>
/// <param name="entryPoint">The entry point.</param>
/// <param name="parseResult">The command-line parsing result.</param>
/// <param name="settings">The submission settings.</param>
/// <typeparam name="TIn">The entry point's argument type.</typeparam>
/// <typeparam name="TOut">The entry point's return type.</typeparam>
internal static async Task<int> Submit<TIn, TOut>(
IEntryPoint<TIn, TOut> entryPoint, ParseResult parseResult, AzureSettings settings)
{
var machine = CreateMachine(settings);
if (machine is null)
{
DisplayUnknownTargetError(settings.Target);
return 1;
}

// TODO: Specify the number of shots. The IQuantumMachine interface should be updated.
var job = await machine.SubmitAsync(entryPoint.Info, entryPoint.CreateArgument(parseResult));
switch (settings.Output)
{
case OutputFormat.FriendlyUri:
Console.WriteLine("Job submitted. To track your job status and see the results use:");
Console.WriteLine();
// TODO: Show the friendly URI. The friendly URI is not yet available from the job.
Console.WriteLine(job.Id);
break;
case OutputFormat.Id:
Console.WriteLine(job.Id);
break;
default:
throw new ArgumentOutOfRangeException($"Invalid output format '{settings.Output}'.");
}
return 0;
}

/// <summary>
/// Creates a quantum machine based on the Azure Quantum submission settings.
/// </summary>
/// <param name="settings">The Azure Quantum submission settings.</param>
/// <returns>A quantum machine.</returns>
private static IQuantumMachine? CreateMachine(AzureSettings settings) =>
settings.Target == "nothing"
? new NothingMachine()
: QuantumMachineFactory.CreateMachine(settings.CreateWorkspace(), settings.Target, settings.Storage);

/// <summary>
/// Displays an error message for attempting to use an unknown target machine.
/// </summary>
/// <param name="target">The target machine.</param>
private static void DisplayUnknownTargetError(string? target)
{
var originalForeground = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine($"The target '{target}' was not recognized.");
Console.ForegroundColor = originalForeground;
}
}

/// <summary>
/// The information to show in the output after the job is submitted.
/// </summary>
internal enum OutputFormat
{
/// <summary>
/// Show a friendly message with a URI that can be used to see the job results.
/// </summary>
FriendlyUri,

/// <summary>
/// Show only the job ID.
/// </summary>
Id
}

/// <summary>
/// Settings for a submission to Azure Quantum.
/// </summary>
internal sealed class AzureSettings
{
/// <summary>
/// The target device ID.
/// </summary>
public string? Target { get; set; }

/// <summary>
/// The storage account connection string.
/// </summary>
public string? Storage { get; set; }

/// <summary>
/// The subscription ID.
/// </summary>
public string? Subscription { get; set; }

/// <summary>
/// The resource group name.
/// </summary>
public string? ResourceGroup { get; set; }

/// <summary>
/// The workspace name.
/// </summary>
public string? Workspace { get; set; }

/// <summary>
/// The Azure Active Directory authentication token.
/// </summary>
public string? AadToken { get; set; }

/// <summary>
/// The base URI of the Azure Quantum endpoint.
/// </summary>
public Uri? BaseUri { get; set; }

/// <summary>
/// The number of times the program is executed on the target machine.
/// </summary>
public int Shots { get; set; }

/// <summary>
/// The information to show in the output after the job is submitted.
/// </summary>
public OutputFormat Output { get; set; }

/// <summary>
/// Creates a <see cref="Workspace"/> based on the settings.
/// </summary>
/// <returns>The <see cref="Workspace"/> based on the settings.</returns>
internal Workspace CreateWorkspace() =>
AadToken is null
? new Workspace(Subscription, ResourceGroup, Workspace, baseUri: BaseUri)
: new Workspace(Subscription, ResourceGroup, Workspace, AadToken, BaseUri);
}
}
Loading