diff --git a/Simulation.sln b/Simulation.sln index 7886189c882..e85b15b0d8a 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -57,6 +57,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library2", "src\Simulation\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\Simulation\Simulators.Tests\TestProjects\UnitTests\UnitTests.csproj", "{46278108-D247-4EFC-AC34-23D4A676F62F}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulation", "Simulation", "{652D1D9B-234B-4DBF-9971-34F866AE58BA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.QSharp.Foundation", "src\Simulation\QsharpFoundation\Microsoft.Quantum.QSharp.Foundation.csproj", "{8D993092-F295-41A3-B1D0-DD5EAFA17B8F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -389,6 +393,22 @@ Global {46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Debug|x64.ActiveCfg = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Debug|x64.Build.0 = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Release|Any CPU.Build.0 = Release|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Release|x64.ActiveCfg = Release|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.Release|x64.Build.0 = Release|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -416,6 +436,8 @@ Global {7256B986-6705-42FC-9F57-485D72D9DE51} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} {A85277B3-4E07-4E15-8F0C-07CC855A3BCB} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} {46278108-D247-4EFC-AC34-23D4A676F62F} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} + {652D1D9B-234B-4DBF-9971-34F866AE58BA} = {99E234BC-997E-4E63-9F5C-3C3977543404} + {8D993092-F295-41A3-B1D0-DD5EAFA17B8F} = {652D1D9B-234B-4DBF-9971-34F866AE58BA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821} diff --git a/build/pack.ps1 b/build/pack.ps1 index 893db2b5728..412902b3617 100644 --- a/build/pack.ps1 +++ b/build/pack.ps1 @@ -63,6 +63,7 @@ Pack-Dotnet '../src/Azure/Azure.Quantum.Client/Microsoft.Azure.Quantum.Client.cs Pack-One '../src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj' '-IncludeReferencedProjects' Pack-Dotnet '../src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj' Pack-Dotnet '../src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj' +Pack-Dotnet '../src/Simulation/QSharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj' Pack-Dotnet '../src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj' Pack-One '../src/Simulation/Simulators/Microsoft.Quantum.Simulators.nuspec' Pack-One '../src/Quantum.Development.Kit/Microsoft.Quantum.Development.Kit.nuspec' diff --git a/src/Simulation/EntryPointDriver.Tests/Tests.fs b/src/Simulation/EntryPointDriver.Tests/Tests.fs index 57f283a2d73..32e649eedd7 100644 --- a/src/Simulation/EntryPointDriver.Tests/Tests.fs +++ b/src/Simulation/EntryPointDriver.Tests/Tests.fs @@ -96,6 +96,7 @@ let private compileCsharp (sources : string seq) = "System.Runtime.Extensions" "System.Runtime.Numerics" "Microsoft.Quantum.EntryPointDriver" + "Microsoft.Quantum.QSharp.Foundation" "Microsoft.Quantum.QSharp.Core" "Microsoft.Quantum.QsDataStructures" "Microsoft.Quantum.Runtime.Core" diff --git a/src/Simulation/QsharpCore/Intrinsic.qs b/src/Simulation/QsharpCore/Intrinsic.qs index 28f0353dd86..5ed04498990 100644 --- a/src/Simulation/QsharpCore/Intrinsic.qs +++ b/src/Simulation/QsharpCore/Intrinsic.qs @@ -5,108 +5,6 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Math; open Microsoft.Quantum.Convert; - /// # Summary - /// The random operation takes an array of doubles as input, and returns - /// a randomly-selected index into the array as an `Int`. - /// The probability of selecting a specific index is proportional to the value - /// of the array element at that index. - /// Array elements that are equal to zero are ignored and their indices are never - /// returned. If any array element is less than zero, - /// or if no array element is greater than zero, then the operation fails. - /// - /// # Input - /// ## probs - /// An array of floating-point numbers proportional to the probability of - /// selecting each index. - /// - /// # Output - /// An integer $i$ with probability $\Pr(i) = p_i / \sum_i p_i$, where $p_i$ - /// is the $i$th element of `probs`. - operation Random (probs : Double[]) : Int { - body intrinsic; - } - - - /// # Summary - /// Asserts that measuring the given qubits in the given Pauli basis will - /// always have the given result. - /// - /// # Input - /// ## bases - /// A measurement effect to assert the probability of, expressed as a - /// multi-qubit Pauli operator. - /// ## qubits - /// A register on which to make the assertion. - /// ## result - /// The expected result of `Measure(bases, qubits)`. - /// ## msg - /// A message to be reported if the assertion fails. - /// - /// # Remarks - /// Note that the Adjoint and Controlled versions of this operation will not - /// check the condition. - /// - /// # See Also - /// - AssertProb - operation Assert (bases : Pauli[], qubits : Qubit[], result : Result, msg : String) : Unit - is Adj + Ctl { - body intrinsic; - } - - - /// # Summary - /// Asserts that measuring the given qubits in the given Pauli basis will have the given result - /// with the given probability, within some tolerance. - /// - /// # Input - /// ## bases - /// A measurement effect to assert the probability of, expressed as a - /// multi-qubit Pauli operator. - /// ## qubits - /// A register on which to make the assertion. - /// ## result - /// An expected result of `Measure(bases, qubits)`. - /// ## prob - /// The probability with which the given result is expected. - /// ## msg - /// A message to be reported if the assertion fails. - /// - /// # Example - /// ```qsharp - /// using (register = Qubit()) { - /// H(register); - /// AssertProb([PauliZ], [register], One, 0.5, - /// "Measuring in conjugate basis did not give 50/50 results.", 1e-5); - /// } - /// ``` - /// - /// # Remarks - /// Note that the Adjoint and Controlled versions of this operation will not - /// check the condition. - /// - /// # See Also - /// - Assert - operation AssertProb (bases : Pauli[], qubits : Qubit[], result : Result, prob : Double, msg : String, tol : Double) : Unit - is Adj + Ctl { - body intrinsic; - } - - - /// # Summary - /// Logs a message. - /// - /// # Input - /// ## msg - /// The message to be reported. - /// - /// # Remarks - /// The specific behavior of this function is simulator-dependent, - /// but in most cases the given message will be written to the console. - function Message (msg : String) : Unit { - body intrinsic; - } - - //------------------------------------------------- // Clifford and related operations //------------------------------------------------- diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index 6fa6d8bc6a1..621f0ebc169 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -27,6 +27,7 @@ + diff --git a/src/Simulation/QsharpFoundation/Assert.qs b/src/Simulation/QsharpFoundation/Assert.qs new file mode 100644 index 00000000000..6f36ade4d6b --- /dev/null +++ b/src/Simulation/QsharpFoundation/Assert.qs @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + /// # Summary + /// Asserts that measuring the given qubits in the given Pauli basis will + /// always have the given result. + /// + /// # Input + /// ## bases + /// A measurement effect to assert the probability of, expressed as a + /// multi-qubit Pauli operator. + /// ## qubits + /// A register on which to make the assertion. + /// ## result + /// The expected result of `Measure(bases, qubits)`. + /// ## msg + /// A message to be reported if the assertion fails. + /// + /// # Remarks + /// Note that the Adjoint and Controlled versions of this operation will not + /// check the condition. + /// + /// # See Also + /// - AssertProb + operation Assert (bases : Pauli[], qubits : Qubit[], result : Result, msg : String) : Unit + is Adj + Ctl { + body intrinsic; + } + + + /// # Summary + /// Asserts that measuring the given qubits in the given Pauli basis will have the given result + /// with the given probability, within some tolerance. + /// + /// # Input + /// ## bases + /// A measurement effect to assert the probability of, expressed as a + /// multi-qubit Pauli operator. + /// ## qubits + /// A register on which to make the assertion. + /// ## result + /// An expected result of `Measure(bases, qubits)`. + /// ## prob + /// The probability with which the given result is expected. + /// ## msg + /// A message to be reported if the assertion fails. + /// + /// # Example + /// ```qsharp + /// using (register = Qubit()) { + /// H(register); + /// AssertProb([PauliZ], [register], One, 0.5, + /// "Measuring in conjugate basis did not give 50/50 results.", 1e-5); + /// } + /// ``` + /// + /// # Remarks + /// Note that the Adjoint and Controlled versions of this operation will not + /// check the condition. + /// + /// # See Also + /// - Assert + operation AssertProb (bases : Pauli[], qubits : Qubit[], result : Result, prob : Double, msg : String, tol : Double) : Unit + is Adj + Ctl { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/QsharpCore/Bitwise/Bitwise.cs b/src/Simulation/QsharpFoundation/Bitwise/Bitwise.cs similarity index 100% rename from src/Simulation/QsharpCore/Bitwise/Bitwise.cs rename to src/Simulation/QsharpFoundation/Bitwise/Bitwise.cs diff --git a/src/Simulation/QsharpCore/Bitwise/Bitwise.qs b/src/Simulation/QsharpFoundation/Bitwise/Bitwise.qs similarity index 100% rename from src/Simulation/QsharpCore/Bitwise/Bitwise.qs rename to src/Simulation/QsharpFoundation/Bitwise/Bitwise.qs diff --git a/src/Simulation/QsharpCore/Bitwise/Deprecated.qs b/src/Simulation/QsharpFoundation/Bitwise/Deprecated.qs similarity index 100% rename from src/Simulation/QsharpCore/Bitwise/Deprecated.qs rename to src/Simulation/QsharpFoundation/Bitwise/Deprecated.qs diff --git a/src/Simulation/QsharpCore/ClassicalControl.qs b/src/Simulation/QsharpFoundation/ClassicalControl.qs similarity index 99% rename from src/Simulation/QsharpCore/ClassicalControl.qs rename to src/Simulation/QsharpFoundation/ClassicalControl.qs index f26320286bc..05ea7392569 100644 --- a/src/Simulation/QsharpCore/ClassicalControl.qs +++ b/src/Simulation/QsharpFoundation/ClassicalControl.qs @@ -3,8 +3,6 @@ namespace Microsoft.Quantum.Simulation.QuantumProcessor.Extensions //ToDo: update namespace to a more appropriate name { - open Microsoft.Quantum.Intrinsic; - operation NoOp() : Unit is Ctl + Adj {} // Private helper operations. diff --git a/src/Simulation/QsharpCore/Convert/Convert.cs b/src/Simulation/QsharpFoundation/Convert/Convert.cs similarity index 100% rename from src/Simulation/QsharpCore/Convert/Convert.cs rename to src/Simulation/QsharpFoundation/Convert/Convert.cs diff --git a/src/Simulation/QsharpCore/Convert/Convert.qs b/src/Simulation/QsharpFoundation/Convert/Convert.qs similarity index 100% rename from src/Simulation/QsharpCore/Convert/Convert.qs rename to src/Simulation/QsharpFoundation/Convert/Convert.qs diff --git a/src/Simulation/QsharpCore/Convert/Deprecated.qs b/src/Simulation/QsharpFoundation/Convert/Deprecated.qs similarity index 100% rename from src/Simulation/QsharpCore/Convert/Deprecated.qs rename to src/Simulation/QsharpFoundation/Convert/Deprecated.qs diff --git a/src/Simulation/QsharpCore/Core.cs b/src/Simulation/QsharpFoundation/Core.cs similarity index 100% rename from src/Simulation/QsharpCore/Core.cs rename to src/Simulation/QsharpFoundation/Core.cs diff --git a/src/Simulation/QsharpCore/Core.qs b/src/Simulation/QsharpFoundation/Core.qs similarity index 100% rename from src/Simulation/QsharpCore/Core.qs rename to src/Simulation/QsharpFoundation/Core.qs diff --git a/src/Simulation/QsharpCore/Environment.qs b/src/Simulation/QsharpFoundation/Environment.qs similarity index 100% rename from src/Simulation/QsharpCore/Environment.qs rename to src/Simulation/QsharpFoundation/Environment.qs diff --git a/src/Simulation/QsharpCore/Math/Constants.qs b/src/Simulation/QsharpFoundation/Math/Constants.qs similarity index 100% rename from src/Simulation/QsharpCore/Math/Constants.qs rename to src/Simulation/QsharpFoundation/Math/Constants.qs diff --git a/src/Simulation/QsharpCore/Math/Deprecated.qs b/src/Simulation/QsharpFoundation/Math/Deprecated.qs similarity index 100% rename from src/Simulation/QsharpCore/Math/Deprecated.qs rename to src/Simulation/QsharpFoundation/Math/Deprecated.qs diff --git a/src/Simulation/QsharpCore/Math/Math.cs b/src/Simulation/QsharpFoundation/Math/Math.cs similarity index 100% rename from src/Simulation/QsharpCore/Math/Math.cs rename to src/Simulation/QsharpFoundation/Math/Math.cs diff --git a/src/Simulation/QsharpCore/Math/Math.qs b/src/Simulation/QsharpFoundation/Math/Math.qs similarity index 100% rename from src/Simulation/QsharpCore/Math/Math.qs rename to src/Simulation/QsharpFoundation/Math/Math.qs diff --git a/src/Simulation/QsharpCore/Math/Trig.qs b/src/Simulation/QsharpFoundation/Math/Trig.qs similarity index 100% rename from src/Simulation/QsharpCore/Math/Trig.qs rename to src/Simulation/QsharpFoundation/Math/Trig.qs diff --git a/src/Simulation/QsharpCore/Math/Types.qs b/src/Simulation/QsharpFoundation/Math/Types.qs similarity index 100% rename from src/Simulation/QsharpCore/Math/Types.qs rename to src/Simulation/QsharpFoundation/Math/Types.qs diff --git a/src/Simulation/QsharpFoundation/Message.qs b/src/Simulation/QsharpFoundation/Message.qs new file mode 100644 index 00000000000..5ae8f8c2cfb --- /dev/null +++ b/src/Simulation/QsharpFoundation/Message.qs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + /// # Summary + /// Logs a message. + /// + /// # Input + /// ## msg + /// The message to be reported. + /// + /// # Remarks + /// The specific behavior of this function is simulator-dependent, + /// but in most cases the given message will be written to the console. + function Message(msg : String) : Unit { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/QsharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj b/src/Simulation/QsharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj new file mode 100644 index 00000000000..ccb777f1fd8 --- /dev/null +++ b/src/Simulation/QsharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj @@ -0,0 +1,40 @@ + + + + + + + netstandard2.1 + true + false + false + + + + Microsoft + Foundation implementation for the Q# programming language. + See: https://docs.microsoft.com/en-us/quantum/relnotes/ + MIT + https://github.com/microsoft/qsharp-runtime + https://secure.gravatar.com/avatar/bd1f02955b2853ba0a3b1cdc2434e8ec.png + Quantum Q# Qsharp + true + + + + + + + + + + + + + + + + + + + diff --git a/src/Simulation/QsharpFoundation/Random.qs b/src/Simulation/QsharpFoundation/Random.qs new file mode 100644 index 00000000000..b43b0c7fb5a --- /dev/null +++ b/src/Simulation/QsharpFoundation/Random.qs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + /// # Summary + /// The random operation takes an array of doubles as input, and returns + /// a randomly-selected index into the array as an `Int`. + /// The probability of selecting a specific index is proportional to the value + /// of the array element at that index. + /// Array elements that are equal to zero are ignored and their indices are never + /// returned. If any array element is less than zero, + /// or if no array element is greater than zero, then the operation fails. + /// + /// # Input + /// ## probs + /// An array of floating-point numbers proportional to the probability of + /// selecting each index. + /// + /// # Output + /// An integer $i$ with probability $\Pr(i) = p_i / \sum_i p_i$, where $p_i$ + /// is the $i$th element of `probs`. + operation Random(probs : Double[]) : Int { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/QsharpCore/Statements/Allocate.cs b/src/Simulation/QsharpFoundation/Statements/Allocate.cs similarity index 100% rename from src/Simulation/QsharpCore/Statements/Allocate.cs rename to src/Simulation/QsharpFoundation/Statements/Allocate.cs diff --git a/src/Simulation/QsharpCore/Statements/Borrow.cs b/src/Simulation/QsharpFoundation/Statements/Borrow.cs similarity index 100% rename from src/Simulation/QsharpCore/Statements/Borrow.cs rename to src/Simulation/QsharpFoundation/Statements/Borrow.cs diff --git a/src/Simulation/QsharpCore/Statements/Release.cs b/src/Simulation/QsharpFoundation/Statements/Release.cs similarity index 100% rename from src/Simulation/QsharpCore/Statements/Release.cs rename to src/Simulation/QsharpFoundation/Statements/Release.cs diff --git a/src/Simulation/QsharpCore/Statements/Return.cs b/src/Simulation/QsharpFoundation/Statements/Return.cs similarity index 100% rename from src/Simulation/QsharpCore/Statements/Return.cs rename to src/Simulation/QsharpFoundation/Statements/Return.cs