From 6ae50ef98666e806a1f38ec9f47b712c953cc8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Mon, 4 May 2020 15:11:10 -0700 Subject: [PATCH 1/2] Removed type parameters from IQuantumMachine interface. (#185) * Removed type parameters from IQuantumMachine interface. * Addressed Sarah's feedback. * Update src/Simulation/Core/IQuantumMachineOutput.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> (cherry picked from commit 1b53a81693d15189d734de2d6400d0691c1595b0) --- src/Simulation/Core/IQuantumMachine.cs | 15 +++--- src/Simulation/Core/IQuantumMachineJob.cs | 57 ++++++++++++++++++++ src/Simulation/Core/IQuantumMachineOutput.cs | 30 +++++++++++ 3 files changed, 93 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..5593572ef16 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..8e5ab684ba4 --- /dev/null +++ b/src/Simulation/Core/IQuantumMachineJob.cs @@ -0,0 +1,57 @@ +// 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 whether job execution failed. + /// + bool Failed { get; } + + /// + /// 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 for the cancel operation. + Task CancelAsync(CancellationToken cancellationToken = default); + + /// + /// Refreshes the state of the job. + /// + /// 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 new file mode 100644 index 00000000000..204765d50f4 --- /dev/null +++ b/src/Simulation/Core/IQuantumMachineOutput.cs @@ -0,0 +1,30 @@ +// 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. + /// Type of output the quantum program returns. + /// + public interface IQuantumMachineOutput + { + /// + /// Gets a histogram of outputs. + /// The key is the output and the value is its frequency. + /// + IReadOnlyDictionary 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 2bbe8c0528119fab1c628b5bd5d0ee48276ed022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 8 May 2020 16:24:14 -0700 Subject: [PATCH 2/2] Update src/Simulation/Core/IQuantumMachineJob.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> --- src/Simulation/Core/IQuantumMachineJob.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulation/Core/IQuantumMachineJob.cs b/src/Simulation/Core/IQuantumMachineJob.cs index 8e5ab684ba4..e715a216053 100644 --- a/src/Simulation/Core/IQuantumMachineJob.cs +++ b/src/Simulation/Core/IQuantumMachineJob.cs @@ -35,7 +35,7 @@ public interface IQuantumMachineJob /// /// Gets whether the job execution completed successfully. /// - bool Succeeded { get; } + bool Succeeded { get; } /// /// Gets an URI to access the job.