This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Add support for submitting standalone entry points to Azure Quantum #194
Merged
bamarsha
merged 44 commits into
feature/azure-quantum-preview
from
samarsha/azure-submit
May 16, 2020
Merged
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
5ee822d
Small code style fixes
f4335c4
Use real provider for Azure submission
00aa3a0
Remove TODO from the wrong place
f8f203e
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha 102c98c
Use SimulatorMachine based on target name
515f969
Merge remote-tracking branch 'origin/samarsha/azure-submit' into sama…
89a6932
Add option for number of shots
6a780f2
Validate that shots is positive
290469c
Use DefaultIfShadowed for Azure settings
7702e3a
Simplify adding/defaulting options
3a75b78
Make SimulatorOption non-static
77e177a
Add AddOptionsIfAvailable method
da6efc3
Fix option aliases missing dashes
da767f8
Disable command if required options are shadowed
c363cc3
Add copyright headers
4bda02b
Add histogram option
28ba977
Make histogram pretty
64188d8
Fix shadowing
5c411f7
Update histogram divider dash
f5ae08e
Preserve required state of options
ed35ff4
Simulator option is not required
c4d0bb2
Use SubmitAsync instead of ExecuteAsync
4aa57a4
Add access token option
7e7007c
Rename ToWorkspace to CreateWorkspace
15f5f67
Remove "Azure" from option descriptions
a67da46
Print job ID instead of URI for now
6568a9e
Add --base-uri option
f72feae
Rename --access to --aad-token
3b105b0
Rename --id-only to --output
ec1b935
Add OptionInfo class
9bf31b6
Update --shots validator message
44383c3
Update --base-uri description
4c2f68f
Add TODO for "submit" tests
6cf2873
Replace NotImplementedExceptions with NotSupportedExceptions
fbcdf60
More specific TODO for number of shots
eca8091
Don't include default value for required options
be0e5d7
Hide "submit" command
3c66e56
Update help test
3f592fc
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha e076855
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha 256ebbd
Update TODO comments
3cd4c43
Merge branch 'feature/azure-quantum-preview' into samarsha/azure-submit
bamarsha 3845b95
Add reference to Microsoft.Azure.Quantum.Client
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.