diff --git a/images/iqsharp-base/Dockerfile b/images/iqsharp-base/Dockerfile index ca13b38bed..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.20072301-beta" && \ +RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20073008-beta" && \ dotnet tool install \ --global \ Microsoft.Quantum.IQSharp \ 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 diff --git a/src/AzureClient/AzureClient.csproj b/src/AzureClient/AzureClient.csproj index 2a99281c8f..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 4ce33a64ee..f7a29284d3 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -38,9 +38,9 @@ - - - + + + diff --git a/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs b/src/Core/ExecutionPathTracer/ExecutionPathTracer.cs index b3fef025cc..830155fe1a 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,16 +57,36 @@ public void OnOperationStartHandler(ICallable operation, IApplyData arguments) { this.currentDepth++; - // Parse operations at or above specified depth - if (this.currentDepth <= this.renderDepth) + // If `compositeTracer` is initialized, pass operations into it instead + if (this.compositeTracer != null) { - var metadata = operation.GetRuntimeMetadata(arguments); + this.compositeTracer.OnOperationStartHandler(operation, arguments); + return; + } + + // Only parse operations at or above (i.e. <= `renderDepth`) specified depth + if (this.currentDepth > this.renderDepth) 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); + var metadata = operation.GetRuntimeMetadata(arguments); + + // 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); } /// @@ -75,11 +97,30 @@ 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 `compositeTracer` is not null, handle the incoming operation recursively. + if (this.compositeTracer != null) + { + // 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; + } + + // Add latest parsed operation to list of operations, if not null if (this.currentOperation != null) { this.operations.Add(this.currentOperation); - // Reset current operation to null this.currentOperation = null; } } @@ -129,6 +170,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/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 79% rename from src/Mock.Chemistry/Mock.Chemistry.csproj rename to src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj index b8b345ce83..7900c48c47 100644 --- a/src/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/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..4971810eab --- /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; + } +} 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..2037f2c618 --- /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]); + } + } +} diff --git a/src/MockLibraries/Mock.Standard/Mock.Standard.csproj b/src/MockLibraries/Mock.Standard/Mock.Standard.csproj new file mode 100644 index 0000000000..7900c48c47 --- /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 3397bd1169..ffd70d71a1 100644 --- a/src/Tests/ExecutionPathTracerTests.cs +++ b/src/Tests/ExecutionPathTracerTests.cs @@ -3,10 +3,11 @@ 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.Core.ExecutionPathTracer; +using Microsoft.Quantum.Simulation.Simulators; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Tests.IQSharp { @@ -15,6 +16,7 @@ public class ExecutionPathTracerTests public Workspace InitWorkspace() { var ws = Startup.Create("Workspace.ExecutionPathTracer"); + ws.GlobalReferences.AddPackage("mock.standard").Wait(); ws.Reload(); Assert.IsFalse(ws.HasErrors); return ws; @@ -104,8 +106,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 +140,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 +251,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 +289,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 +438,18 @@ 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) }, + }, + new Operation() + { + Gate = "Reset", + Targets = new List() { new QubitRegister(2) }, }, }; var expected = new ExecutionPath(qubits, operations); @@ -569,12 +597,69 @@ 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); + Assert.AreEqual(expected.ToJson(), path.ToJson()); + } + } + + [TestClass] + public class CanonTests : ExecutionPathTracerTests + { + [TestMethod] + public void ApplyToEachTest() + { + 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 = "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); @@ -650,5 +735,35 @@ 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 = "MResetZ", + IsMeasurement = true, + Controls = new List() { new QubitRegister(0) }, + Targets = new List() { new ClassicalRegister(0, 0) }, + }, + new Operation() + { + Gate = "MResetZ", + IsMeasurement = true, + Controls = new List() { new QubitRegister(1) }, + Targets = new List() { new ClassicalRegister(1, 0) }, + }, + }; + var expected = new ExecutionPath(qubits, operations); + Assert.AreEqual(expected.ToJson(), path.ToJson()); + } } } diff --git a/src/Tests/IQsharpEngineTests.cs b/src/Tests/IQsharpEngineTests.cs index 2dff15d348..7252c893fb 100644 --- a/src/Tests/IQsharpEngineTests.cs +++ b/src/Tests/IQsharpEngineTests.cs @@ -88,11 +88,27 @@ 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 wsMagic = new WorkspaceMagic(snippets.Workspace); + var pkgMagic = new PackageMagic(snippets.GlobalReferences); var traceMagic = new TraceMagic(engine.SymbolsResolver, configSource); + var channel = new MockChannel(); - var response = await traceMagic.Execute(name, channel); + // 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); @@ -303,7 +319,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); 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 115a5896eb..059313ded9 100644 --- a/src/Tests/Tests.IQsharp.csproj +++ b/src/Tests/Tests.IQsharp.csproj @@ -28,7 +28,8 @@ - + + @@ -49,13 +50,16 @@ PreserveNewest - + PreserveNewest - + PreserveNewest - + + PreserveNewest + + PreserveNewest diff --git a/src/Tests/Workspace.ExecutionPathTracer/Canon.qs b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs new file mode 100644 index 0000000000..658b765ba4 --- /dev/null +++ b/src/Tests/Workspace.ExecutionPathTracer/Canon.qs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Tests.ExecutionPathTracer { + + 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 01efa8d5f8..1b78f87ff3 100644 --- a/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs +++ b/src/Tests/Workspace.ExecutionPathTracer/Measurement.qs @@ -2,9 +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); @@ -22,7 +24,13 @@ namespace Tests.ExecutionPathTracer { let res = MResetZ(q); } } - + + operation ForEachMeasureCirc() : Unit { + using (qs = Qubit[2]) { + let res = ForEach(MResetZ, qs); + } + } + } diff --git a/src/Tool/appsettings.json b/src/Tool/appsettings.json index f3fd49e8e7..7ec58902e5 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.20073008-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.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.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.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.20072301-beta", + "Microsoft.Quantum.Katas::0.12.20073008-beta", - "Microsoft.Quantum.Research::0.12.20072301-beta", + "Microsoft.Quantum.Research::0.12.20073008-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.20073008-beta", + "Microsoft.Quantum.Providers.Honeywell::0.12.20073008-beta", + "Microsoft.Quantum.Providers.QCI::0.12.20073008-beta" ] }