From 22d1b23d83bb3e5005cbf5db55808870ba85051a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Mon, 12 Apr 2021 20:04:22 -0700 Subject: [PATCH 01/19] Create IQirMachine interface. --- src/Simulation/Core/IAzureMachine.cs | 28 ++++++++++++++++++ src/Simulation/Core/IQirMachine.cs | 43 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/Simulation/Core/IAzureMachine.cs create mode 100644 src/Simulation/Core/IQirMachine.cs diff --git a/src/Simulation/Core/IAzureMachine.cs b/src/Simulation/Core/IAzureMachine.cs new file mode 100644 index 00000000000..c92f18290e4 --- /dev/null +++ b/src/Simulation/Core/IAzureMachine.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Runtime +{ + public interface IAzureMachine + { + /// + /// Function that configures a job object before submission. + /// + public delegate void ConfigureJob(object job); + + /// + /// Gets the ID of the quantum machine provider. + /// + string ProviderId { get; } + + /// + /// Gets the name of the target quantum machine. + /// A provider may expose multiple targets that can be used to execute programs. + /// Users may select which target they would like to be used for execution. + /// + string Target { get; } + } +} diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs new file mode 100644 index 00000000000..0a633dd5435 --- /dev/null +++ b/src/Simulation/Core/IQirMachine.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Runtime +{ + public interface IQirMachine : IAzureMachine + { + /// + /// Submits a job to execute a Q# program. + /// Does not wait for execution to be completed. + /// + /// Information about the Q# program. + /// Input for the Q# program. + /// Input for the Q# program. + /// Type of input the quantum program receives. + /// Type of output the quantum program returns. + /// An object that implements the IQuantumMachineJob interface through which data about the job can be obtained. + Task SubmitAsync( + EntryPointInfo info, + TInput input, + byte[] qir) => SubmitAsync(info, input, qir, null); + + /// + /// Submits a job to execute a Q# program. + /// Does not wait for execution to be completed. + /// + /// Information about the Q# program. + /// Input for the Q# program. + /// Input for the Q# program. + /// Function that configures a job object before submission. + /// Type of input the quantum program receives. + /// Type of output the quantum program returns. + /// An object that implements the IQuantumMachineJob interface through which data about the job can be obtained. + Task SubmitAsync( + EntryPointInfo info, + TInput input, + byte[] qir, + ConfigureJob configureJobCallback); + } +} From 7df14c5a97f4cf751a6775849cb671b077be3231 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Tue, 13 Apr 2021 17:01:08 -0700 Subject: [PATCH 02/19] Remove ConfigureJob, IQuantumMachine inherits IAzureMachine --- src/Simulation/Core/IAzureMachine.cs | 8 ------ src/Simulation/Core/IQirMachine.cs | 36 +++++++------------------- src/Simulation/Core/IQuantumMachine.cs | 15 +---------- 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/src/Simulation/Core/IAzureMachine.cs b/src/Simulation/Core/IAzureMachine.cs index c92f18290e4..d161055cc8d 100644 --- a/src/Simulation/Core/IAzureMachine.cs +++ b/src/Simulation/Core/IAzureMachine.cs @@ -1,18 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System.Threading.Tasks; -using Microsoft.Quantum.Simulation.Core; - namespace Microsoft.Quantum.Runtime { public interface IAzureMachine { - /// - /// Function that configures a job object before submission. - /// - public delegate void ConfigureJob(object job); - /// /// Gets the ID of the quantum machine provider. /// diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 0a633dd5435..99dbe0fc75c 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -9,35 +9,19 @@ namespace Microsoft.Quantum.Runtime public interface IQirMachine : IAzureMachine { /// - /// Submits a job to execute a Q# program. - /// Does not wait for execution to be completed. + /// Submits a job to execute a QIR program. Does not wait for execution to be completed. /// - /// Information about the Q# program. - /// Input for the Q# program. - /// Input for the Q# program. - /// Type of input the quantum program receives. - /// Type of output the quantum program returns. - /// An object that implements the IQuantumMachineJob interface through which data about the job can be obtained. + /// The entry point information. + /// The input to the entry point. + /// The QIR program as a byte string. + /// Type of input the QIR program receives. + /// Type of output the QIR program returns. + /// + /// An object that implements the IQuantumMachineJob interface through which data about the job can be obtained. + /// Task SubmitAsync( EntryPointInfo info, TInput input, - byte[] qir) => SubmitAsync(info, input, qir, null); - - /// - /// Submits a job to execute a Q# program. - /// Does not wait for execution to be completed. - /// - /// Information about the Q# program. - /// Input for the Q# program. - /// Input for the Q# program. - /// Function that configures a job object before submission. - /// Type of input the quantum program receives. - /// Type of output the quantum program returns. - /// An object that implements the IQuantumMachineJob interface through which data about the job can be obtained. - Task SubmitAsync( - EntryPointInfo info, - TInput input, - byte[] qir, - ConfigureJob configureJobCallback); + byte[] qir); } } diff --git a/src/Simulation/Core/IQuantumMachine.cs b/src/Simulation/Core/IQuantumMachine.cs index 0e7cc236692..2d81d39ec0a 100644 --- a/src/Simulation/Core/IQuantumMachine.cs +++ b/src/Simulation/Core/IQuantumMachine.cs @@ -9,26 +9,13 @@ namespace Microsoft.Quantum.Runtime /// /// Interface that a quantum machine must implement. /// - public interface IQuantumMachine + public interface IQuantumMachine : IAzureMachine { - /// /// Function that configures a job object before submission. /// public delegate void ConfigureJob(object job); - /// - /// Gets the ID of the quantum machine provider. - /// - string ProviderId { get; } - - /// - /// Gets the name of the target quantum machine. - /// A provider may expose multiple targets that can be used to execute programs. - /// Users may select which target they would like to be used for execution. - /// - string Target { get; } - /// /// Executes a Q# program. /// Submits a job to execute it and continuously checks whether it has been completed. From 15f485b812be395d6e362dd0faab093440cd4340 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Tue, 13 Apr 2021 17:27:14 -0700 Subject: [PATCH 03/19] Use Stream --- src/Simulation/Core/IQirMachine.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 99dbe0fc75c..3f2534be19e 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System.IO; using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; @@ -13,7 +14,7 @@ public interface IQirMachine : IAzureMachine /// /// The entry point information. /// The input to the entry point. - /// The QIR program as a byte string. + /// The QIR program as a byte stream. /// Type of input the QIR program receives. /// Type of output the QIR program returns. /// @@ -22,6 +23,6 @@ public interface IQirMachine : IAzureMachine Task SubmitAsync( EntryPointInfo info, TInput input, - byte[] qir); + Stream qir); } } From 4ad0265f44e3c258cde6db39cd197418d3d48610 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Tue, 13 Apr 2021 18:12:29 -0700 Subject: [PATCH 04/19] Add Argument class --- src/Simulation/Core/IQirMachine.cs | 95 ++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 3f2534be19e..773a599af38 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -1,28 +1,99 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; +using Core = Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Runtime { public interface IQirMachine : IAzureMachine { /// - /// Submits a job to execute a QIR program. Does not wait for execution to be completed. + /// Submits a job to execute a QIR program without waiting for execution to complete. /// - /// The entry point information. - /// The input to the entry point. /// The QIR program as a byte stream. - /// Type of input the QIR program receives. - /// Type of output the QIR program returns. - /// - /// An object that implements the IQuantumMachineJob interface through which data about the job can be obtained. - /// - Task SubmitAsync( - EntryPointInfo info, - TInput input, - Stream qir); + /// The fully-qualified name of the entry point to execute. + /// The arguments to the entry point. + /// The submitted job. + Task SubmitAsync(Stream qir, string entryPoint, IReadOnlyList arguments); + } + + public class Argument + { + public string Name { get; } + + public ArgumentValue Value { get; } + + public Argument(string name, ArgumentValue value) + { + this.Name = name; + this.Value = value; + } + } + + public abstract class ArgumentValue + { + private ArgumentValue() + { + } + + public class Bool : ArgumentValue + { + public bool Value { get; } + + public Bool(bool value) => this.Value = value; + } + + public class Int : ArgumentValue + { + public long Value { get; } + + public Int(long value) => this.Value = value; + } + + public class Double : ArgumentValue + { + public double Value { get; } + + public Double(double value) => this.Value = value; + } + + public class Pauli : ArgumentValue + { + public Core.Pauli Value { get; } + + public Pauli(Core.Pauli value) => this.Value = value; + } + + public class Range : ArgumentValue + { + public QRange Value { get; } + + public Range(QRange value) => this.Value = value; + } + + public class Result : ArgumentValue + { + public Core.Result Value { get; } + + public Result(Core.Result value) => this.Value = value; + } + + public class String : ArgumentValue + { + public string Value { get; } + + public String(string value) => this.Value = value; + } + + public class Array : ArgumentValue + { + public QArray Values { get; } + + public Array(QArray values) => this.Values = values; + } } } From dc7c79a5aa8619745dbec7afa8b2a1afd24ec7b0 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Tue, 13 Apr 2021 18:18:54 -0700 Subject: [PATCH 05/19] Use IQArray --- src/Simulation/Core/IQirMachine.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 773a599af38..32dea97378e 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -43,57 +43,49 @@ private ArgumentValue() public class Bool : ArgumentValue { public bool Value { get; } - public Bool(bool value) => this.Value = value; } public class Int : ArgumentValue { public long Value { get; } - public Int(long value) => this.Value = value; } public class Double : ArgumentValue { public double Value { get; } - public Double(double value) => this.Value = value; } public class Pauli : ArgumentValue { public Core.Pauli Value { get; } - public Pauli(Core.Pauli value) => this.Value = value; } public class Range : ArgumentValue { public QRange Value { get; } - public Range(QRange value) => this.Value = value; } public class Result : ArgumentValue { public Core.Result Value { get; } - public Result(Core.Result value) => this.Value = value; } public class String : ArgumentValue { public string Value { get; } - public String(string value) => this.Value = value; } public class Array : ArgumentValue { - public QArray Values { get; } - - public Array(QArray values) => this.Values = values; + public IQArray Values { get; } + public Array(IQArray values) => this.Values = values; } } } From 1e4129dc84bac733e7819d8be2383763e90c5350 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Tue, 13 Apr 2021 18:25:33 -0700 Subject: [PATCH 06/19] Tuple assignment --- src/Simulation/Core/IQirMachine.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 32dea97378e..22049b42046 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -27,11 +27,7 @@ public class Argument public ArgumentValue Value { get; } - public Argument(string name, ArgumentValue value) - { - this.Name = name; - this.Value = value; - } + public Argument(string name, ArgumentValue value) => (this.Name, this.Value) = (name, value); } public abstract class ArgumentValue @@ -43,48 +39,56 @@ private ArgumentValue() public class Bool : ArgumentValue { public bool Value { get; } + public Bool(bool value) => this.Value = value; } public class Int : ArgumentValue { public long Value { get; } + public Int(long value) => this.Value = value; } public class Double : ArgumentValue { public double Value { get; } + public Double(double value) => this.Value = value; } public class Pauli : ArgumentValue { public Core.Pauli Value { get; } + public Pauli(Core.Pauli value) => this.Value = value; } public class Range : ArgumentValue { public QRange Value { get; } + public Range(QRange value) => this.Value = value; } public class Result : ArgumentValue { public Core.Result Value { get; } + public Result(Core.Result value) => this.Value = value; } public class String : ArgumentValue { public string Value { get; } + public String(string value) => this.Value = value; } public class Array : ArgumentValue { public IQArray Values { get; } + public Array(IQArray values) => this.Values = values; } } From 9d3a929decb6d10fd2af78cfd89cd13675c42ed6 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 14 Apr 2021 13:47:00 -0700 Subject: [PATCH 07/19] Add doc comments --- src/Simulation/Core/IQirMachine.cs | 102 ++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 22049b42046..39802fa95b1 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -9,6 +9,9 @@ namespace Microsoft.Quantum.Runtime { + /// + /// A machine that can submit QIR programs to Azure. + /// public interface IQirMachine : IAzureMachine { /// @@ -16,79 +19,176 @@ public interface IQirMachine : IAzureMachine /// /// The QIR program as a byte stream. /// The fully-qualified name of the entry point to execute. - /// The arguments to the entry point. + /// The arguments to the entry point in the order in which they are declared. /// The submitted job. Task SubmitAsync(Stream qir, string entryPoint, IReadOnlyList arguments); } + /// + /// An argument to a QIR callable. + /// public class Argument { + /// + /// The name of the argument. + /// public string Name { get; } + /// + /// The value of the argument. + /// public ArgumentValue Value { get; } + /// + /// Creates a new argument. + /// + /// The name of the argument. + /// The value of the argument. public Argument(string name, ArgumentValue value) => (this.Name, this.Value) = (name, value); } + /// + /// The value of an argument to a QIR callable is a discriminated union of the argument types. + /// public abstract class ArgumentValue { private ArgumentValue() { } + /// + /// A boolean argument value. + /// public class Bool : ArgumentValue { + /// + /// The value of the argument. + /// public bool Value { get; } + /// + /// Creates a boolean argument value. + /// + /// The value of the argument. public Bool(bool value) => this.Value = value; } + /// + /// An integer argument value. + /// public class Int : ArgumentValue { + /// + /// The value of the argument. + /// public long Value { get; } + /// + /// Creates an integer argument value. + /// + /// The value of the argument. public Int(long value) => this.Value = value; } + /// + /// A double-precision floating point argument value. + /// public class Double : ArgumentValue { + /// + /// The value of the argument. + /// public double Value { get; } + /// + /// Creates a double-precision floating point argument value. + /// + /// The value of the argument. public Double(double value) => this.Value = value; } + /// + /// A Pauli operator argument value. + /// public class Pauli : ArgumentValue { + /// + /// The value of the argument. + /// public Core.Pauli Value { get; } + /// + /// Creates a Pauli operator argument value. + /// + /// The value of the argument. public Pauli(Core.Pauli value) => this.Value = value; } + /// + /// A range argument value. + /// public class Range : ArgumentValue { + /// + /// The value of the argument. + /// public QRange Value { get; } + /// + /// Creates a range argument value. + /// + /// The value of the argument. public Range(QRange value) => this.Value = value; } + /// + /// A result argument value. + /// public class Result : ArgumentValue { + /// + /// The value of the argument. + /// public Core.Result Value { get; } + /// + /// Creates a result argument value. + /// + /// The value of the argument. public Result(Core.Result value) => this.Value = value; } + /// + /// A string argument value. + /// public class String : ArgumentValue { + /// + /// The value of the argument. + /// public string Value { get; } + /// + /// Creates a string argument value. + /// + /// The value of the argument. public String(string value) => this.Value = value; } + /// + /// An array argument value. + /// public class Array : ArgumentValue { + /// + /// The values of the argument. + /// public IQArray Values { get; } + /// + /// Creates an array argument value. + /// + /// The values of the argument. public Array(IQArray values) => this.Values = values; } } From eb763a06e3695fbc55e6c08ee77ea2bfb1698752 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 14 Apr 2021 13:47:53 -0700 Subject: [PATCH 08/19] Enable nullable --- src/Simulation/Core/IAzureMachine.cs | 2 ++ src/Simulation/Core/IQirMachine.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Simulation/Core/IAzureMachine.cs b/src/Simulation/Core/IAzureMachine.cs index d161055cc8d..f73baacbd0d 100644 --- a/src/Simulation/Core/IAzureMachine.cs +++ b/src/Simulation/Core/IAzureMachine.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#nullable enable + namespace Microsoft.Quantum.Runtime { public interface IAzureMachine diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 39802fa95b1..4c5a0734988 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#nullable enable + using System.Collections.Generic; using System.IO; using System.Threading.Tasks; From 76d02d6f829b98042862d0fc1f311bc71350954f Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 14 Apr 2021 13:52:55 -0700 Subject: [PATCH 09/19] Add doc comment to IAzureMachine --- src/Simulation/Core/IAzureMachine.cs | 3 +++ src/Simulation/Core/IQirMachine.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Simulation/Core/IAzureMachine.cs b/src/Simulation/Core/IAzureMachine.cs index f73baacbd0d..f5444521e7b 100644 --- a/src/Simulation/Core/IAzureMachine.cs +++ b/src/Simulation/Core/IAzureMachine.cs @@ -5,6 +5,9 @@ namespace Microsoft.Quantum.Runtime { + /// + /// A machine that can execute quantum programs on Azure. + /// public interface IAzureMachine { /// diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 4c5a0734988..4e2ed5de478 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -12,7 +12,7 @@ namespace Microsoft.Quantum.Runtime { /// - /// A machine that can submit QIR programs to Azure. + /// A machine that can execute QIR programs on Azure. /// public interface IQirMachine : IAzureMachine { From 3542f8863b27edeabcb8dc1a9bba657722174f9c Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 14 Apr 2021 22:39:31 -0700 Subject: [PATCH 10/19] Enforce array homogeneity --- src/Simulation/Core/IQirMachine.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 4e2ed5de478..698dce20521 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -3,8 +3,10 @@ #nullable enable +using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; using Core = Microsoft.Quantum.Simulation.Core; @@ -178,7 +180,7 @@ public class String : ArgumentValue } /// - /// An array argument value. + /// An array argument value where all values in the array are of the same type. /// public class Array : ArgumentValue { @@ -191,7 +193,26 @@ public class Array : ArgumentValue /// Creates an array argument value. /// /// The values of the argument. - public Array(IQArray values) => this.Values = values; + /// The array values are not all of the same type. + public Array(IQArray values) => + this.Values = IsHomogeneous(values) + ? values + : throw new ArgumentException("The array values are not all of the same type."); + + private static bool IsHomogeneous(IQArray values) => values + .Zip(values.Skip(1), ValueTuple.Create) + .All(pair => pair switch + { + (Bool _, Bool _) => true, + (Int _, Int _) => true, + (Double _, Double _) => true, + (Pauli _, Pauli _) => true, + (Range _, Range _) => true, + (Result _, Result _) => true, + (String _, String _) => true, + (Array _, Array _) => true, + _ => false + }); } } } From 3e524d3d5b741956f7cd64b271bfcdd78482456b Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 14 Apr 2021 22:57:40 -0700 Subject: [PATCH 11/19] Avoid exception --- src/Simulation/Core/IQirMachine.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 698dce20521..5b2c046dcbc 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -180,7 +180,7 @@ public class String : ArgumentValue } /// - /// An array argument value where all values in the array are of the same type. + /// An array argument value where all values are of the same type. /// public class Array : ArgumentValue { @@ -189,15 +189,15 @@ public class Array : ArgumentValue /// public IQArray Values { get; } + private Array(IQArray values) => this.Values = values; + /// - /// Creates an array argument value. + /// Tries to create an array argument value. /// /// The values of the argument. - /// The array values are not all of the same type. - public Array(IQArray values) => - this.Values = IsHomogeneous(values) - ? values - : throw new ArgumentException("The array values are not all of the same type."); + /// The array or null if not all values are of the same type. + public static Array? TryCreate(IQArray values) => + IsHomogeneous(values) ? new Array(values) : null; private static bool IsHomogeneous(IQArray values) => values .Zip(values.Skip(1), ValueTuple.Create) From 0269a6ef897165ecfea733e4a4405e08b64ac079 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Thu, 15 Apr 2021 14:57:35 -0700 Subject: [PATCH 12/19] Fix array homogeneity check --- src/Simulation/Core/IQirMachine.cs | 126 ++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 19 deletions(-) diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 5b2c046dcbc..7a1ab53137a 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; using Core = Microsoft.Quantum.Simulation.Core; @@ -51,11 +52,90 @@ public class Argument public Argument(string name, ArgumentValue value) => (this.Name, this.Value) = (name, value); } + /// + /// The type of an argument to a QIR callable. + /// + public class ArgumentType + { + private ArgumentType() + { + } + + /// + /// The boolean type. + /// + public static ArgumentType Bool { get; } = new ArgumentType(); + + /// + /// The integer type. + /// + public static ArgumentType Int { get; } = new ArgumentType(); + + /// + /// The double-precision floating point type. + /// + public static ArgumentType Double { get; } = new ArgumentType(); + + /// + /// The Pauli operator type. + /// + public static ArgumentType Pauli { get; } = new ArgumentType(); + + /// + /// The range type. + /// + public static ArgumentType Range { get; } = new ArgumentType(); + + /// + /// The result type. + /// + public static ArgumentType Result { get; } = new ArgumentType(); + + /// + /// The string type. + /// + public static ArgumentType String { get; } = new ArgumentType(); + + /// + /// The array type. + /// + public class Array : ArgumentType + { + /// + /// The type of the array items. + /// + public ArgumentType Item { get; } + + /// + /// Creates a new array type. + /// + /// The type of the array items. + public Array(ArgumentType item) => this.Item = item; + + public override bool Equals(object obj) => obj is Array array && this.Item.Equals(array.Item); + + public override int GetHashCode() => HashCode.Combine(1, this.Item.GetHashCode()); + } + + public override bool Equals(object obj) => ReferenceEquals(this, obj); + + public override int GetHashCode() => RuntimeHelpers.GetHashCode(this); + + public static bool operator ==(ArgumentType lhs, ArgumentType rhs) => lhs.Equals(rhs); + + public static bool operator !=(ArgumentType lhs, ArgumentType rhs) => !(lhs == rhs); + } + /// /// The value of an argument to a QIR callable is a discriminated union of the argument types. /// public abstract class ArgumentValue { + /// + /// The type of the argument. + /// + public abstract ArgumentType Type { get; } + private ArgumentValue() { } @@ -70,6 +150,8 @@ public class Bool : ArgumentValue /// public bool Value { get; } + public override ArgumentType Type => ArgumentType.Bool; + /// /// Creates a boolean argument value. /// @@ -87,6 +169,8 @@ public class Int : ArgumentValue /// public long Value { get; } + public override ArgumentType Type => ArgumentType.Int; + /// /// Creates an integer argument value. /// @@ -104,6 +188,8 @@ public class Double : ArgumentValue /// public double Value { get; } + public override ArgumentType Type => ArgumentType.Double; + /// /// Creates a double-precision floating point argument value. /// @@ -121,6 +207,8 @@ public class Pauli : ArgumentValue /// public Core.Pauli Value { get; } + public override ArgumentType Type => ArgumentType.Pauli; + /// /// Creates a Pauli operator argument value. /// @@ -138,6 +226,8 @@ public class Range : ArgumentValue /// public QRange Value { get; } + public override ArgumentType Type => ArgumentType.Range; + /// /// Creates a range argument value. /// @@ -155,6 +245,8 @@ public class Result : ArgumentValue /// public Core.Result Value { get; } + public override ArgumentType Type => ArgumentType.Result; + /// /// Creates a result argument value. /// @@ -172,6 +264,8 @@ public class String : ArgumentValue /// public string Value { get; } + public override ArgumentType Type => ArgumentType.String; + /// /// Creates a string argument value. /// @@ -189,30 +283,24 @@ public class Array : ArgumentValue /// public IQArray Values { get; } - private Array(IQArray values) => this.Values = values; + /// + /// The type of the array items. + /// + public ArgumentType ItemType { get; } + + public override ArgumentType Type => new ArgumentType.Array(this.ItemType); + + private Array(IQArray values, ArgumentType itemType) => + (this.Values, this.ItemType) = (values, itemType); /// /// Tries to create an array argument value. /// /// The values of the argument. - /// The array or null if not all values are of the same type. - public static Array? TryCreate(IQArray values) => - IsHomogeneous(values) ? new Array(values) : null; - - private static bool IsHomogeneous(IQArray values) => values - .Zip(values.Skip(1), ValueTuple.Create) - .All(pair => pair switch - { - (Bool _, Bool _) => true, - (Int _, Int _) => true, - (Double _, Double _) => true, - (Pauli _, Pauli _) => true, - (Range _, Range _) => true, - (Result _, Result _) => true, - (String _, String _) => true, - (Array _, Array _) => true, - _ => false - }); + /// The type of the values. + /// The array or null if not all values have the type . + public static Array? TryCreate(IQArray values, ArgumentType itemType) => + values.All(value => value.Type == itemType) ? new Array(values, itemType) : null; } } } From fc5d5fe1ab0a4edfb00d9fbd93c038852eb9242e Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Thu, 15 Apr 2021 17:02:51 -0700 Subject: [PATCH 13/19] Use separate files for argument classes --- src/Simulation/Core/Argument.cs | 30 +++ src/Simulation/Core/ArgumentType.cs | 84 ++++++++ src/Simulation/Core/ArgumentValue.cs | 188 ++++++++++++++++++ src/Simulation/Core/IQirMachine.cs | 280 --------------------------- 4 files changed, 302 insertions(+), 280 deletions(-) create mode 100644 src/Simulation/Core/Argument.cs create mode 100644 src/Simulation/Core/ArgumentType.cs create mode 100644 src/Simulation/Core/ArgumentValue.cs diff --git a/src/Simulation/Core/Argument.cs b/src/Simulation/Core/Argument.cs new file mode 100644 index 00000000000..b7ef2efbff5 --- /dev/null +++ b/src/Simulation/Core/Argument.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#nullable enable + +namespace Microsoft.Quantum.Runtime +{ + /// + /// An argument to a QIR callable. + /// + public class Argument + { + /// + /// The name of the argument. + /// + public string Name { get; } + + /// + /// The value of the argument. + /// + public ArgumentValue Value { get; } + + /// + /// Creates a new argument. + /// + /// The name of the argument. + /// The value of the argument. + public Argument(string name, ArgumentValue value) => (this.Name, this.Value) = (name, value); + } +} diff --git a/src/Simulation/Core/ArgumentType.cs b/src/Simulation/Core/ArgumentType.cs new file mode 100644 index 00000000000..b2e9f03dba4 --- /dev/null +++ b/src/Simulation/Core/ArgumentType.cs @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#nullable enable + +using System; +using System.Runtime.CompilerServices; + +namespace Microsoft.Quantum.Runtime +{ + /// + /// The type of an argument to a QIR callable. + /// + public class ArgumentType + { + private ArgumentType() + { + } + + /// + /// The boolean type. + /// + public static ArgumentType Bool { get; } = new ArgumentType(); + + /// + /// The integer type. + /// + public static ArgumentType Int { get; } = new ArgumentType(); + + /// + /// The double-precision floating point type. + /// + public static ArgumentType Double { get; } = new ArgumentType(); + + /// + /// The Pauli operator type. + /// + public static ArgumentType Pauli { get; } = new ArgumentType(); + + /// + /// The range type. + /// + public static ArgumentType Range { get; } = new ArgumentType(); + + /// + /// The result type. + /// + public static ArgumentType Result { get; } = new ArgumentType(); + + /// + /// The string type. + /// + public static ArgumentType String { get; } = new ArgumentType(); + + /// + /// The array type. + /// + public class Array : ArgumentType + { + /// + /// The type of the array items. + /// + public ArgumentType Item { get; } + + /// + /// Creates a new array type. + /// + /// The type of the array items. + public Array(ArgumentType item) => this.Item = item; + + public override bool Equals(object obj) => obj is Array array && this.Item.Equals(array.Item); + + public override int GetHashCode() => HashCode.Combine(1, this.Item.GetHashCode()); + } + + public override bool Equals(object obj) => ReferenceEquals(this, obj); + + public override int GetHashCode() => RuntimeHelpers.GetHashCode(this); + + public static bool operator ==(ArgumentType lhs, ArgumentType rhs) => lhs.Equals(rhs); + + public static bool operator !=(ArgumentType lhs, ArgumentType rhs) => !(lhs == rhs); + } +} diff --git a/src/Simulation/Core/ArgumentValue.cs b/src/Simulation/Core/ArgumentValue.cs new file mode 100644 index 00000000000..33f5f4c85dd --- /dev/null +++ b/src/Simulation/Core/ArgumentValue.cs @@ -0,0 +1,188 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#nullable enable + +using System.Linq; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Runtime +{ + /// + /// The value of an argument to a QIR callable is a discriminated union of the argument types. + /// + public abstract class ArgumentValue + { + /// + /// The type of the argument. + /// + public abstract ArgumentType Type { get; } + + private ArgumentValue() + { + } + + /// + /// A boolean argument value. + /// + public class Bool : ArgumentValue + { + /// + /// The value of the argument. + /// + public bool Value { get; } + + public override ArgumentType Type => ArgumentType.Bool; + + /// + /// Creates a boolean argument value. + /// + /// The value of the argument. + public Bool(bool value) => this.Value = value; + } + + /// + /// An integer argument value. + /// + public class Int : ArgumentValue + { + /// + /// The value of the argument. + /// + public long Value { get; } + + public override ArgumentType Type => ArgumentType.Int; + + /// + /// Creates an integer argument value. + /// + /// The value of the argument. + public Int(long value) => this.Value = value; + } + + /// + /// A double-precision floating point argument value. + /// + public class Double : ArgumentValue + { + /// + /// The value of the argument. + /// + public double Value { get; } + + public override ArgumentType Type => ArgumentType.Double; + + /// + /// Creates a double-precision floating point argument value. + /// + /// The value of the argument. + public Double(double value) => this.Value = value; + } + + /// + /// A Pauli operator argument value. + /// + public class Pauli : ArgumentValue + { + /// + /// The value of the argument. + /// + public Simulation.Core.Pauli Value { get; } + + public override ArgumentType Type => ArgumentType.Pauli; + + /// + /// Creates a Pauli operator argument value. + /// + /// The value of the argument. + public Pauli(Simulation.Core.Pauli value) => this.Value = value; + } + + /// + /// A range argument value. + /// + public class Range : ArgumentValue + { + /// + /// The value of the argument. + /// + public QRange Value { get; } + + public override ArgumentType Type => ArgumentType.Range; + + /// + /// Creates a range argument value. + /// + /// The value of the argument. + public Range(QRange value) => this.Value = value; + } + + /// + /// A result argument value. + /// + public class Result : ArgumentValue + { + /// + /// The value of the argument. + /// + public Simulation.Core.Result Value { get; } + + public override ArgumentType Type => ArgumentType.Result; + + /// + /// Creates a result argument value. + /// + /// The value of the argument. + public Result(Simulation.Core.Result value) => this.Value = value; + } + + /// + /// A string argument value. + /// + public class String : ArgumentValue + { + /// + /// The value of the argument. + /// + public string Value { get; } + + public override ArgumentType Type => ArgumentType.String; + + /// + /// Creates a string argument value. + /// + /// The value of the argument. + public String(string value) => this.Value = value; + } + + /// + /// An array argument value where all values are of the same type. + /// + public class Array : ArgumentValue + { + /// + /// The values of the argument. + /// + public IQArray Values { get; } + + /// + /// The type of the array items. + /// + public ArgumentType ItemType { get; } + + public override ArgumentType Type => new ArgumentType.Array(this.ItemType); + + private Array(IQArray values, ArgumentType itemType) => + (this.Values, this.ItemType) = (values, itemType); + + /// + /// Tries to create an array argument value. + /// + /// The values of the argument. + /// The type of the values. + /// The array or null if not all values have the type . + public static Array? TryCreate(IQArray values, ArgumentType itemType) => + values.All(value => value.Type == itemType) ? new Array(values, itemType) : null; + } + } +} diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirMachine.cs index 7a1ab53137a..1519990852c 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirMachine.cs @@ -3,14 +3,9 @@ #nullable enable -using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; using System.Threading.Tasks; -using Microsoft.Quantum.Simulation.Core; -using Core = Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Runtime { @@ -28,279 +23,4 @@ public interface IQirMachine : IAzureMachine /// The submitted job. Task SubmitAsync(Stream qir, string entryPoint, IReadOnlyList arguments); } - - /// - /// An argument to a QIR callable. - /// - public class Argument - { - /// - /// The name of the argument. - /// - public string Name { get; } - - /// - /// The value of the argument. - /// - public ArgumentValue Value { get; } - - /// - /// Creates a new argument. - /// - /// The name of the argument. - /// The value of the argument. - public Argument(string name, ArgumentValue value) => (this.Name, this.Value) = (name, value); - } - - /// - /// The type of an argument to a QIR callable. - /// - public class ArgumentType - { - private ArgumentType() - { - } - - /// - /// The boolean type. - /// - public static ArgumentType Bool { get; } = new ArgumentType(); - - /// - /// The integer type. - /// - public static ArgumentType Int { get; } = new ArgumentType(); - - /// - /// The double-precision floating point type. - /// - public static ArgumentType Double { get; } = new ArgumentType(); - - /// - /// The Pauli operator type. - /// - public static ArgumentType Pauli { get; } = new ArgumentType(); - - /// - /// The range type. - /// - public static ArgumentType Range { get; } = new ArgumentType(); - - /// - /// The result type. - /// - public static ArgumentType Result { get; } = new ArgumentType(); - - /// - /// The string type. - /// - public static ArgumentType String { get; } = new ArgumentType(); - - /// - /// The array type. - /// - public class Array : ArgumentType - { - /// - /// The type of the array items. - /// - public ArgumentType Item { get; } - - /// - /// Creates a new array type. - /// - /// The type of the array items. - public Array(ArgumentType item) => this.Item = item; - - public override bool Equals(object obj) => obj is Array array && this.Item.Equals(array.Item); - - public override int GetHashCode() => HashCode.Combine(1, this.Item.GetHashCode()); - } - - public override bool Equals(object obj) => ReferenceEquals(this, obj); - - public override int GetHashCode() => RuntimeHelpers.GetHashCode(this); - - public static bool operator ==(ArgumentType lhs, ArgumentType rhs) => lhs.Equals(rhs); - - public static bool operator !=(ArgumentType lhs, ArgumentType rhs) => !(lhs == rhs); - } - - /// - /// The value of an argument to a QIR callable is a discriminated union of the argument types. - /// - public abstract class ArgumentValue - { - /// - /// The type of the argument. - /// - public abstract ArgumentType Type { get; } - - private ArgumentValue() - { - } - - /// - /// A boolean argument value. - /// - public class Bool : ArgumentValue - { - /// - /// The value of the argument. - /// - public bool Value { get; } - - public override ArgumentType Type => ArgumentType.Bool; - - /// - /// Creates a boolean argument value. - /// - /// The value of the argument. - public Bool(bool value) => this.Value = value; - } - - /// - /// An integer argument value. - /// - public class Int : ArgumentValue - { - /// - /// The value of the argument. - /// - public long Value { get; } - - public override ArgumentType Type => ArgumentType.Int; - - /// - /// Creates an integer argument value. - /// - /// The value of the argument. - public Int(long value) => this.Value = value; - } - - /// - /// A double-precision floating point argument value. - /// - public class Double : ArgumentValue - { - /// - /// The value of the argument. - /// - public double Value { get; } - - public override ArgumentType Type => ArgumentType.Double; - - /// - /// Creates a double-precision floating point argument value. - /// - /// The value of the argument. - public Double(double value) => this.Value = value; - } - - /// - /// A Pauli operator argument value. - /// - public class Pauli : ArgumentValue - { - /// - /// The value of the argument. - /// - public Core.Pauli Value { get; } - - public override ArgumentType Type => ArgumentType.Pauli; - - /// - /// Creates a Pauli operator argument value. - /// - /// The value of the argument. - public Pauli(Core.Pauli value) => this.Value = value; - } - - /// - /// A range argument value. - /// - public class Range : ArgumentValue - { - /// - /// The value of the argument. - /// - public QRange Value { get; } - - public override ArgumentType Type => ArgumentType.Range; - - /// - /// Creates a range argument value. - /// - /// The value of the argument. - public Range(QRange value) => this.Value = value; - } - - /// - /// A result argument value. - /// - public class Result : ArgumentValue - { - /// - /// The value of the argument. - /// - public Core.Result Value { get; } - - public override ArgumentType Type => ArgumentType.Result; - - /// - /// Creates a result argument value. - /// - /// The value of the argument. - public Result(Core.Result value) => this.Value = value; - } - - /// - /// A string argument value. - /// - public class String : ArgumentValue - { - /// - /// The value of the argument. - /// - public string Value { get; } - - public override ArgumentType Type => ArgumentType.String; - - /// - /// Creates a string argument value. - /// - /// The value of the argument. - public String(string value) => this.Value = value; - } - - /// - /// An array argument value where all values are of the same type. - /// - public class Array : ArgumentValue - { - /// - /// The values of the argument. - /// - public IQArray Values { get; } - - /// - /// The type of the array items. - /// - public ArgumentType ItemType { get; } - - public override ArgumentType Type => new ArgumentType.Array(this.ItemType); - - private Array(IQArray values, ArgumentType itemType) => - (this.Values, this.ItemType) = (values, itemType); - - /// - /// Tries to create an array argument value. - /// - /// The values of the argument. - /// The type of the values. - /// The array or null if not all values have the type . - public static Array? TryCreate(IQArray values, ArgumentType itemType) => - values.All(value => value.Type == itemType) ? new Array(values, itemType) : null; - } - } } From 78c09c6bce8c3a73a7ed4f1aa99fa33118097f75 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Thu, 15 Apr 2021 18:45:42 -0700 Subject: [PATCH 14/19] Remove ArgumentValue.Array.ItemType property --- src/Simulation/Core/ArgumentValue.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Simulation/Core/ArgumentValue.cs b/src/Simulation/Core/ArgumentValue.cs index 33f5f4c85dd..0a7e36de1ac 100644 --- a/src/Simulation/Core/ArgumentValue.cs +++ b/src/Simulation/Core/ArgumentValue.cs @@ -165,15 +165,10 @@ public class Array : ArgumentValue /// public IQArray Values { get; } - /// - /// The type of the array items. - /// - public ArgumentType ItemType { get; } - - public override ArgumentType Type => new ArgumentType.Array(this.ItemType); + public override ArgumentType Type { get; } - private Array(IQArray values, ArgumentType itemType) => - (this.Values, this.ItemType) = (values, itemType); + private Array(IQArray values, ArgumentType itemType) => + (this.Values, this.Type) = (values, new ArgumentType.Array(itemType)); /// /// Tries to create an array argument value. From 66f9fc3ea8a39bca0c8532c65f62d7b153839ab7 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Thu, 15 Apr 2021 18:46:56 -0700 Subject: [PATCH 15/19] Shorter qualified names --- src/Simulation/Core/ArgumentValue.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Simulation/Core/ArgumentValue.cs b/src/Simulation/Core/ArgumentValue.cs index 0a7e36de1ac..b5ba4d5d62d 100644 --- a/src/Simulation/Core/ArgumentValue.cs +++ b/src/Simulation/Core/ArgumentValue.cs @@ -5,6 +5,7 @@ using System.Linq; using Microsoft.Quantum.Simulation.Core; +using Core = Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Runtime { @@ -87,7 +88,7 @@ public class Pauli : ArgumentValue /// /// The value of the argument. /// - public Simulation.Core.Pauli Value { get; } + public Core.Pauli Value { get; } public override ArgumentType Type => ArgumentType.Pauli; @@ -95,7 +96,7 @@ public class Pauli : ArgumentValue /// Creates a Pauli operator argument value. /// /// The value of the argument. - public Pauli(Simulation.Core.Pauli value) => this.Value = value; + public Pauli(Core.Pauli value) => this.Value = value; } /// @@ -125,7 +126,7 @@ public class Result : ArgumentValue /// /// The value of the argument. /// - public Simulation.Core.Result Value { get; } + public Core.Result Value { get; } public override ArgumentType Type => ArgumentType.Result; @@ -133,7 +134,7 @@ public class Result : ArgumentValue /// Creates a result argument value. /// /// The value of the argument. - public Result(Simulation.Core.Result value) => this.Value = value; + public Result(Core.Result value) => this.Value = value; } /// From 87fd479e63d2deb1198bb3ce01d2ddacefcf5325 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Thu, 15 Apr 2021 19:08:41 -0700 Subject: [PATCH 16/19] Use ImmutableArray --- src/Simulation/Core/ArgumentValue.cs | 7 ++++--- src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Simulation/Core/ArgumentValue.cs b/src/Simulation/Core/ArgumentValue.cs index b5ba4d5d62d..7769e8fbdea 100644 --- a/src/Simulation/Core/ArgumentValue.cs +++ b/src/Simulation/Core/ArgumentValue.cs @@ -3,6 +3,7 @@ #nullable enable +using System.Collections.Immutable; using System.Linq; using Microsoft.Quantum.Simulation.Core; using Core = Microsoft.Quantum.Simulation.Core; @@ -164,11 +165,11 @@ public class Array : ArgumentValue /// /// The values of the argument. /// - public IQArray Values { get; } + public ImmutableArray Values { get; } public override ArgumentType Type { get; } - private Array(IQArray values, ArgumentType itemType) => + private Array(ImmutableArray values, ArgumentType itemType) => (this.Values, this.Type) = (values, new ArgumentType.Array(itemType)); /// @@ -177,7 +178,7 @@ private Array(IQArray values, ArgumentType itemType) => /// The values of the argument. /// The type of the values. /// The array or null if not all values have the type . - public static Array? TryCreate(IQArray values, ArgumentType itemType) => + public static Array? TryCreate(ImmutableArray values, ArgumentType itemType) => values.All(value => value.Type == itemType) ? new Array(values, itemType) : null; } } diff --git a/src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj b/src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj index b5169a63955..866adc91ba0 100644 --- a/src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj +++ b/src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj @@ -18,6 +18,7 @@ + From d23898536de57b8dd6cc3fb4c18375ac869dc3c8 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Thu, 15 Apr 2021 20:57:13 -0700 Subject: [PATCH 17/19] Remove == overload --- src/Simulation/Core/ArgumentType.cs | 13 +------------ src/Simulation/Core/ArgumentValue.cs | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/Simulation/Core/ArgumentType.cs b/src/Simulation/Core/ArgumentType.cs index b2e9f03dba4..7dc2db55f22 100644 --- a/src/Simulation/Core/ArgumentType.cs +++ b/src/Simulation/Core/ArgumentType.cs @@ -3,9 +3,6 @@ #nullable enable -using System; -using System.Runtime.CompilerServices; - namespace Microsoft.Quantum.Runtime { /// @@ -70,15 +67,7 @@ public class Array : ArgumentType public override bool Equals(object obj) => obj is Array array && this.Item.Equals(array.Item); - public override int GetHashCode() => HashCode.Combine(1, this.Item.GetHashCode()); + public override int GetHashCode() => this.Item.GetHashCode() + 1; } - - public override bool Equals(object obj) => ReferenceEquals(this, obj); - - public override int GetHashCode() => RuntimeHelpers.GetHashCode(this); - - public static bool operator ==(ArgumentType lhs, ArgumentType rhs) => lhs.Equals(rhs); - - public static bool operator !=(ArgumentType lhs, ArgumentType rhs) => !(lhs == rhs); } } diff --git a/src/Simulation/Core/ArgumentValue.cs b/src/Simulation/Core/ArgumentValue.cs index 7769e8fbdea..8f9c713b29b 100644 --- a/src/Simulation/Core/ArgumentValue.cs +++ b/src/Simulation/Core/ArgumentValue.cs @@ -179,7 +179,7 @@ private Array(ImmutableArray values, ArgumentType itemType) => /// The type of the values. /// The array or null if not all values have the type . public static Array? TryCreate(ImmutableArray values, ArgumentType itemType) => - values.All(value => value.Type == itemType) ? new Array(values, itemType) : null; + values.All(value => value.Type.Equals(itemType)) ? new Array(values, itemType) : null; } } } From e69141a1a99121fd9f049f4d43e1b12c803d5dc8 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Fri, 16 Apr 2021 14:51:50 -0700 Subject: [PATCH 18/19] Use Submitter suffix for new interfaces --- src/Simulation/Core/IAzureMachine.cs | 25 ------------------- src/Simulation/Core/IAzureSubmitter.cs | 24 ++++++++++++++++++ .../Core/{IQirMachine.cs => IQirSubmitter.cs} | 4 +-- src/Simulation/Core/IQuantumMachine.cs | 4 +-- 4 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 src/Simulation/Core/IAzureMachine.cs create mode 100644 src/Simulation/Core/IAzureSubmitter.cs rename src/Simulation/Core/{IQirMachine.cs => IQirSubmitter.cs} (88%) diff --git a/src/Simulation/Core/IAzureMachine.cs b/src/Simulation/Core/IAzureMachine.cs deleted file mode 100644 index f5444521e7b..00000000000 --- a/src/Simulation/Core/IAzureMachine.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#nullable enable - -namespace Microsoft.Quantum.Runtime -{ - /// - /// A machine that can execute quantum programs on Azure. - /// - public interface IAzureMachine - { - /// - /// Gets the ID of the quantum machine provider. - /// - string ProviderId { get; } - - /// - /// Gets the name of the target quantum machine. - /// A provider may expose multiple targets that can be used to execute programs. - /// Users may select which target they would like to be used for execution. - /// - string Target { get; } - } -} diff --git a/src/Simulation/Core/IAzureSubmitter.cs b/src/Simulation/Core/IAzureSubmitter.cs new file mode 100644 index 00000000000..0fc11515b3f --- /dev/null +++ b/src/Simulation/Core/IAzureSubmitter.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#nullable enable + +namespace Microsoft.Quantum.Runtime +{ + /// + /// An interface for submitting quantum programs to Azure. + /// + public interface IAzureSubmitter + { + /// + /// The ID of the quantum machine provider. + /// + string ProviderId { get; } + + /// + /// The name of the target quantum machine. A provider may expose multiple targets that can be used to execute + /// programs. Users may select which target they would like to be used for execution. + /// + string Target { get; } + } +} diff --git a/src/Simulation/Core/IQirMachine.cs b/src/Simulation/Core/IQirSubmitter.cs similarity index 88% rename from src/Simulation/Core/IQirMachine.cs rename to src/Simulation/Core/IQirSubmitter.cs index 1519990852c..f18c171c6f0 100644 --- a/src/Simulation/Core/IQirMachine.cs +++ b/src/Simulation/Core/IQirSubmitter.cs @@ -10,9 +10,9 @@ namespace Microsoft.Quantum.Runtime { /// - /// A machine that can execute QIR programs on Azure. + /// An interface for submitting QIR programs to Azure. /// - public interface IQirMachine : IAzureMachine + public interface IQirSubmitter : IAzureSubmitter { /// /// Submits a job to execute a QIR program without waiting for execution to complete. diff --git a/src/Simulation/Core/IQuantumMachine.cs b/src/Simulation/Core/IQuantumMachine.cs index 2d81d39ec0a..361a6eea37a 100644 --- a/src/Simulation/Core/IQuantumMachine.cs +++ b/src/Simulation/Core/IQuantumMachine.cs @@ -7,9 +7,9 @@ namespace Microsoft.Quantum.Runtime { /// - /// Interface that a quantum machine must implement. + /// An interface for submitting Q# programs to Azure. /// - public interface IQuantumMachine : IAzureMachine + public interface IQuantumMachine : IAzureSubmitter { /// /// Function that configures a job object before submission. From d6b0689c62890a2bcddf0dfed4dbc34d3470585c Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Fri, 16 Apr 2021 17:48:02 -0700 Subject: [PATCH 19/19] Move new interfaces to Submitters folder --- src/Simulation/Core/{ => Submitters}/IAzureSubmitter.cs | 0 src/Simulation/Core/{ => Submitters}/IQirSubmitter.cs | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/Simulation/Core/{ => Submitters}/IAzureSubmitter.cs (100%) rename src/Simulation/Core/{ => Submitters}/IQirSubmitter.cs (100%) diff --git a/src/Simulation/Core/IAzureSubmitter.cs b/src/Simulation/Core/Submitters/IAzureSubmitter.cs similarity index 100% rename from src/Simulation/Core/IAzureSubmitter.cs rename to src/Simulation/Core/Submitters/IAzureSubmitter.cs diff --git a/src/Simulation/Core/IQirSubmitter.cs b/src/Simulation/Core/Submitters/IQirSubmitter.cs similarity index 100% rename from src/Simulation/Core/IQirSubmitter.cs rename to src/Simulation/Core/Submitters/IQirSubmitter.cs