From 4987f5ea39e5919097517d1d9e75f9b1b6c50620 Mon Sep 17 00:00:00 2001 From: Cesar Zaragoza Cortes Date: Fri, 1 May 2020 17:27:49 -0700 Subject: [PATCH 1/3] Removed type parameters from IQuantumMachine interface. --- src/Simulation/Core/IQuantumMachine.cs | 15 +++--- src/Simulation/Core/IQuantumMachineJob.cs | 53 ++++++++++++++++++++ src/Simulation/Core/IQuantumMachineOutput.cs | 42 ++++++++++++++++ 3 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 src/Simulation/Core/IQuantumMachineJob.cs create mode 100644 src/Simulation/Core/IQuantumMachineOutput.cs diff --git a/src/Simulation/Core/IQuantumMachine.cs b/src/Simulation/Core/IQuantumMachine.cs index abe2c4538f0..de6cb2302d6 100644 --- a/src/Simulation/Core/IQuantumMachine.cs +++ b/src/Simulation/Core/IQuantumMachine.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; @@ -10,9 +9,7 @@ namespace Microsoft.Quantum.Runtime /// /// Interface that a quantum machine must implement. /// - /// Type of job that handles the execution of a program in the quantum machine. - /// Type of result the quantum machine returns. - public interface IQuantumMachine + public interface IQuantumMachine { /// /// Gets the ID of the quantum machine provider. @@ -29,14 +26,14 @@ public interface IQuantumMachine /// /// Executes a Q# program. /// Submits a job to execute it and continuously checks whether it has been completed. - /// Once its execution completes, returns its output. + /// Once its execution completes, returns an object that implements the IQuantumMachineOutput interface through which the execution output can be obtained. /// /// Information about the Q# program /// Input for the Q# program /// Type of input the quantum program receives. /// Type of output the quantum program returns. - /// Sampled output of the quantum program - Task> ExecuteAsync(EntryPointInfo info, TInput input); + /// An object that implements the IQuantumMachineOutput interface. + Task ExecuteAsync(EntryPointInfo info, TInput input); /// /// Submits a job to execute a Q# program. @@ -46,7 +43,7 @@ public interface IQuantumMachine /// Input for the Q# program /// Type of input the quantum program receives. /// Type of output the quantum program returns. - /// A Job instance. Status and results from the execution can be retrieved from this instance. - Task SubmitAsync(EntryPointInfo info, TInput input); + /// An object that implements the IQuantumMachineJob interface through which data about the job can be obtained. + Task SubmitAsync(EntryPointInfo info, TInput input); } } diff --git a/src/Simulation/Core/IQuantumMachineJob.cs b/src/Simulation/Core/IQuantumMachineJob.cs new file mode 100644 index 00000000000..dc5abc39e42 --- /dev/null +++ b/src/Simulation/Core/IQuantumMachineJob.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.Quantum.Runtime +{ + /// + /// Interface to track a job submitted to a quantum machine. + /// + public interface IQuantumMachineJob + { + /// + /// Gets the ID of submitted job. + /// + string Id { get; } + + /// + /// Gets whether job execution is in progress. + /// + bool InProgress { get; } + + /// + /// Gets the status of the submitted job. + /// + string Status { get; } + + /// + /// Gets whether the job execution completed successfully. + /// + bool Succeeded { get; } + + /// + /// Gets an URI to access the job. + /// + Uri Uri { get; } + + /// + /// Cancels the job. + /// + /// The cancellation token. + Task CancelAsync(CancellationToken cancellationToken = default); + + /// + /// Refreshes the state of the job. + /// + /// The cancellation token. + Task RefreshAsync(CancellationToken cancellationToken = default); + + } +} diff --git a/src/Simulation/Core/IQuantumMachineOutput.cs b/src/Simulation/Core/IQuantumMachineOutput.cs new file mode 100644 index 00000000000..12e665aad57 --- /dev/null +++ b/src/Simulation/Core/IQuantumMachineOutput.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; + +namespace Microsoft.Quantum.Runtime +{ + /// + /// Interface to access the results of a program executed in a quantum machine. + /// + public interface IQuantumMachineOutput + { + + /// + /// Gets an output probabilistically. + /// Calls to this method are not deterministic, each call can return a different output. + /// + object GetOutput(); + + /// + /// Gets the most frequent output. + /// If multiple outputs have the same frequency, it gets the first one in ascending order. + /// + object GetMostFrequentOutput(); + + /// + /// Gets a histogram of outputs. + /// The key is the output and the value is its frequency. + /// + IDictionary Histogram { get; } + + /// + /// Gets the job associated to the output. + /// + IQuantumMachineJob Job { get; } + + /// + /// Gets the number of times the program was executed. + /// + int Shots { get; } + } +} From 61376f9db21c96b20f28540d89bdf47a4c48589c Mon Sep 17 00:00:00 2001 From: Cesar Zaragoza Cortes Date: Mon, 4 May 2020 14:29:05 -0700 Subject: [PATCH 2/3] Addressed Sarah's feedback. --- src/Simulation/Core/IQuantumMachine.cs | 2 +- src/Simulation/Core/IQuantumMachineJob.cs | 10 +++++++--- src/Simulation/Core/IQuantumMachineOutput.cs | 18 +++--------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/Simulation/Core/IQuantumMachine.cs b/src/Simulation/Core/IQuantumMachine.cs index de6cb2302d6..5593572ef16 100644 --- a/src/Simulation/Core/IQuantumMachine.cs +++ b/src/Simulation/Core/IQuantumMachine.cs @@ -33,7 +33,7 @@ public interface IQuantumMachine /// Type of input the quantum program receives. /// Type of output the quantum program returns. /// An object that implements the IQuantumMachineOutput interface. - Task ExecuteAsync(EntryPointInfo info, TInput input); + Task> ExecuteAsync(EntryPointInfo info, TInput input); /// /// Submits a job to execute a Q# program. diff --git a/src/Simulation/Core/IQuantumMachineJob.cs b/src/Simulation/Core/IQuantumMachineJob.cs index dc5abc39e42..8e5ab684ba4 100644 --- a/src/Simulation/Core/IQuantumMachineJob.cs +++ b/src/Simulation/Core/IQuantumMachineJob.cs @@ -12,6 +12,11 @@ namespace Microsoft.Quantum.Runtime /// public interface IQuantumMachineJob { + /// + /// Gets whether job execution failed. + /// + bool Failed { get; } + /// /// Gets the ID of submitted job. /// @@ -40,14 +45,13 @@ public interface IQuantumMachineJob /// /// Cancels the job. /// - /// The cancellation token. + /// The cancellation token for the cancel operation. Task CancelAsync(CancellationToken cancellationToken = default); /// /// Refreshes the state of the job. /// - /// The cancellation token. + /// The cancellation token for the refresh operation. Task RefreshAsync(CancellationToken cancellationToken = default); - } } diff --git a/src/Simulation/Core/IQuantumMachineOutput.cs b/src/Simulation/Core/IQuantumMachineOutput.cs index 12e665aad57..cfecb473c77 100644 --- a/src/Simulation/Core/IQuantumMachineOutput.cs +++ b/src/Simulation/Core/IQuantumMachineOutput.cs @@ -7,27 +7,15 @@ namespace Microsoft.Quantum.Runtime { /// /// Interface to access the results of a program executed in a quantum machine. + /// Type of output the quantum program returns. /// - public interface IQuantumMachineOutput + public interface IQuantumMachineOutput { - - /// - /// Gets an output probabilistically. - /// Calls to this method are not deterministic, each call can return a different output. - /// - object GetOutput(); - - /// - /// Gets the most frequent output. - /// If multiple outputs have the same frequency, it gets the first one in ascending order. - /// - object GetMostFrequentOutput(); - /// /// Gets a histogram of outputs. /// The key is the output and the value is its frequency. /// - IDictionary Histogram { get; } + IReadOnlyDictionary Histogram { get; } /// /// Gets the job associated to the output. From f0535136164e14135cd4e8f3e583e5eb87e5312f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Mon, 4 May 2020 14:49:48 -0700 Subject: [PATCH 3/3] Update src/Simulation/Core/IQuantumMachineOutput.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> --- src/Simulation/Core/IQuantumMachineOutput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulation/Core/IQuantumMachineOutput.cs b/src/Simulation/Core/IQuantumMachineOutput.cs index cfecb473c77..204765d50f4 100644 --- a/src/Simulation/Core/IQuantumMachineOutput.cs +++ b/src/Simulation/Core/IQuantumMachineOutput.cs @@ -15,7 +15,7 @@ public interface IQuantumMachineOutput /// Gets a histogram of outputs. /// The key is the output and the value is its frequency. /// - IReadOnlyDictionary Histogram { get; } + IReadOnlyDictionary Histogram { get; } /// /// Gets the job associated to the output.