From 9788303439da935469f9a7ee4b36c363f16e4c02 Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Fri, 17 Jul 2020 16:12:19 -0400 Subject: [PATCH 01/15] Add composite operation handling --- .../ExecutionPathTracer.cs | 57 +++++++++++++++++-- src/Tests/ExecutionPathTracerTests.cs | 41 +++++++++++++ .../Workspace.ExecutionPathTracer/Canon.qs | 17 ++++++ 3 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 src/Tests/Workspace.ExecutionPathTracer/Canon.qs diff --git a/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs b/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs index b3fef025cc..c5734b0aaf 100644 --- a/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs +++ b/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs @@ -19,6 +19,8 @@ public class ExecutionPathTracer { private int currentDepth = 0; private int renderDepth; + private ICallable? currCompositeOp = null; + private ExecutionPathTracer? compositeTracer = null; private Operation? currentOperation = null; private IDictionary qubitRegisters = new Dictionary(); private IDictionary> classicalRegisters = new Dictionary>(); @@ -55,15 +57,36 @@ public void OnOperationStartHandler(ICallable operation, IApplyData arguments) { this.currentDepth++; + // If `compositeTracer` is initialized, pass operations into it instead + if (this.compositeTracer != null) + { + this.compositeTracer.OnOperationStartHandler(operation, arguments); + } // Parse operations at or above specified depth - if (this.currentDepth <= this.renderDepth) + else if (this.currentDepth <= this.renderDepth) { var metadata = operation.GetRuntimeMetadata(arguments); + Operation? parsedOp = null; + + // If metadata is a composite operation (i.e. want to trace its components instead), + // we recursively create a tracer that traces its components instead + if (metadata != null && metadata.IsComposite) + { + this.compositeTracer = new ExecutionPathTracer(0); + // Attach our registers by reference to compositeTracer + this.compositeTracer.qubitRegisters = this.qubitRegisters; + this.compositeTracer.classicalRegisters = this.classicalRegisters; + this.currCompositeOp = operation; + } + else + { + parsedOp = this.MetadataToOperation(metadata); + } // Save parsed operation as a potential candidate for rendering. // We only want to render the operation at the lowest depth, so we keep // a running track of the lowest operation seen in the stack thus far. - this.currentOperation = this.MetadataToOperation(metadata); + this.currentOperation = parsedOp; } } @@ -75,9 +98,23 @@ public void OnOperationStartHandler(ICallable operation, IApplyData arguments) public void OnOperationEndHandler(ICallable operation, IApplyData result) { this.currentDepth--; - // Add parsed operation to list of operations, if not null - if (this.currentOperation != null) + + if (operation == this.currCompositeOp) + { + // If the current operation is the composite operation we start with, append + // the operations traced out by the `compositeTracer` to the current list of operations + this.AddCompositeOperations(); + this.currCompositeOp = null; + this.compositeTracer = null; + } + else if (this.compositeTracer != null) + { + // If `compositeTracer` is initialized, we pass operations down to it for handling + this.compositeTracer.OnOperationEndHandler(operation, result); + } + else if (this.currentOperation != null) { + // Add parsed operation to list of operations, if not null this.operations.Add(this.currentOperation); // Reset current operation to null this.currentOperation = null; @@ -129,6 +166,18 @@ private ClassicalRegister GetClassicalRegister(Qubit controlQubit) return this.classicalRegisters[qId][cId]; } + /// + /// Parse s traced out by the compositeTracer. + /// + private void AddCompositeOperations() + { + if (this.compositeTracer == null) + throw new NullReferenceException("ERROR: compositeTracer not initialized."); + + // The composite tracer has done its job and we retrieve the operations it traced + this.operations.AddRange(this.compositeTracer.operations); + } + /// /// Parse into its corresponding . /// diff --git a/src/Tests/ExecutionPathTracerTests.cs b/src/Tests/ExecutionPathTracerTests.cs index 3397bd1169..cf0ae0be96 100644 --- a/src/Tests/ExecutionPathTracerTests.cs +++ b/src/Tests/ExecutionPathTracerTests.cs @@ -580,6 +580,47 @@ public void BigTest() var expected = new ExecutionPath(qubits, operations); Assert.AreEqual(expected.ToJson(), path.ToJson()); } + + [TestMethod] + public void CompositeTest() + { + var path = GetExecutionPath("ApplyToEachCirc"); + var qubits = new QubitDeclaration[] + { + new QubitDeclaration(0), + new QubitDeclaration(1), + new QubitDeclaration(2), + }; + var operations = new Operation[] + { + new Operation() + { + Gate = "H", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "H", + Targets = new List() { new QubitRegister(1) }, + }, + new Operation() + { + Gate = "H", + Targets = new List() { new QubitRegister(2) }, + }, + new Operation() + { + Gate = "ResetAll", + Targets = new List() { + new QubitRegister(0), + new QubitRegister(1), + new QubitRegister(2), + }, + }, + }; + var expected = new ExecutionPath(qubits, operations); + Assert.AreEqual(expected.ToJson(), path.ToJson()); + } } [TestClass] diff --git a/src/Tests/Workspace.ExecutionPathTracer/Canon.qs b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs new file mode 100644 index 0000000000..516f05b9de --- /dev/null +++ b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Tests.ExecutionPathTracer { + + open Microsoft.Quantum.Canon; + + operation ApplyToEachCirc() : Unit { + using (qs = Qubit[3]) { + ApplyToEach(H, qs); + ResetAll(qs); + } + } + +} + + From 4cf7a4635862955883ee7788338ecdfd1308394d Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Wed, 22 Jul 2020 16:16:48 -0400 Subject: [PATCH 02/15] Add ForEach tests --- src/Tests/ExecutionPathTracerTests.cs | 34 ++++++++++++++++++- .../Measurement.qs | 7 ++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Tests/ExecutionPathTracerTests.cs b/src/Tests/ExecutionPathTracerTests.cs index cf0ae0be96..3694963431 100644 --- a/src/Tests/ExecutionPathTracerTests.cs +++ b/src/Tests/ExecutionPathTracerTests.cs @@ -580,9 +580,13 @@ public void BigTest() var expected = new ExecutionPath(qubits, operations); Assert.AreEqual(expected.ToJson(), path.ToJson()); } + } + [TestClass] + public class CanonTests : ExecutionPathTracerTests + { [TestMethod] - public void CompositeTest() + public void ApplyToEachTest() { var path = GetExecutionPath("ApplyToEachCirc"); var qubits = new QubitDeclaration[] @@ -691,5 +695,33 @@ public void MResetZTest() var expected = new ExecutionPath(qubits, operations); Assert.AreEqual(expected.ToJson(), path.ToJson()); } + + [TestMethod] + public void ForEachMeasureCirc() + { + var path = GetExecutionPath("ForEachMeasureCirc"); + var qubits = new QubitDeclaration[] + { + new QubitDeclaration(0, 1), + new QubitDeclaration(1, 1), + }; + var operations = new Operation[] + { + new Operation() + { + Gate = "measure", + Controls = new List() { new QubitRegister(0) }, + Targets = new List() { new ClassicalRegister(0, 0) }, + }, + new Operation() + { + Gate = "measure", + Controls = new List() { new QubitRegister(1) }, + Targets = new List() { new ClassicalRegister(0, 0) }, + }, + }; + var expected = new ExecutionPath(qubits, operations); + Assert.AreEqual(expected.ToJson(), path.ToJson()); + } } } diff --git a/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs b/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs index 01efa8d5f8..563f79c53a 100644 --- a/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs +++ b/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs @@ -4,6 +4,7 @@ namespace Tests.ExecutionPathTracer { open Microsoft.Quantum.Measurement; + open Microsoft.Quantum.Arrays; operation MResetXCirc() : Unit { using (q = Qubit()) { @@ -22,6 +23,12 @@ namespace Tests.ExecutionPathTracer { let res = MResetZ(q); } } + + operation ForEachMeasureCirc() : Unit { + using (qs = Qubit[2]) { + let res = ForEach(MResetZ, qs); + } + } } From bddbce97bb16afe16eb187806b0fa3b43f8b9c63 Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Wed, 22 Jul 2020 16:19:40 -0400 Subject: [PATCH 03/15] Add Canon.qs to Tests.IQSharp.csproj --- src/Tests/Tests.IQsharp.csproj | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Tests/Tests.IQsharp.csproj b/src/Tests/Tests.IQsharp.csproj index 115a5896eb..2a29dfef26 100644 --- a/src/Tests/Tests.IQsharp.csproj +++ b/src/Tests/Tests.IQsharp.csproj @@ -49,13 +49,16 @@ PreserveNewest - + PreserveNewest - + PreserveNewest - + + PreserveNewest + + PreserveNewest From b854166283dee6363d68e26817709b33f56d1cd4 Mon Sep 17 00:00:00 2001 From: "Project Collection Build Service (ms-quantum)" <> Date: Fri, 24 Jul 2020 23:38:37 +0000 Subject: [PATCH 04/15] Build 0.12.2007.2412. --- images/iqsharp-base/Dockerfile | 2 +- src/AzureClient/AzureClient.csproj | 2 +- src/Core/Core.csproj | 6 ++--- src/Mock.Chemistry/Mock.Chemistry.csproj | 4 ++-- src/Tool/appsettings.json | 30 ++++++++++++------------ 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/images/iqsharp-base/Dockerfile b/images/iqsharp-base/Dockerfile index ca13b38bed..705b045e71 100644 --- a/images/iqsharp-base/Dockerfile +++ b/images/iqsharp-base/Dockerfile @@ -109,7 +109,7 @@ ENV PATH=$PATH:${HOME}/dotnet:${HOME}/.dotnet/tools \ # Install IQ# and the project templates, using the NuGet packages from the # build context. ARG IQSHARP_VERSION -RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20072301-beta" && \ +RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20072412-beta" && \ dotnet tool install \ --global \ Microsoft.Quantum.IQSharp \ diff --git a/src/AzureClient/AzureClient.csproj b/src/AzureClient/AzureClient.csproj index 2a99281c8f..6ed7239ce6 100644 --- a/src/AzureClient/AzureClient.csproj +++ b/src/AzureClient/AzureClient.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 4ce33a64ee..fd5a7ef673 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -38,9 +38,9 @@ - - - + + + diff --git a/src/Mock.Chemistry/Mock.Chemistry.csproj b/src/Mock.Chemistry/Mock.Chemistry.csproj index b8b345ce83..bd6c810731 100644 --- a/src/Mock.Chemistry/Mock.Chemistry.csproj +++ b/src/Mock.Chemistry/Mock.Chemistry.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -6,6 +6,6 @@ - + diff --git a/src/Tool/appsettings.json b/src/Tool/appsettings.json index f3fd49e8e7..4ea9210dbd 100644 --- a/src/Tool/appsettings.json +++ b/src/Tool/appsettings.json @@ -6,25 +6,25 @@ }, "AllowedHosts": "*", "DefaultPackageVersions": [ - "Microsoft.Quantum.Compiler::0.12.20072301-beta", + "Microsoft.Quantum.Compiler::0.12.20072412-beta", - "Microsoft.Quantum.CsharpGeneration::0.12.20072301-beta", - "Microsoft.Quantum.Development.Kit::0.12.20072301-beta", - "Microsoft.Quantum.Simulators::0.12.20072301-beta", - "Microsoft.Quantum.Xunit::0.12.20072301-beta", + "Microsoft.Quantum.CsharpGeneration::0.12.20072412-beta", + "Microsoft.Quantum.Development.Kit::0.12.20072412-beta", + "Microsoft.Quantum.Simulators::0.12.20072412-beta", + "Microsoft.Quantum.Xunit::0.12.20072412-beta", - "Microsoft.Quantum.Standard::0.12.20072301-beta", - "Microsoft.Quantum.Chemistry::0.12.20072301-beta", - "Microsoft.Quantum.Chemistry.Jupyter::0.12.20072301-beta", - "Microsoft.Quantum.MachineLearning::0.12.20072301-beta", - "Microsoft.Quantum.Numerics::0.12.20072301-beta", + "Microsoft.Quantum.Standard::0.12.20072412-beta", + "Microsoft.Quantum.Chemistry::0.12.20072412-beta", + "Microsoft.Quantum.Chemistry.Jupyter::0.12.20072412-beta", + "Microsoft.Quantum.MachineLearning::0.12.20072412-beta", + "Microsoft.Quantum.Numerics::0.12.20072412-beta", - "Microsoft.Quantum.Katas::0.12.20072301-beta", + "Microsoft.Quantum.Katas::0.12.20072412-beta", - "Microsoft.Quantum.Research::0.12.20072301-beta", + "Microsoft.Quantum.Research::0.12.20072412-beta", - "Microsoft.Quantum.Providers.IonQ::0.12.20072301-beta", - "Microsoft.Quantum.Providers.Honeywell::0.12.20072301-beta", - "Microsoft.Quantum.Providers.QCI::0.12.20072301-beta" + "Microsoft.Quantum.Providers.IonQ::0.12.20072412-beta", + "Microsoft.Quantum.Providers.Honeywell::0.12.20072412-beta", + "Microsoft.Quantum.Providers.QCI::0.12.20072412-beta" ] } From 4106cc9d319308be22b0990b31795aaada2f139b Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Sat, 25 Jul 2020 00:37:42 -0400 Subject: [PATCH 05/15] Fix ResetAll tests --- src/Tests/ExecutionPathTracerTests.cs | 95 +++++++++++++------ .../Workspace.ExecutionPathTracer/Canon.qs | 1 + 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/Tests/ExecutionPathTracerTests.cs b/src/Tests/ExecutionPathTracerTests.cs index 3694963431..eb5823c711 100644 --- a/src/Tests/ExecutionPathTracerTests.cs +++ b/src/Tests/ExecutionPathTracerTests.cs @@ -104,8 +104,13 @@ public void CnotTest() }, new Operation() { - Gate = "ResetAll", - Targets = new List() { new QubitRegister(0), new QubitRegister(1) }, + Gate = "Reset", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(1) }, }, }; var expected = new ExecutionPath(qubits, operations); @@ -133,13 +138,18 @@ public void CcnotTest() }, new Operation() { - Gate = "ResetAll", - Targets = new List() - { - new QubitRegister(0), - new QubitRegister(1), - new QubitRegister(2), - }, + Gate = "Reset", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(1) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(2) }, }, }; var expected = new ExecutionPath(qubits, operations); @@ -239,8 +249,13 @@ public void ControlledXTest() }, new Operation() { - Gate = "ResetAll", - Targets = new List() { new QubitRegister(0), new QubitRegister(1) }, + Gate = "Reset", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(1) }, }, }; var expected = new ExecutionPath(qubits, operations); @@ -272,8 +287,13 @@ public void ControlledAdjointSTest() }, new Operation() { - Gate = "ResetAll", - Targets = new List() { new QubitRegister(0), new QubitRegister(1) }, + Gate = "Reset", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(1) }, }, }; var expected = new ExecutionPath(qubits, operations); @@ -416,12 +436,13 @@ public void PartialOpTest() }, new Operation() { - Gate = "ResetAll", - Targets = new List() { - new QubitRegister(0), - new QubitRegister(1), - new QubitRegister(2), - }, + Gate = "Reset", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(1) }, }, }; var expected = new ExecutionPath(qubits, operations); @@ -569,12 +590,18 @@ public void BigTest() }, new Operation() { - Gate = "ResetAll", - Targets = new List() { - new QubitRegister(0), - new QubitRegister(1), - new QubitRegister(2), - }, + Gate = "Reset", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(1) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(2) }, }, }; var expected = new ExecutionPath(qubits, operations); @@ -614,12 +641,18 @@ public void ApplyToEachTest() }, new Operation() { - Gate = "ResetAll", - Targets = new List() { - new QubitRegister(0), - new QubitRegister(1), - new QubitRegister(2), - }, + Gate = "Reset", + Targets = new List() { new QubitRegister(0) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(1) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(2) }, }, }; var expected = new ExecutionPath(qubits, operations); diff --git a/src/Tests/Workspace.ExecutionPathTracer/Canon.qs b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs index 516f05b9de..13fc2d2098 100644 --- a/src/Tests/Workspace.ExecutionPathTracer/Canon.qs +++ b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs @@ -4,6 +4,7 @@ namespace Tests.ExecutionPathTracer { open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Intrinsic; operation ApplyToEachCirc() : Unit { using (qs = Qubit[3]) { From c332f5fd3f2dab6d2af8c0ddb5f7369311ba88b5 Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 30 Jul 2020 17:16:46 -0400 Subject: [PATCH 06/15] Fix tests to allow using Microsoft.Quantum.Canon --- .../Mock.Chemistry/Library.qs | 2 - .../Mock.Chemistry/Mock.Chemistry.csproj | 0 src/MockLibraries/Mock.Standard/Arrays.cs | 19 ++++++++ src/MockLibraries/Mock.Standard/Arrays.qs | 43 +++++++++++++++++++ src/MockLibraries/Mock.Standard/Canon.cs | 19 ++++++++ src/MockLibraries/Mock.Standard/Canon.qs | 43 +++++++++++++++++++ .../Mock.Standard/Mock.Standard.csproj | 11 +++++ src/Tests/ExecutionPathTracerTests.cs | 29 ++++++++++--- src/Tests/Mocks.cs | 9 +++- src/Tests/Tests.IQsharp.csproj | 3 +- .../Workspace.ExecutionPathTracer/Canon.qs | 6 +-- .../Measurement.qs | 7 +-- 12 files changed, 175 insertions(+), 16 deletions(-) rename src/{ => MockLibraries}/Mock.Chemistry/Library.qs (99%) rename src/{ => MockLibraries}/Mock.Chemistry/Mock.Chemistry.csproj (100%) create mode 100644 src/MockLibraries/Mock.Standard/Arrays.cs create mode 100644 src/MockLibraries/Mock.Standard/Arrays.qs create mode 100644 src/MockLibraries/Mock.Standard/Canon.cs create mode 100644 src/MockLibraries/Mock.Standard/Canon.qs create mode 100644 src/MockLibraries/Mock.Standard/Mock.Standard.csproj diff --git a/src/Mock.Chemistry/Library.qs b/src/MockLibraries/Mock.Chemistry/Library.qs similarity index 99% rename from src/Mock.Chemistry/Library.qs rename to src/MockLibraries/Mock.Chemistry/Library.qs index 1f95182e28..247eea5d79 100644 --- a/src/Mock.Chemistry/Library.qs +++ b/src/MockLibraries/Mock.Chemistry/Library.qs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - // // These are mock classes that resemble the data structures defined in the chemistry library // @@ -9,7 +8,6 @@ namespace Mock.Chemistry { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon; - /// # Summary /// Format of data passed from C# to Q# to represent a term of the Hamiltonian. /// The meaning of the data represented is determined by the algorithm that receives it. diff --git a/src/Mock.Chemistry/Mock.Chemistry.csproj b/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj similarity index 100% rename from src/Mock.Chemistry/Mock.Chemistry.csproj rename to src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj diff --git a/src/MockLibraries/Mock.Standard/Arrays.cs b/src/MockLibraries/Mock.Standard/Arrays.cs new file mode 100644 index 0000000000..c3e930e07b --- /dev/null +++ b/src/MockLibraries/Mock.Standard/Arrays.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using System; + +namespace Mock.Standard +{ + public partial class ForEach<__T__, __U__> + { + public override RuntimeMetadata GetRuntimeMetadata(IApplyData args) + { + var metadata = base.GetRuntimeMetadata(args); + if (metadata == null) throw new NullReferenceException($"Null RuntimeMetadata found for {this.ToString()}."); + metadata.IsComposite = true; + return metadata; + } + } +} diff --git a/src/MockLibraries/Mock.Standard/Arrays.qs b/src/MockLibraries/Mock.Standard/Arrays.qs new file mode 100644 index 0000000000..5c2cfd3302 --- /dev/null +++ b/src/MockLibraries/Mock.Standard/Arrays.qs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// +// These are mock classes that resemble the data structures defined in the Microsoft.Quantum.Arrays library +// +namespace Mock.Standard { + open Microsoft.Quantum.Arrays; + + /// # Summary + /// Given an array and an operation that is defined + /// for the elements of the array, returns a new array that consists + /// of the images of the original array under the operation. + /// + /// # Remarks + /// The operation is defined for generic types, i.e., whenever we have + /// an array `'T[]` and an operation `action : 'T -> 'U` we can map the elements + /// of the array and produce a new array of type `'U[]`. + /// + /// # Type Parameters + /// ## 'T + /// The type of `array` elements. + /// ## 'U + /// The result type of the `action` operation. + /// + /// # Input + /// ## action + /// An operation from `'T` to `'U` that is applied to each element. + /// ## array + /// An array of elements over `'T`. + /// + /// # Output + /// An array `'U[]` of elements that are mapped by the `action` operation. + operation ForEach<'T, 'U> (action : ('T => 'U), array : 'T[]) : 'U[] { + mutable resultArray = new 'U[Length(array)]; + + for (idxElement in IndexRange(array)) { + set resultArray w/= idxElement <- action(array[idxElement]); + } + + return resultArray; + } +} \ No newline at end of file diff --git a/src/MockLibraries/Mock.Standard/Canon.cs b/src/MockLibraries/Mock.Standard/Canon.cs new file mode 100644 index 0000000000..3d28a19152 --- /dev/null +++ b/src/MockLibraries/Mock.Standard/Canon.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using System; + +namespace Mock.Standard +{ + public partial class ApplyToEach<__T__> + { + public override RuntimeMetadata GetRuntimeMetadata(IApplyData args) + { + var metadata = base.GetRuntimeMetadata(args); + if (metadata == null) throw new NullReferenceException($"Null RuntimeMetadata found for {this.ToString()}."); + metadata.IsComposite = true; + return metadata; + } + } +} diff --git a/src/MockLibraries/Mock.Standard/Canon.qs b/src/MockLibraries/Mock.Standard/Canon.qs new file mode 100644 index 0000000000..b7379338af --- /dev/null +++ b/src/MockLibraries/Mock.Standard/Canon.qs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// +// These are mock classes that resemble the data structures defined in the Microsoft.Quantum.Canon library +// +namespace Mock.Standard { + open Microsoft.Quantum.Arrays; + + /// # Summary + /// Applies a single-qubit operation to each element in a register. + /// + /// # Input + /// ## singleElementOperation + /// Operation to apply to each qubit. + /// ## register + /// Array of qubits on which to apply the given operation. + /// + /// # Type Parameters + /// ## 'T + /// The target on which the operation acts. + /// + /// # Remarks + /// ## Example + /// Prepare a three-qubit $\ket{+}$ state: + /// ```qsharp + /// using (register = Qubit[3]) { + /// ApplyToEach(H, register); + /// } + /// ``` + /// + /// # See Also + /// - Microsoft.Quantum.Canon.ApplyToEachC + /// - Microsoft.Quantum.Canon.ApplyToEachA + /// - Microsoft.Quantum.Canon.ApplyToEachCA + operation ApplyToEach<'T> (singleElementOperation : ('T => Unit), register : 'T[]) : Unit + { + for (idxQubit in IndexRange(register)) + { + singleElementOperation(register[idxQubit]); + } + } +} \ No newline at end of file diff --git a/src/MockLibraries/Mock.Standard/Mock.Standard.csproj b/src/MockLibraries/Mock.Standard/Mock.Standard.csproj new file mode 100644 index 0000000000..bd6c810731 --- /dev/null +++ b/src/MockLibraries/Mock.Standard/Mock.Standard.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.1 + false + + + + + + diff --git a/src/Tests/ExecutionPathTracerTests.cs b/src/Tests/ExecutionPathTracerTests.cs index eb5823c711..35796dcf0d 100644 --- a/src/Tests/ExecutionPathTracerTests.cs +++ b/src/Tests/ExecutionPathTracerTests.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.Quantum.IQSharp; -using Microsoft.Quantum.Simulation.Simulators; +using Microsoft.Quantum.IQSharp.Kernel; using Microsoft.Quantum.IQSharp.Core.ExecutionPathTracer; +using Microsoft.Quantum.Simulation.Simulators; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Tests.IQSharp { @@ -14,9 +16,17 @@ public class ExecutionPathTracerTests { public Workspace InitWorkspace() { - var ws = Startup.Create("Workspace.ExecutionPathTracer"); + var engine = Startup.Create("Workspace.ExecutionPathTracer"); + var snippets = engine.Snippets as Snippets; + + var pkgMagic = new PackageMagic(snippets.GlobalReferences); + var channel = new MockChannel(); + pkgMagic.Execute("mock.standard", channel).Wait(); + + var ws = snippets.Workspace as Workspace; ws.Reload(); Assert.IsFalse(ws.HasErrors); + return ws; } @@ -444,6 +454,11 @@ public void PartialOpTest() Gate = "Reset", Targets = new List() { new QubitRegister(1) }, }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(2) }, + }, }; var expected = new ExecutionPath(qubits, operations); Assert.AreEqual(expected.ToJson(), path.ToJson()); @@ -742,15 +757,17 @@ public void ForEachMeasureCirc() { new Operation() { - Gate = "measure", + Gate = "MResetZ", + IsMeasurement = true, Controls = new List() { new QubitRegister(0) }, Targets = new List() { new ClassicalRegister(0, 0) }, }, new Operation() { - Gate = "measure", + Gate = "MResetZ", + IsMeasurement = true, Controls = new List() { new QubitRegister(1) }, - Targets = new List() { new ClassicalRegister(0, 0) }, + Targets = new List() { new ClassicalRegister(1, 0) }, }, }; var expected = new ExecutionPath(qubits, operations); diff --git a/src/Tests/Mocks.cs b/src/Tests/Mocks.cs index 8b668d7b07..9485061eb9 100644 --- a/src/Tests/Mocks.cs +++ b/src/Tests/Mocks.cs @@ -141,6 +141,8 @@ public class MockNugetPackages : INugetPackages { private static readonly AssemblyInfo MockChemistryAssembly = new AssemblyInfo(typeof(Mock.Chemistry.JordanWignerEncodingData).Assembly); + private static readonly AssemblyInfo MockStandardAssembly = new AssemblyInfo(typeof(Mock.Standard.ApplyToEach).Assembly); + List _items = new List(); public IEnumerable Items => _items; @@ -149,10 +151,15 @@ public IEnumerable Assemblies { get { - if (_items.Select(p => p.Id).Contains("mock.chemistry")) + var packageIds = _items.Select(p => p.Id); + if (packageIds.Contains("mock.chemistry")) { yield return MockChemistryAssembly; } + else if (packageIds.Contains("mock.standard")) + { + yield return MockStandardAssembly; + } } } diff --git a/src/Tests/Tests.IQsharp.csproj b/src/Tests/Tests.IQsharp.csproj index 2a29dfef26..059313ded9 100644 --- a/src/Tests/Tests.IQsharp.csproj +++ b/src/Tests/Tests.IQsharp.csproj @@ -28,7 +28,8 @@ - + + diff --git a/src/Tests/Workspace.ExecutionPathTracer/Canon.qs b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs index 13fc2d2098..658b765ba4 100644 --- a/src/Tests/Workspace.ExecutionPathTracer/Canon.qs +++ b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs @@ -3,16 +3,16 @@ namespace Tests.ExecutionPathTracer { - open Microsoft.Quantum.Canon; open Microsoft.Quantum.Intrinsic; - + open Mock.Standard; + operation ApplyToEachCirc() : Unit { using (qs = Qubit[3]) { ApplyToEach(H, qs); ResetAll(qs); } } - + } diff --git a/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs b/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs index 563f79c53a..1b78f87ff3 100644 --- a/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs +++ b/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs @@ -2,10 +2,11 @@ // Licensed under the MIT License. namespace Tests.ExecutionPathTracer { - + open Microsoft.Quantum.Measurement; open Microsoft.Quantum.Arrays; - + open Mock.Standard; + operation MResetXCirc() : Unit { using (q = Qubit()) { let res = MResetX(q); @@ -29,7 +30,7 @@ namespace Tests.ExecutionPathTracer { let res = ForEach(MResetZ, qs); } } - + } From f413c716b87decda6891fc4a413b1de652d77839 Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 30 Jul 2020 17:24:22 -0400 Subject: [PATCH 07/15] Add newline --- src/MockLibraries/Mock.Standard/Arrays.qs | 2 +- src/MockLibraries/Mock.Standard/Canon.qs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MockLibraries/Mock.Standard/Arrays.qs b/src/MockLibraries/Mock.Standard/Arrays.qs index 5c2cfd3302..4971810eab 100644 --- a/src/MockLibraries/Mock.Standard/Arrays.qs +++ b/src/MockLibraries/Mock.Standard/Arrays.qs @@ -40,4 +40,4 @@ namespace Mock.Standard { return resultArray; } -} \ No newline at end of file +} diff --git a/src/MockLibraries/Mock.Standard/Canon.qs b/src/MockLibraries/Mock.Standard/Canon.qs index b7379338af..2037f2c618 100644 --- a/src/MockLibraries/Mock.Standard/Canon.qs +++ b/src/MockLibraries/Mock.Standard/Canon.qs @@ -40,4 +40,4 @@ namespace Mock.Standard { singleElementOperation(register[idxQubit]); } } -} \ No newline at end of file +} From 99981b084c6043308d96f36eb04e41598038c0de Mon Sep 17 00:00:00 2001 From: "Project Collection Build Service (ms-quantum)" <> Date: Thu, 30 Jul 2020 16:09:17 +0000 Subject: [PATCH 08/15] Build 0.12.2007.3008. --- images/iqsharp-base/Dockerfile | 2 +- src/AzureClient/AzureClient.csproj | 2 +- src/Core/Core.csproj | 6 ++-- .../Mock.Chemistry/Mock.Chemistry.csproj | 4 +-- .../Mock.Standard/Mock.Standard.csproj | 4 +-- src/Tool/appsettings.json | 30 +++++++++---------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/images/iqsharp-base/Dockerfile b/images/iqsharp-base/Dockerfile index 705b045e71..738b1f292a 100644 --- a/images/iqsharp-base/Dockerfile +++ b/images/iqsharp-base/Dockerfile @@ -109,7 +109,7 @@ ENV PATH=$PATH:${HOME}/dotnet:${HOME}/.dotnet/tools \ # Install IQ# and the project templates, using the NuGet packages from the # build context. ARG IQSHARP_VERSION -RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20072412-beta" && \ +RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20073008-beta" && \ dotnet tool install \ --global \ Microsoft.Quantum.IQSharp \ diff --git a/src/AzureClient/AzureClient.csproj b/src/AzureClient/AzureClient.csproj index 6ed7239ce6..fc021e4a9a 100644 --- a/src/AzureClient/AzureClient.csproj +++ b/src/AzureClient/AzureClient.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index fd5a7ef673..f7a29284d3 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -38,9 +38,9 @@ - - - + + + diff --git a/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj b/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj index bd6c810731..7900c48c47 100644 --- a/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj +++ b/src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -6,6 +6,6 @@ - + diff --git a/src/MockLibraries/Mock.Standard/Mock.Standard.csproj b/src/MockLibraries/Mock.Standard/Mock.Standard.csproj index bd6c810731..7900c48c47 100644 --- a/src/MockLibraries/Mock.Standard/Mock.Standard.csproj +++ b/src/MockLibraries/Mock.Standard/Mock.Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -6,6 +6,6 @@ - + diff --git a/src/Tool/appsettings.json b/src/Tool/appsettings.json index 4ea9210dbd..7ec58902e5 100644 --- a/src/Tool/appsettings.json +++ b/src/Tool/appsettings.json @@ -6,25 +6,25 @@ }, "AllowedHosts": "*", "DefaultPackageVersions": [ - "Microsoft.Quantum.Compiler::0.12.20072412-beta", + "Microsoft.Quantum.Compiler::0.12.20073008-beta", - "Microsoft.Quantum.CsharpGeneration::0.12.20072412-beta", - "Microsoft.Quantum.Development.Kit::0.12.20072412-beta", - "Microsoft.Quantum.Simulators::0.12.20072412-beta", - "Microsoft.Quantum.Xunit::0.12.20072412-beta", + "Microsoft.Quantum.CsharpGeneration::0.12.20073008-beta", + "Microsoft.Quantum.Development.Kit::0.12.20073008-beta", + "Microsoft.Quantum.Simulators::0.12.20073008-beta", + "Microsoft.Quantum.Xunit::0.12.20073008-beta", - "Microsoft.Quantum.Standard::0.12.20072412-beta", - "Microsoft.Quantum.Chemistry::0.12.20072412-beta", - "Microsoft.Quantum.Chemistry.Jupyter::0.12.20072412-beta", - "Microsoft.Quantum.MachineLearning::0.12.20072412-beta", - "Microsoft.Quantum.Numerics::0.12.20072412-beta", + "Microsoft.Quantum.Standard::0.12.20073008-beta", + "Microsoft.Quantum.Chemistry::0.12.20073008-beta", + "Microsoft.Quantum.Chemistry.Jupyter::0.12.20073008-beta", + "Microsoft.Quantum.MachineLearning::0.12.20073008-beta", + "Microsoft.Quantum.Numerics::0.12.20073008-beta", - "Microsoft.Quantum.Katas::0.12.20072412-beta", + "Microsoft.Quantum.Katas::0.12.20073008-beta", - "Microsoft.Quantum.Research::0.12.20072412-beta", + "Microsoft.Quantum.Research::0.12.20073008-beta", - "Microsoft.Quantum.Providers.IonQ::0.12.20072412-beta", - "Microsoft.Quantum.Providers.Honeywell::0.12.20072412-beta", - "Microsoft.Quantum.Providers.QCI::0.12.20072412-beta" + "Microsoft.Quantum.Providers.IonQ::0.12.20073008-beta", + "Microsoft.Quantum.Providers.Honeywell::0.12.20073008-beta", + "Microsoft.Quantum.Providers.QCI::0.12.20073008-beta" ] } From ca7c696a43938fd339ac5bd00e959fb7a12e2ac9 Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 30 Jul 2020 18:08:37 -0400 Subject: [PATCH 09/15] Reformat ExecutionPathTracer stylistically --- .../ExecutionPathTracer.cs | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs b/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs index c5734b0aaf..830155fe1a 100644 --- a/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs +++ b/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs @@ -61,33 +61,32 @@ public void OnOperationStartHandler(ICallable operation, IApplyData arguments) if (this.compositeTracer != null) { this.compositeTracer.OnOperationStartHandler(operation, arguments); + return; } - // Parse operations at or above specified depth - else if (this.currentDepth <= this.renderDepth) - { - var metadata = operation.GetRuntimeMetadata(arguments); - Operation? parsedOp = null; - // If metadata is a composite operation (i.e. want to trace its components instead), - // we recursively create a tracer that traces its components instead - if (metadata != null && metadata.IsComposite) - { - this.compositeTracer = new ExecutionPathTracer(0); - // Attach our registers by reference to compositeTracer - this.compositeTracer.qubitRegisters = this.qubitRegisters; - this.compositeTracer.classicalRegisters = this.classicalRegisters; - this.currCompositeOp = operation; - } - else - { - parsedOp = this.MetadataToOperation(metadata); - } + // Only parse operations at or above (i.e. <= `renderDepth`) specified depth + if (this.currentDepth > this.renderDepth) return; + + var metadata = operation.GetRuntimeMetadata(arguments); - // Save parsed operation as a potential candidate for rendering. - // We only want to render the operation at the lowest depth, so we keep - // a running track of the lowest operation seen in the stack thus far. - this.currentOperation = parsedOp; + // If metadata is a composite operation (i.e. want to trace its components instead), + // we recursively create a tracer that traces its components instead + if (metadata != null && metadata.IsComposite) + { + this.compositeTracer = new ExecutionPathTracer(0); + // Attach our registers by reference to compositeTracer + this.compositeTracer.qubitRegisters = this.qubitRegisters; + this.compositeTracer.classicalRegisters = this.classicalRegisters; + this.currCompositeOp = operation; + // Set currentOperation to null so we don't render higher-depth operations unintentionally. + this.currentOperation = null; + return; } + + // Save parsed operation as a potential candidate for rendering. + // We only want to render the operation at the lowest depth, so we keep + // a running track of the lowest operation seen in the stack thus far. + this.currentOperation = this.MetadataToOperation(metadata); } /// @@ -99,24 +98,29 @@ public void OnOperationEndHandler(ICallable operation, IApplyData result) { this.currentDepth--; - if (operation == this.currCompositeOp) - { - // If the current operation is the composite operation we start with, append - // the operations traced out by the `compositeTracer` to the current list of operations - this.AddCompositeOperations(); - this.currCompositeOp = null; - this.compositeTracer = null; - } - else if (this.compositeTracer != null) + // If `compositeTracer` is not null, handle the incoming operation recursively. + if (this.compositeTracer != null) { - // If `compositeTracer` is initialized, we pass operations down to it for handling + // If the current operation is the composite operation we started with, append + // the operations traced out by the `compositeTracer` to the current list of + // operations and reset. + if (operation == this.currCompositeOp) + { + this.AddCompositeOperations(); + this.currCompositeOp = null; + this.compositeTracer = null; + return; + } + + // Pass operations down to it for handling this.compositeTracer.OnOperationEndHandler(operation, result); + return; } - else if (this.currentOperation != null) + + // Add latest parsed operation to list of operations, if not null + if (this.currentOperation != null) { - // Add parsed operation to list of operations, if not null this.operations.Add(this.currentOperation); - // Reset current operation to null this.currentOperation = null; } } From 484f08d7d87b1a83fc2b07d6c066b9ce9687c6e7 Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 30 Jul 2020 18:31:21 -0400 Subject: [PATCH 10/15] Fix iqsharp.sln --- iqsharp.sln | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/iqsharp.sln b/iqsharp.sln index b7abcb6152..38a7e6ff59 100644 --- a/iqsharp.sln +++ b/iqsharp.sln @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureClient", "src\AzureCli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jupyter", "src\Jupyter\Jupyter.csproj", "{19A9E2AB-8842-47E2-8E6A-6DD292B49E97}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock.Chemistry", "src\Mock.Chemistry\Mock.Chemistry.csproj", "{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock.Chemistry", "src\MockLibraries\Mock.Chemistry\Mock.Chemistry.csproj", "{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock.Standard", "src\MockLibraries\Mock.Standard\Mock.Standard.csproj", "{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -113,18 +115,30 @@ Global {19A9E2AB-8842-47E2-8E6A-6DD292B49E97}.Release|x64.Build.0 = Release|Any CPU {19A9E2AB-8842-47E2-8E6A-6DD292B49E97}.Release|x86.ActiveCfg = Release|Any CPU {19A9E2AB-8842-47E2-8E6A-6DD292B49E97}.Release|x86.Build.0 = Release|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x64.ActiveCfg = Debug|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x64.Build.0 = Debug|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x86.ActiveCfg = Debug|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x86.Build.0 = Debug|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|Any CPU.Build.0 = Release|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x64.ActiveCfg = Release|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x64.Build.0 = Release|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x86.ActiveCfg = Release|Any CPU - {2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x86.Build.0 = Release|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x64.ActiveCfg = Debug|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x64.Build.0 = Debug|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x86.ActiveCfg = Debug|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x86.Build.0 = Debug|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|Any CPU.Build.0 = Release|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x64.ActiveCfg = Release|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x64.Build.0 = Release|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x86.ActiveCfg = Release|Any CPU + {AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x86.Build.0 = Release|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x64.ActiveCfg = Debug|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x64.Build.0 = Debug|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x86.ActiveCfg = Debug|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x86.Build.0 = Debug|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|Any CPU.Build.0 = Release|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x64.ActiveCfg = Release|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x64.Build.0 = Release|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x86.ActiveCfg = Release|Any CPU + {854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 34072543d367c04aa296d82a9131e89ea332445e Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 30 Jul 2020 18:48:17 -0400 Subject: [PATCH 11/15] Empty commit to retrigger CI From 83bdf647d1416e2e6e9b59c5ec2461979e39744e Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 30 Jul 2020 20:11:23 -0400 Subject: [PATCH 12/15] Remove dotnet test args --- build/test.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/test.ps1 b/build/test.ps1 index be6b89ba65..6d0f8c8351 100644 --- a/build/test.ps1 +++ b/build/test.ps1 @@ -102,7 +102,7 @@ function Test-JavaScript { } } -Test-One '../iqsharp.sln' @("AzureClient", "IQSharpEngine", "Workspace") +Test-One '../iqsharp.sln' if ($Env:ENABLE_PYTHON -eq "false") { Write-Host "##vso[task.logissue type=warning;]Skipping Testing Python packages. Env:ENABLE_PYTHON was set to 'false'." From 2225021dd7b2c557193817e73be5130b6644497d Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 30 Jul 2020 20:28:08 -0400 Subject: [PATCH 13/15] Fix broken build --- build/test.ps1 | 2 +- src/Tests/ExecutionPathTracerTests.cs | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/build/test.ps1 b/build/test.ps1 index 6d0f8c8351..be6b89ba65 100644 --- a/build/test.ps1 +++ b/build/test.ps1 @@ -102,7 +102,7 @@ function Test-JavaScript { } } -Test-One '../iqsharp.sln' +Test-One '../iqsharp.sln' @("AzureClient", "IQSharpEngine", "Workspace") if ($Env:ENABLE_PYTHON -eq "false") { Write-Host "##vso[task.logissue type=warning;]Skipping Testing Python packages. Env:ENABLE_PYTHON was set to 'false'." diff --git a/src/Tests/ExecutionPathTracerTests.cs b/src/Tests/ExecutionPathTracerTests.cs index 35796dcf0d..ffd70d71a1 100644 --- a/src/Tests/ExecutionPathTracerTests.cs +++ b/src/Tests/ExecutionPathTracerTests.cs @@ -5,7 +5,6 @@ using System.Linq; using Microsoft.Quantum.IQSharp; -using Microsoft.Quantum.IQSharp.Kernel; using Microsoft.Quantum.IQSharp.Core.ExecutionPathTracer; using Microsoft.Quantum.Simulation.Simulators; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -16,17 +15,10 @@ public class ExecutionPathTracerTests { public Workspace InitWorkspace() { - var engine = Startup.Create("Workspace.ExecutionPathTracer"); - var snippets = engine.Snippets as Snippets; - - var pkgMagic = new PackageMagic(snippets.GlobalReferences); - var channel = new MockChannel(); - pkgMagic.Execute("mock.standard", channel).Wait(); - - var ws = snippets.Workspace as Workspace; + var ws = Startup.Create("Workspace.ExecutionPathTracer"); + ws.GlobalReferences.AddPackage("mock.standard").Wait(); ws.Reload(); Assert.IsFalse(ws.HasErrors); - return ws; } From f27eb23225408ea0dd4d52a5778283335211be2e Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Fri, 31 Jul 2020 09:56:21 -0400 Subject: [PATCH 14/15] Fix TraceMagic test --- src/Tests/IQsharpEngineTests.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Tests/IQsharpEngineTests.cs b/src/Tests/IQsharpEngineTests.cs index 2dff15d348..9d0197b347 100644 --- a/src/Tests/IQsharpEngineTests.cs +++ b/src/Tests/IQsharpEngineTests.cs @@ -88,11 +88,16 @@ public static async Task AssertEstimate(IQSharpEngine engine, string sni private async Task AssertTrace(string name, ExecutionPath expectedPath) { var engine = Init("Workspace.ExecutionPathTracer"); + var snippets = engine.Snippets as Snippets; var configSource = new ConfigurationSource(skipLoading: true); + var pkgMagic = new PackageMagic(snippets.GlobalReferences); var traceMagic = new TraceMagic(engine.SymbolsResolver, configSource); var channel = new MockChannel(); - var response = await traceMagic.Execute(name, channel); + var response = await pkgMagic.Execute("mock.standard", channel); + Assert.AreEqual(ExecuteStatus.Ok, response.Status); + + response = await traceMagic.Execute(name, channel); Assert.AreEqual(ExecuteStatus.Ok, response.Status); var message = channel.iopubMessages.ElementAtOrDefault(0); @@ -303,7 +308,7 @@ public async Task TestPackages() { var engine = Init(); var snippets = engine.Snippets as Snippets; - + var pkgMagic = new PackageMagic(snippets.GlobalReferences); var channel = new MockChannel(); var response = await pkgMagic.Execute("", channel); From 16e2f2cf9f4496a398478a725527cdab8ad3b5ed Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Fri, 31 Jul 2020 11:18:51 -0400 Subject: [PATCH 15/15] Fix broken build tests --- src/Tests/IQsharpEngineTests.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Tests/IQsharpEngineTests.cs b/src/Tests/IQsharpEngineTests.cs index 9d0197b347..7252c893fb 100644 --- a/src/Tests/IQsharpEngineTests.cs +++ b/src/Tests/IQsharpEngineTests.cs @@ -90,14 +90,25 @@ private async Task AssertTrace(string name, ExecutionPath expectedPath) var engine = Init("Workspace.ExecutionPathTracer"); var snippets = engine.Snippets as Snippets; var configSource = new ConfigurationSource(skipLoading: true); + + var wsMagic = new WorkspaceMagic(snippets.Workspace); var pkgMagic = new PackageMagic(snippets.GlobalReferences); var traceMagic = new TraceMagic(engine.SymbolsResolver, configSource); + var channel = new MockChannel(); + // Add dependencies: var response = await pkgMagic.Execute("mock.standard", channel); + PrintResult(response, channel); + Assert.AreEqual(ExecuteStatus.Ok, response.Status); + + // Reload workspace: + response = await wsMagic.Execute("reload", channel); + PrintResult(response, channel); Assert.AreEqual(ExecuteStatus.Ok, response.Status); response = await traceMagic.Execute(name, channel); + PrintResult(response, channel); Assert.AreEqual(ExecuteStatus.Ok, response.Status); var message = channel.iopubMessages.ElementAtOrDefault(0);