Add support for target packages (merge from feature/decomp) (#476)
This PR merges the payload from feature/decomp to enable target packages for Q# runtime. This resolves #249 (see that issue for details on the individual elements and links to previous PRs and discussions). Here's the high level summary of the contents: - Introduces an opt-in alternate behavior for C# generation where body intrinsic callables are generated as concrete classes that expect their implementation to be provided via an object implementing a matching interface. - Adds interfaces for each intrinsic callable in the three target packages. - Adds Q# implementation for decompositions and intrinsics for three target packages (Qsharp.Core, Type1.Core, Type2.Core). - Updates the wrapper around the full state simulator to provide implementations for all three target packages. - Splits the existing Qsharp.Core into Qsharp.Core and Qsharp.Foundation, where the latter contains common implementations shared across all target packages. - Refactors dependencies across the package hierarchy to allow for alternate target packages to be chosen at compile time. - Updates test infrastructure to include testing of the simulator with Type1 and Type2 packages. - Adds a readme with guidance on the folder structure and package relationships for target packages that helps guide additions of new packages.
This commit is contained in:
Родитель
e07ab7169f
Коммит
974a385cc5
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.Quantum.Sdk/0.13.20102604">
|
||||
<Project Sdk="Microsoft.Quantum.Sdk/0.14.2012122063-beta">
|
||||
<!-- Add project references to Simulator and other required packages: -->
|
||||
<Import Project="..\..\src\Simulation\Common\Simulators.Dev.props" />
|
||||
|
||||
|
@ -8,4 +8,9 @@
|
|||
<IncludeQSharpCorePackages>false</IncludeQSharpCorePackages> <!-- otherwise the standard library is included by the Sdk -->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Simulation\Simulators\Microsoft.Quantum.Simulators.csproj" />
|
||||
<ProjectReference Include="..\..\src\Simulation\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.Quantum.Sdk/0.13.20102604">
|
||||
<Project Sdk="Microsoft.Quantum.Sdk/0.14.2012122063-beta">
|
||||
|
||||
<ItemGroup>
|
||||
<QSharpCompile Include="..\..\privateBuild\quantum.qs" />
|
||||
|
|
|
@ -2715,7 +2715,7 @@ SOFTWARE.
|
|||
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Microsoft.Quantum.Compiler 0.12.20082209-beta - MIT
|
||||
Microsoft.Quantum.Compiler 0.13.20102604 - MIT
|
||||
|
||||
|
||||
(c) 2008 VeriSign, Inc.
|
||||
|
|
167
Simulation.sln
167
Simulation.sln
|
@ -63,9 +63,31 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IonQExe", "src\Simulation\S
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QCIExe", "src\Simulation\Simulators.Tests\TestProjects\QCIExe\QCIExe.csproj", "{C015FF41-9A51-4AF0-AEFC-2547D596B10A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetedExe", "src\Simulation\Simulators.Tests\TestProjects\TargetedExe\TargetedExe.csproj", "{D292BF18-3956-4827-820E-254C3F81EF09}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TargetedExe", "src\Simulation\Simulators.Tests\TestProjects\TargetedExe\TargetedExe.csproj", "{D292BF18-3956-4827-820E-254C3F81EF09}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntrinsicTests", "src\Simulation\Simulators.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BC562DAE-FE2B-4A8C-880C-C546F83F99E4}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulation", "Simulation", "{9008B252-2DF7-404B-B626-D4497BB70A05}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.QSharp.Foundation", "src\Simulation\QSharpFoundation\Microsoft.Quantum.QSharp.Foundation.csproj", "{DB45AD73-4D91-43F3-85CC-C63614A96FB0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Type2.Core", "src\Simulation\Type2Core\Microsoft.Quantum.Type2.Core.csproj", "{AF6CD304-8E03-433D-AAA2-6E0094B53071}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Microsoft.Quantum.Simulators.Type2", "src\Simulation\Simulators.Type2.Tests\Tests.Microsoft.Quantum.Simulators.Type2.csproj", "{ED3D7040-4B3F-4217-A75E-9DF63DD84707}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulators.Tests", "Simulators.Tests", "{CF48986A-B487-407F-98A7-97AED29C6A43}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntrinsicTests", "src\Simulation\Simulators.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Microsoft.Quantum.Simulators.Type1", "src\Simulation\Simulators.Type1.Tests\Tests.Microsoft.Quantum.Simulators.Type1.csproj", "{EB6E3DBD-C884-4241-9BC4-8281191D1F53}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Type1.Core", "src\Simulation\Type1Core\Microsoft.Quantum.Type1.Core.csproj", "{E1A463D7-2E23-4134-BE04-1EFF7A546813}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TargetDefinitions", "TargetDefinitions", "{93409CC3-8DF9-45FA-AE21-16A19FDEF650}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Targets.Interfaces", "src\Simulation\TargetDefinitions\Interfaces\Microsoft.Quantum.Targets.Interfaces.csproj", "{789C86D9-CE77-40DA-BDDD-979436952512}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -479,22 +501,118 @@ Global
|
|||
{D292BF18-3956-4827-820E-254C3F81EF09}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{D292BF18-3956-4827-820E-254C3F81EF09}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{D292BF18-3956-4827-820E-254C3F81EF09}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.Release|x64.Build.0 = Release|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.Release|x64.Build.0 = Release|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|x64.Build.0 = Release|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|x64.Build.0 = Release|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|x64.Build.0 = Release|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.Release|x64.Build.0 = Release|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -526,9 +644,20 @@ Global
|
|||
{55833C6C-6E91-4413-9F77-96B3A09666B8} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
|
||||
{C015FF41-9A51-4AF0-AEFC-2547D596B10A} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
|
||||
{D292BF18-3956-4827-820E-254C3F81EF09} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
|
||||
{D5D41201-101F-4C0D-B6A0-201D8FC3AB91} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
|
||||
{9008B252-2DF7-404B-B626-D4497BB70A05} = {BC562DAE-FE2B-4A8C-880C-C546F83F99E4}
|
||||
{DB45AD73-4D91-43F3-85CC-C63614A96FB0} = {9008B252-2DF7-404B-B626-D4497BB70A05}
|
||||
{AF6CD304-8E03-433D-AAA2-6E0094B53071} = {9008B252-2DF7-404B-B626-D4497BB70A05}
|
||||
{ED3D7040-4B3F-4217-A75E-9DF63DD84707} = {9008B252-2DF7-404B-B626-D4497BB70A05}
|
||||
{CF48986A-B487-407F-98A7-97AED29C6A43} = {9008B252-2DF7-404B-B626-D4497BB70A05}
|
||||
{F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3} = {CF48986A-B487-407F-98A7-97AED29C6A43}
|
||||
{4EF958CA-B4A6-4E5F-924A-100B5615BEC3} = {F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3}
|
||||
{EB6E3DBD-C884-4241-9BC4-8281191D1F53} = {9008B252-2DF7-404B-B626-D4497BB70A05}
|
||||
{E1A463D7-2E23-4134-BE04-1EFF7A546813} = {9008B252-2DF7-404B-B626-D4497BB70A05}
|
||||
{93409CC3-8DF9-45FA-AE21-16A19FDEF650} = {9008B252-2DF7-404B-B626-D4497BB70A05}
|
||||
{789C86D9-CE77-40DA-BDDD-979436952512} = {93409CC3-8DF9-45FA-AE21-16A19FDEF650}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ $artifacts = @{
|
|||
"Microsoft.Quantum.Development.Kit",
|
||||
"Microsoft.Quantum.EntryPointDriver",
|
||||
"Microsoft.Quantum.QSharp.Core",
|
||||
"Microsoft.Quantum.Type1.Core",
|
||||
"Microsoft.Quantum.Type2.Core",
|
||||
"Microsoft.Quantum.Runtime.Core",
|
||||
"Microsoft.Quantum.Simulators",
|
||||
"Microsoft.Quantum.Xunit"
|
||||
|
@ -37,6 +39,9 @@ $artifacts = @{
|
|||
".\src\Simulation\Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Runtime.Core.dll",
|
||||
".\src\Simulation\EntryPointDriver\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.EntryPointDriver.dll",
|
||||
".\src\Simulation\QSharpCore\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QSharp.Core.dll",
|
||||
".\src\Simulation\Type1Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Type1.Core.dll",
|
||||
".\src\Simulation\Type2Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Type2.Core.dll",
|
||||
".\src\Simulation\QSharpFoundation\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QSharp.Foundation.dll",
|
||||
".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.Common.dll",
|
||||
".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll",
|
||||
".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.dll",
|
||||
|
|
|
@ -65,7 +65,11 @@ 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/TargetDefinitions/Interfaces/Microsoft.Quantum.Targets.Interfaces.csproj'
|
||||
Pack-Dotnet '../src/Simulation/QSharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj'
|
||||
Pack-Dotnet '../src/Simulation/QSharpCore/Microsoft.Quantum.QSharp.Core.csproj'
|
||||
Pack-Dotnet '../src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj'
|
||||
Pack-Dotnet '../src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj'
|
||||
Pack-One '../src/Simulation/Simulators/Microsoft.Quantum.Simulators.nuspec'
|
||||
Pack-One '../src/Quantum.Development.Kit/Microsoft.Quantum.Development.Kit.nuspec'
|
||||
Pack-One '../src/Xunit/Microsoft.Quantum.Xunit.csproj'
|
||||
|
|
|
@ -1710,7 +1710,7 @@ namespace N1
|
|||
|
||||
let testOneSpecialization pick (_,op) expected =
|
||||
let context = createTestContext op
|
||||
let actual = op |> pick |> buildSpecialization context |> Option.map (fst >> formatSyntaxTree)
|
||||
let actual = op |> pick |> buildSpecialization context op |> Option.map (fst >> formatSyntaxTree)
|
||||
Assert.Equal(expected |> Option.map clearFormatting, actual |> Option.map clearFormatting)
|
||||
|
||||
[<Fact>]
|
||||
|
@ -2315,7 +2315,7 @@ namespace N1
|
|||
[<Fact>]
|
||||
let ``is abstract`` () =
|
||||
let testOne (_,op) expected =
|
||||
let actual = op |> isAbstract
|
||||
let actual = op |> isIntrinsic
|
||||
Assert.Equal(expected, actual)
|
||||
|
||||
true |> testOne emptyOperation
|
||||
|
|
|
@ -52,10 +52,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Microsoft.Quantum.Runtime.Core.csproj" />
|
||||
<ProjectReference Include="..\CSharpGeneration\Microsoft.Quantum.CSharpGeneration.fsproj" />
|
||||
<ProjectReference Include="..\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
|
||||
<ProjectReference Include="..\Simulators\Microsoft.Quantum.Simulators.csproj" />
|
||||
<ProjectReference Include="..\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="FSharp.Core" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.13.2011.802-alpha" />
|
||||
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.14.2012122063-beta" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -45,6 +45,15 @@ module SimulationCode =
|
|||
"Microsoft.Quantum.Simulation.Core"
|
||||
]
|
||||
|
||||
let autoNamespacesWithInterfaces =
|
||||
[
|
||||
"System"
|
||||
"Microsoft.Quantum.Core"
|
||||
"Microsoft.Quantum.Intrinsic"
|
||||
"Microsoft.Quantum.Intrinsic.Interfaces"
|
||||
"Microsoft.Quantum.Simulation.Core"
|
||||
]
|
||||
|
||||
let funcsAsProps = [
|
||||
("Length", { Namespace = "Microsoft.Quantum.Core"; Name = "Length" } )
|
||||
("Start", { Namespace = "Microsoft.Quantum.Core"; Name = "RangeStart" } )
|
||||
|
@ -69,16 +78,24 @@ module SimulationCode =
|
|||
let prependNamespaceString (name : QsQualifiedName) =
|
||||
name.Namespace.Replace (".", "__") + "__" + name.Name
|
||||
|
||||
let isConcreteIntrinsic (context:CodegenContext) =
|
||||
match context.assemblyConstants.TryGetValue AssemblyConstants.GenerateConcreteIntrinsic with
|
||||
| true, "false" -> false
|
||||
| true, _ -> true
|
||||
| false, _ -> false
|
||||
|
||||
let needsFullPath context (op:QsQualifiedName) =
|
||||
let hasMultipleDefinitions() = if context.byName.ContainsKey op.Name then context.byName.[op.Name].Length > 1 else false
|
||||
let sameNamespace = match context.current with | None -> false | Some n -> n.Namespace = op.Namespace
|
||||
|
||||
let namespaces = if isConcreteIntrinsic context then autoNamespacesWithInterfaces else autoNamespaces
|
||||
|
||||
if sameNamespace then
|
||||
false
|
||||
elif hasMultipleDefinitions() then
|
||||
true
|
||||
else
|
||||
not (autoNamespaces |> List.contains op.Namespace)
|
||||
not (namespaces |> List.contains op.Namespace)
|
||||
|
||||
let getOpName context n =
|
||||
if isCurrentOp context n then Directives.Self
|
||||
|
@ -913,6 +930,18 @@ module SimulationCode =
|
|||
``{`` [] ``}``
|
||||
:> MemberDeclarationSyntax
|
||||
|
||||
/// Returns the constructor for the given intrinsic operation.
|
||||
let buildIntrinsicConstructor context name : MemberDeclarationSyntax =
|
||||
``constructor`` name ``(`` [ ("m", ``type`` "IOperationFactory") ] ``)``
|
||||
``:`` [ "m" ]
|
||||
[ ``public`` ]
|
||||
``{``
|
||||
[
|
||||
(``ident`` "this") <|.|> (``ident`` "Gate") <-- (``ident`` "m") |~> ("IGate_" + name) |> statement
|
||||
]
|
||||
``}``
|
||||
:> MemberDeclarationSyntax
|
||||
|
||||
/// For each Operation used in the given OperationDeclartion, returns
|
||||
/// a Property that returns an instance of the operation by calling the
|
||||
/// IOperationFactory
|
||||
|
@ -957,27 +986,9 @@ module SimulationCode =
|
|||
(``=>`` newInstance)
|
||||
:> MemberDeclarationSyntax
|
||||
|
||||
let buildSpecializationBody context (sp:QsSpecialization) =
|
||||
match sp.Implementation with
|
||||
| Provided (args, _) ->
|
||||
let returnType = sp.Signature.ReturnType
|
||||
let statements =
|
||||
let builder = new SyntaxBuilder(context)
|
||||
builder.Namespaces.OnSpecializationDeclaration sp |> ignore
|
||||
builder.BuiltStatements
|
||||
|
||||
let buildSpecializationBody (context:CodegenContext) (op:QsCallable) (sp:QsSpecialization) =
|
||||
let getInputVarWithInit args =
|
||||
let inData = ``ident`` "__in__"
|
||||
let ret =
|
||||
match returnType.Resolution with
|
||||
| QsTypeKind.UnitType ->
|
||||
[
|
||||
``#line hidden`` <|
|
||||
``return`` ( Some ((``ident`` "QVoid") <|.|> (``ident`` "Instance")) )
|
||||
]
|
||||
| _ ->
|
||||
[]
|
||||
let (argName, argsInit) =
|
||||
//TODO: diagnostics.
|
||||
let name = function | ValidName n -> n | InvalidName -> ""
|
||||
let rec buildVariableName = function
|
||||
| QsTupleItem one -> one.VariableName |> name
|
||||
|
@ -991,7 +1002,17 @@ module SimulationCode =
|
|||
("__in__", [ ``var`` (buildVariableName many.[0]) (``:=`` <| inData) ])
|
||||
else
|
||||
("__in__", [ ``var`` (buildVariableName args) (``:=`` <| inData) ])
|
||||
|
||||
match sp.Implementation with
|
||||
| Provided (args, _) ->
|
||||
let argName, argsInit = getInputVarWithInit args
|
||||
let statements =
|
||||
let builder = new SyntaxBuilder(context)
|
||||
builder.Namespaces.OnSpecializationDeclaration sp |> ignore
|
||||
builder.BuiltStatements
|
||||
let ret =
|
||||
match sp.Signature.ReturnType.Resolution with
|
||||
| QsTypeKind.UnitType -> [ ``return`` ( Some ((``ident`` "QVoid") <|.|> (``ident`` "Instance")) ) |> ``#line hidden`` ]
|
||||
| _ -> []
|
||||
Some (``() => {}`` [ argName ] (argsInit @ statements @ ret) :> ExpressionSyntax)
|
||||
| Generated SelfInverse ->
|
||||
let adjointedBodyName =
|
||||
|
@ -1001,10 +1022,50 @@ module SimulationCode =
|
|||
//TODO: diagnostics.
|
||||
| _ -> "__Body__"
|
||||
Some (``ident`` adjointedBodyName :> ExpressionSyntax)
|
||||
| Intrinsic when isConcreteIntrinsic context ->
|
||||
// Add in the control qubits parameter when dealing with a controlled spec
|
||||
let args =
|
||||
match sp.Kind with
|
||||
| QsControlled | QsControlledAdjoint ->
|
||||
let ctlVar =
|
||||
let name = ValidName("__controlQubits__")
|
||||
let varType = Qubit |> ResolvedType.New |> ArrayType |> ResolvedType.New
|
||||
let info = InferredExpressionInformation.New(false, false)
|
||||
let pos = QsNullable<Position>.Null
|
||||
let range = Range.Zero
|
||||
{VariableName = name; Type = varType; InferredInformation = info; Position = pos; Range = range}
|
||||
match op.ArgumentTuple with
|
||||
| QsTuple many when many.Length = 1 ->
|
||||
QsTuple(ImmutableArray.Create(QsTupleItem(ctlVar), many.[0]))
|
||||
| _ -> QsTuple(ImmutableArray.Create(QsTupleItem(ctlVar), op.ArgumentTuple))
|
||||
| _ -> op.ArgumentTuple
|
||||
let argName, argsInit = getInputVarWithInit args
|
||||
let specCall =
|
||||
(userDefinedName None op.FullName.Name) + "__" +
|
||||
match sp.Kind with
|
||||
| QsBody -> ""
|
||||
| QsAdjoint -> "Adjoint"
|
||||
| QsControlled -> "Controlled"
|
||||
| QsControlledAdjoint -> "ControlledAdjoint"
|
||||
+ "Body"
|
||||
let name = function | ValidName n -> ``ident`` n | InvalidName -> ``ident`` ""
|
||||
let rec argsToVars = function
|
||||
| QsTupleItem one -> [one.VariableName |> name]
|
||||
| QsTuple many -> many |> Seq.map argsToVars |> List.concat
|
||||
let callExp = (``ident`` "Gate") <.> (``ident`` specCall, argsToVars args)
|
||||
let statements =
|
||||
match sp.Signature.ReturnType.Resolution with
|
||||
| QsTypeKind.UnitType ->
|
||||
[
|
||||
callExp |> statement
|
||||
``return`` ( Some ((``ident`` "QVoid") <|.|> (``ident`` "Instance")) ) |> ``#line hidden``
|
||||
]
|
||||
| _ -> [ ``return`` ( Some callExp ) ]
|
||||
Some (``() => {}`` [ argName ] (argsInit @ statements) :> ExpressionSyntax)
|
||||
| _ ->
|
||||
None
|
||||
|
||||
let buildSpecialization context (sp:QsSpecialization) : (PropertyDeclarationSyntax * _) option =
|
||||
let buildSpecialization context (op:QsCallable) (sp:QsSpecialization) : (PropertyDeclarationSyntax * _) option =
|
||||
let inType = roslynTypeName context sp.Signature.ArgumentType
|
||||
let outType = roslynTypeName context sp.Signature.ReturnType
|
||||
let propertyType = "Func<" + inType + ", " + outType + ">"
|
||||
|
@ -1014,7 +1075,7 @@ module SimulationCode =
|
|||
| QsAdjoint -> "Adjoint"
|
||||
| QsControlled -> "Controlled"
|
||||
| QsControlledAdjoint -> "ControlledAdjoint"
|
||||
let body = buildSpecializationBody context sp
|
||||
let body = buildSpecializationBody context op sp
|
||||
let attributes =
|
||||
match sp.Location with
|
||||
| Null -> []
|
||||
|
@ -1217,6 +1278,10 @@ module SimulationCode =
|
|||
``get`` (``=>`` (``literal`` name) )
|
||||
:> MemberDeclarationSyntax
|
||||
|
||||
let buildGate name =
|
||||
``propg`` ("IGate_" + name) "Gate" [ ``private``; ``protected`` ]
|
||||
:> MemberDeclarationSyntax
|
||||
|
||||
let buildFullName (name : QsQualifiedName) =
|
||||
let fqn =
|
||||
let ns = name.Namespace
|
||||
|
@ -1336,7 +1401,7 @@ module SimulationCode =
|
|||
let nonGeneric = if typeParameters.IsEmpty then name else sprintf "%s<%s>" name (String.Join(",", typeParameters))
|
||||
(name, nonGeneric)
|
||||
|
||||
let isAbstract op =
|
||||
let isIntrinsic op =
|
||||
let isBody (sp:QsSpecialization) = match sp.Kind with | QsBody when sp.Implementation <> Intrinsic -> true | _ -> false
|
||||
not (op.Specializations |> Seq.exists isBody)
|
||||
|
||||
|
@ -1385,16 +1450,20 @@ module SimulationCode =
|
|||
let opNames = operationDependencies op
|
||||
let inType = op.Signature.ArgumentType |> roslynTypeName context
|
||||
let outType = op.Signature.ReturnType |> roslynTypeName context
|
||||
let opIsIntrinsic = isIntrinsic op
|
||||
let isConcreteIntrinsic = opIsIntrinsic && isConcreteIntrinsic context
|
||||
|
||||
let constructors = [ (buildConstructor context name) ]
|
||||
let constructors = [ ((if isConcreteIntrinsic then buildIntrinsicConstructor else buildConstructor) context name) ]
|
||||
let properties =
|
||||
let opProperties = buildOpsProperties context opNames
|
||||
buildName name ::
|
||||
buildFullName context.current.Value ::
|
||||
[
|
||||
yield buildName name
|
||||
yield buildFullName context.current.Value
|
||||
if globalContext.entryPoints |> Seq.contains op.FullName then
|
||||
buildOperationInfoProperty globalContext inType outType nonGenericName ::
|
||||
opProperties
|
||||
else opProperties
|
||||
yield buildOperationInfoProperty globalContext inType outType nonGenericName
|
||||
if isConcreteIntrinsic then yield buildGate name
|
||||
yield! opProperties
|
||||
]
|
||||
|
||||
let baseOp =
|
||||
if isFunction op then
|
||||
|
@ -1411,7 +1480,7 @@ module SimulationCode =
|
|||
let typeParameters = typeParametersNames op.Signature
|
||||
let baseClass = genericBase baseOp ``<<`` typeArgsInterface ``>>``
|
||||
let bodies, attr =
|
||||
op.Specializations |> Seq.map (buildSpecialization context) |> Seq.choose id |> Seq.toList
|
||||
op.Specializations |> Seq.map (buildSpecialization context op) |> Seq.choose id |> Seq.toList
|
||||
|> List.map (fun (x, y) -> (x :> MemberDeclarationSyntax, y)) |> List.unzip
|
||||
let inData = (buildDataWrapper context "In" op.Signature.ArgumentType)
|
||||
let outData = (buildDataWrapper context "Out" op.Signature.ReturnType)
|
||||
|
@ -1441,7 +1510,7 @@ module SimulationCode =
|
|||
|
||||
let modifiers =
|
||||
let access = classAccessModifier op.Modifiers.Access
|
||||
if isAbstract op then
|
||||
if opIsIntrinsic && not isConcreteIntrinsic then
|
||||
[ access; ``abstract``; ``partial`` ]
|
||||
else
|
||||
[ access; ``partial`` ]
|
||||
|
@ -1625,7 +1694,8 @@ module SimulationCode =
|
|||
|
||||
// Builds the C# syntaxTree for the Q# elements defined in the given file.
|
||||
let buildSyntaxTree localElements (context : CodegenContext) =
|
||||
let usings = autoNamespaces |> List.map (fun ns -> ``using`` ns)
|
||||
let namespaces = if isConcreteIntrinsic context then autoNamespacesWithInterfaces else autoNamespaces
|
||||
let usings = namespaces |> List.map (fun ns -> ``using`` ns)
|
||||
let attributes = localElements |> List.map (snd >> buildDeclarationAttributes) |> List.concat
|
||||
let namespaces = localElements |> List.map (buildNamespace context)
|
||||
|
||||
|
|
|
@ -5,6 +5,12 @@
|
|||
<Authors>Microsoft</Authors>
|
||||
<Product>Microsoft Quantum Development Kit Preview</Product>
|
||||
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
|
||||
<PackageReleaseNotes>See: https://docs.microsoft.com/en-us/quantum/relnotes/</PackageReleaseNotes>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<ProjectUrl>https://docs.microsoft.com/quantum/</ProjectUrl>
|
||||
<PackageProjectUrl>https://github.com/microsoft/qsharp-runtime</PackageProjectUrl>
|
||||
<PackageIcon>qdk-nuget-icon.png</PackageIcon>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Microsoft.Quantum.Runtime.Core.csproj" />
|
||||
<ProjectReference Include="..\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Microsoft.Quantum.Simulation.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that implements exception to be thrown when Operation is not supported.
|
||||
/// </summary>
|
||||
public class UnsupportedOperationException : PlatformNotSupportedException
|
||||
{
|
||||
public UnsupportedOperationException(string text = "",
|
||||
[CallerFilePath] string file = "",
|
||||
[CallerMemberName] string member = "",
|
||||
[CallerLineNumber] int line = 0)
|
||||
: base($"{file}::{line}::[{member}]:{text}")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -18,10 +18,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(EnlistmentRoot)src\Simulation\Core\Microsoft.Quantum.Runtime.Core.csproj" />
|
||||
<ProjectReference Include="$(EnlistmentRoot)src\Simulation\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
|
||||
<ProjectReference Include="$(EnlistmentRoot)src\Simulation\Common\Microsoft.Quantum.Simulation.Common.csproj" IncludeInSimulatorPackage="true" />
|
||||
<ProjectReference Include="$(EnlistmentRoot)src\Simulation\QCTraceSimulator\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj" IncludeInSimulatorPackage="true" />
|
||||
<ProjectReference Include="$(EnlistmentRoot)src\Simulation\Simulators\Microsoft.Quantum.Simulators.csproj" Condition=" '$([MSBuild]::NormalizePath($(EnlistmentRoot)src\Simulation\Simulators))' != '$(MSBuildProjectDirectory)'" IncludeInSimulatorPackage="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup>
|
||||
<EnlistmentRoot>$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\))</EnlistmentRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="AssemblyCommon.props" />
|
||||
<Import Project="DebugSymbols.props" />
|
||||
<Import Project="Simulators.Dev.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IncludeQSharpCorePackages>false</IncludeQSharpCorePackages>
|
||||
<CSharpGeneration>false</CSharpGeneration><!-- we will provide our own -->
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="$(EnlistmentRoot)src\Simulation\Common\DelaySign.cs" Link="Properties\DelaySign.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(EnlistmentRoot)src\Simulation\CSharpGeneration\Microsoft.Quantum.CSharpGeneration.fsproj" IsQscReference="true" />
|
||||
<ProjectReference Include="$(EnlistmentRoot)src\Xunit\Microsoft.Quantum.Xunit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -8,14 +8,8 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Authors>Microsoft</Authors>
|
||||
<Description>Core support for the Q# runtime.</Description>
|
||||
<PackageReleaseNotes>See: https://docs.microsoft.com/en-us/quantum/relnotes/</PackageReleaseNotes>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/microsoft/qsharp-runtime</PackageProjectUrl>
|
||||
<PackageIcon>qdk-nuget-icon.png</PackageIcon>
|
||||
<PackageTags>Quantum Q# QSharp</PackageTags>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\CSharpGeneration\Microsoft.Quantum.CSharpGeneration.fsproj" />
|
||||
<ProjectReference Include="..\EntryPointDriver\Microsoft.Quantum.EntryPointDriver.csproj" />
|
||||
<ProjectReference Include="..\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
|
||||
<ProjectReference Include="..\TargetDefinitions\Interfaces\Microsoft.Quantum.Targets.Interfaces.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -99,11 +99,13 @@ 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"
|
||||
"Microsoft.Quantum.Simulation.Common"
|
||||
"Microsoft.Quantum.Simulators"
|
||||
"Microsoft.Quantum.Targets.Interfaces"
|
||||
]
|
||||
|> List.map (fun name -> upcast MetadataReference.CreateFromFile (referencedAssembly name))
|
||||
|
||||
|
|
|
@ -11,14 +11,8 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Authors>Microsoft</Authors>
|
||||
<Description>Entry point driver for Q# command line applications.</Description>
|
||||
<PackageReleaseNotes>See: https://docs.microsoft.com/en-us/quantum/relnotes/</PackageReleaseNotes>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/microsoft/qsharp-runtime</PackageProjectUrl>
|
||||
<PackageIcon>qdk-nuget-icon.png</PackageIcon>
|
||||
<PackageTags>Quantum Q# QSharp</PackageTags>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -26,7 +20,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Microsoft.Quantum.Runtime.Core.csproj" />
|
||||
<ProjectReference Include="..\Simulators\Microsoft.Quantum.Simulators.csproj" />
|
||||
<ProjectReference Include="..\..\Azure\Azure.Quantum.Client\Microsoft.Azure.Quantum.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
using System;
|
||||
using System.CommandLine.Parsing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Quantum.Simulation.Core;
|
||||
using Microsoft.Quantum.Simulation.Simulators;
|
||||
|
@ -31,7 +33,15 @@ namespace Microsoft.Quantum.EntryPointDriver
|
|||
{
|
||||
if (simulator == settings.ResourcesEstimatorName)
|
||||
{
|
||||
var resourcesEstimator = new ResourcesEstimator();
|
||||
// Force the explicit load of the QSharp.Core assembly so that the ResourcesEstimator
|
||||
// can discover it dynamically at runtime and override the defined callables.
|
||||
var coreAssemblyName =
|
||||
(from aName in entryPoint.GetType().Assembly.GetReferencedAssemblies()
|
||||
where aName.Name == "Microsoft.Quantum.QSharp.Core"
|
||||
select aName).First();
|
||||
var coreAssembly = Assembly.Load(coreAssemblyName.FullName);
|
||||
|
||||
var resourcesEstimator = new ResourcesEstimator(coreAssembly);
|
||||
await resourcesEstimator.Run<TCallable, TIn, TOut>(entryPoint.CreateArgument(parseResult));
|
||||
Console.WriteLine(resourcesEstimator.ToTSV());
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.Tests
|
|||
[Fact]
|
||||
public void DistinctQubitsTests()
|
||||
{
|
||||
QCTraceSimulator sim = new QCTraceSimulator( new QCTraceSimulatorConfiguration() { UseDistinctInputsChecker = true } );
|
||||
QCTraceSimulator sim = new QCTraceSimulator(new QCTraceSimulatorConfiguration() { UseDistinctInputsChecker = true } );
|
||||
Assert.Throws<DistinctInputsCheckerException>(GetTest<DisctinctQubitTest>(sim));
|
||||
Assert.Throws<DistinctInputsCheckerException>(GetTest<DisctinctQubitCapturedTest>(sim));
|
||||
Assert.Throws<DistinctInputsCheckerException>(GetTest<DisctinctQubitCaptured2Test>(sim));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.Quantum.Sdk/0.13.2011.802-alpha">
|
||||
<Project Sdk="Microsoft.Quantum.Sdk/0.14.2012122063-beta">
|
||||
|
||||
<Import Project="..\Common\AssemblyCommon.props" />
|
||||
<Import Project="..\Common\Simulators.Dev.props" />
|
||||
|
@ -13,6 +13,8 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Xunit\Microsoft.Quantum.Xunit.csproj" />
|
||||
<ProjectReference Include="..\CSharpGeneration\Microsoft.Quantum.CSharpGeneration.fsproj" IsQscReference="true" />
|
||||
<ProjectReference Include="..\Simulators\Microsoft.Quantum.Simulators.csproj" />
|
||||
<ProjectReference Include="..\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.Quantum.Extensions.Diagnostics {
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.dumpmachine".
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.DumpMachine")
|
||||
function DumpMachine<'T> (location : 'T) : Unit {
|
||||
return Microsoft.Quantum.Diagnostics.DumpMachine(location);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.dumpregister".
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.DumpRegister")
|
||||
function DumpRegister<'T> (location : 'T, qubits : Qubit[]) : Unit {
|
||||
return Microsoft.Quantum.Diagnostics.DumpRegister(location, qubits);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.Quantum.Extensions.Testing {
|
||||
open Microsoft.Quantum.Math;
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertqubit".
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertQubit")
|
||||
operation AssertQubit(expected : Result, q : Qubit) : Unit {
|
||||
Microsoft.Quantum.Diagnostics.AssertQubit(expected, q);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertqubitwithintolerance".
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertQubitWithinTolerance")
|
||||
operation AssertQubitTol(expected : Result, q : Qubit, tolerance : Double) : Unit {
|
||||
Microsoft.Quantum.Diagnostics.AssertQubitWithinTolerance(expected, q, tolerance);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertqubitisinstatewithintolerance".
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertQubitIsInStateWithinTolerance")
|
||||
operation AssertQubitState(expected : (Complex, Complex), register : Qubit, tolerance : Double) : Unit {
|
||||
Microsoft.Quantum.Diagnostics.AssertQubitIsInStateWithinTolerance(expected, register, tolerance);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertoperationsequalreferenced".
|
||||
/// Note that the order of the arguments to this operation has changed.
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertOperationsEqualReferenced")
|
||||
operation AssertOperationsEqualReferenced(actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit {
|
||||
Microsoft.Quantum.Diagnostics.AssertOperationsEqualReferenced(nQubits, actual, expected);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertoperationsequalinplace".
|
||||
/// Note that the order of the arguments to this operation has changed.
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlace")
|
||||
operation AssertOperationsEqualInPlace(actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit {
|
||||
Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlace(nQubits, actual, expected);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertoperationsequalinplaceCompBasis".
|
||||
/// Note that the order of the arguments to this operation has changed.
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlaceCompBasis")
|
||||
operation AssertOperationsEqualInPlaceCompBasis(actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit {
|
||||
Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlaceCompBasis(nQubits, actual, expected);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertallzero".
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertAllZero")
|
||||
operation AssertAllZero(qubits : Qubit[]) : Unit is Adj + Ctl {
|
||||
Microsoft.Quantum.Diagnostics.AssertAllZero(qubits);
|
||||
}
|
||||
|
||||
/// # Deprecated
|
||||
/// Please use @"microsoft.quantum.diagnostics.assertallzerowithintolerance".
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertAllZeroWithinTolerance")
|
||||
operation AssertAllZeroTol(qubits : Qubit[], tolerance : Double) : Unit is Adj + Ctl {
|
||||
Microsoft.Quantum.Diagnostics.AssertAllZeroWithinTolerance(qubits, tolerance);
|
||||
}
|
||||
|
||||
}
|
|
@ -88,4 +88,113 @@ namespace Microsoft.Quantum.Intrinsic
|
|||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimExp : Exp
|
||||
{
|
||||
public QSimExp(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimExpFrac : ExpFrac
|
||||
{
|
||||
public QSimExpFrac(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimH : H
|
||||
{
|
||||
public QSimH(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimM : M
|
||||
{
|
||||
public QSimM(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimMeasure : Measure
|
||||
{
|
||||
public QSimMeasure(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimR : R
|
||||
{
|
||||
public QSimR(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimRFrac : RFrac
|
||||
{
|
||||
public QSimRFrac(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimS : S
|
||||
{
|
||||
public QSimS(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimT : T
|
||||
{
|
||||
public QSimT(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimX : X
|
||||
{
|
||||
public QSimX(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimY : Y
|
||||
{
|
||||
public QSimY(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This class is deprecated and will be removed in a future release. Considering using the corresponding callable class from 'Microsoft.Quantum.Intrinsic' directly.")]
|
||||
public class QSimZ : Z
|
||||
{
|
||||
public QSimZ(IOperationFactory factory) : base(factory)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,695 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.Quantum.Intrinsic {
|
||||
open Microsoft.Quantum.Math;
|
||||
open Microsoft.Quantum.Convert;
|
||||
open Microsoft.Quantum.Targeting;
|
||||
|
||||
@Deprecated("Microsoft.Quantum.Random.DrawCategorical")
|
||||
operation Random (probs : Double[]) : Int {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertMeasurement")
|
||||
operation Assert (bases : Pauli[], qubits : Qubit[], result : Result, msg : String) : Unit
|
||||
is Adj + Ctl {
|
||||
Microsoft.Quantum.Diagnostics.AssertMeasurement(bases, qubits, result, msg);
|
||||
}
|
||||
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertMeasurementProbability")
|
||||
operation AssertProb (bases : Pauli[], qubits : Qubit[], result : Result, prob : Double, msg : String, tol : Double) : Unit
|
||||
is Adj + Ctl {
|
||||
Microsoft.Quantum.Diagnostics.AssertMeasurementProbability(bases, qubits, result, prob, msg, tol);
|
||||
}
|
||||
|
||||
|
||||
/// # 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
|
||||
//-------------------------------------------------
|
||||
|
||||
/// # Summary
|
||||
/// Performs the identity operation (no-op) on a single qubit.
|
||||
///
|
||||
/// # Remarks
|
||||
/// This is a no-op. It is provided for completeness and because
|
||||
/// sometimes it is useful to call the identity in an algorithm or to pass it as a parameter.
|
||||
operation I (target : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body (...) { }
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the Pauli $X$ gate.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// \sigma_x \mathrel{:=}
|
||||
/// \begin{bmatrix}
|
||||
/// 0 & 1 \\\\
|
||||
/// 1 & 0
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
operation X (qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
/// Applies the Pauli $Y$ gate.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// \sigma_y \mathrel{:=}
|
||||
/// \begin{bmatrix}
|
||||
/// 0 & -i \\\\
|
||||
/// i & 0
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
operation Y (qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the Pauli $Z$ gate.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// \sigma_z \mathrel{:=}
|
||||
/// \begin{bmatrix}
|
||||
/// 1 & 0 \\\\
|
||||
/// 0 & -1
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
operation Z (qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the Hadamard transformation to a single qubit.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// H \mathrel{:=}
|
||||
/// \frac{1}{\sqrt{2}}
|
||||
/// \begin{bmatrix}
|
||||
/// 1 & 1 \\\\
|
||||
/// 1 & -1
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
operation H (qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the S gate to a single qubit.
|
||||
///
|
||||
/// # Description
|
||||
/// This operation can be simulated by the unitary matrix
|
||||
/// \begin{align}
|
||||
/// S \mathrel{:=}
|
||||
/// \begin{bmatrix}
|
||||
/// 1 & 0 \\\\
|
||||
/// 0 & i
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
operation S(qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the T gate to a single qubit.
|
||||
///
|
||||
/// # Description
|
||||
/// This operation can be simulated by the unitary matrix
|
||||
/// \begin{align}
|
||||
/// T \mathrel{:=}
|
||||
/// \begin{bmatrix}
|
||||
/// 1 & 0 \\\\
|
||||
/// 0 & e^{i \pi / 4}
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
operation T(qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the controlled-NOT (CNOT) gate to a pair of qubits.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// \operatorname{CNOT} \mathrel{:=}
|
||||
/// \begin{bmatrix}
|
||||
/// 1 & 0 & 0 & 0 \\\\
|
||||
/// 0 & 1 & 0 & 0 \\\\
|
||||
/// 0 & 0 & 0 & 1 \\\\
|
||||
/// 0 & 0 & 1 & 0
|
||||
/// \end{bmatrix},
|
||||
/// \end{align}
|
||||
///
|
||||
/// where rows and columns are ordered as in the quantum concepts guide.
|
||||
///
|
||||
/// # Input
|
||||
/// ## control
|
||||
/// Control qubit for the CNOT gate.
|
||||
/// ## target
|
||||
/// Target qubit for the CNOT gate.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// Controlled X([control], target);
|
||||
/// ```
|
||||
operation CNOT (control : Qubit, target : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
|
||||
body (...) {
|
||||
Controlled X([control], target);
|
||||
}
|
||||
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the doubly controlled–NOT (CCNOT) gate to three qubits.
|
||||
///
|
||||
/// # Input
|
||||
/// ## control1
|
||||
/// First control qubit for the CCNOT gate.
|
||||
/// ## control2
|
||||
/// Second control qubit for the CCNOT gate.
|
||||
/// ## target
|
||||
/// Target qubit for the CCNOT gate.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// Controlled X([control1, control2], target);
|
||||
/// ```
|
||||
operation CCNOT (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body (...) {
|
||||
Controlled X([control1, control2], target);
|
||||
}
|
||||
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the SWAP gate to a pair of qubits.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// \operatorname{SWAP} \mathrel{:=}
|
||||
/// \begin{bmatrix}
|
||||
/// 1 & 0 & 0 & 0 \\\\
|
||||
/// 0 & 0 & 1 & 0 \\\\
|
||||
/// 0 & 1 & 0 & 0 \\\\
|
||||
/// 0 & 0 & 0 & 1
|
||||
/// \end{bmatrix},
|
||||
/// \end{align}
|
||||
///
|
||||
/// where rows and columns are ordered as in the quantum concepts guide.
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit1
|
||||
/// First qubit to be swapped.
|
||||
/// ## qubit2
|
||||
/// Second qubit to be swapped.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// CNOT(qubit1, qubit2);
|
||||
/// CNOT(qubit2, qubit1);
|
||||
/// CNOT(qubit1, qubit2);
|
||||
/// ```
|
||||
operation SWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body (...)
|
||||
{
|
||||
within {
|
||||
CNOT(qubit1, qubit2);
|
||||
} apply {
|
||||
CNOT(qubit2, qubit1);
|
||||
}
|
||||
}
|
||||
|
||||
adjoint self;
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// Rotations
|
||||
//-------------------------------------------------
|
||||
|
||||
/// # Summary
|
||||
/// Applies a rotation about the given Pauli axis.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// R_{\mu}(\theta) \mathrel{:=}
|
||||
/// e^{-i \theta \sigma_{\mu} / 2},
|
||||
/// \end{align}
|
||||
/// where $\mu \in \{I, X, Y, Z\}$.
|
||||
///
|
||||
/// # Input
|
||||
/// ## pauli
|
||||
/// Pauli operator ($\mu$) to be exponentiated to form the rotation.
|
||||
/// ## theta
|
||||
/// Angle about which the qubit is to be rotated.
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
///
|
||||
/// # Remarks
|
||||
/// When called with `pauli = PauliI`, this operation applies
|
||||
/// a *global phase*. This phase can be significant
|
||||
/// when used with the `Controlled` functor.
|
||||
operation R (pauli : Pauli, theta : Double, qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies a rotation about the given Pauli axis by an angle specified
|
||||
/// as a dyadic fraction.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// R_{\mu}(n, k) \mathrel{:=}
|
||||
/// e^{i \pi n \sigma_{\mu} / 2^k},
|
||||
/// \end{align}
|
||||
/// where $\mu \in \{I, X, Y, Z\}$.
|
||||
///
|
||||
/// > [!WARNING]
|
||||
/// > This operation uses the **opposite** sign convention from
|
||||
/// > @"microsoft.quantum.intrinsic.r".
|
||||
///
|
||||
/// # Input
|
||||
/// ## pauli
|
||||
/// Pauli operator to be exponentiated to form the rotation.
|
||||
/// ## numerator
|
||||
/// Numerator in the dyadic fraction representation of the angle
|
||||
/// by which the qubit is to be rotated.
|
||||
/// ## power
|
||||
/// Power of two specifying the denominator of the angle by which
|
||||
/// the qubit is to be rotated.
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// // PI() is a Q# function that returns an approximation of π.
|
||||
/// R(pauli, -PI() * IntAsDouble(numerator) / IntAsDouble(2 ^ (power - 1)), qubit);
|
||||
/// ```
|
||||
operation RFrac (pauli : Pauli, numerator : Int, power : Int, qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
|
||||
let angle = ((-2.0 * PI()) * IntAsDouble(numerator)) / IntAsDouble(2 ^ power);
|
||||
R(pauli, angle, qubit);
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies a rotation about the $x$-axis by a given angle.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// R_x(\theta) \mathrel{:=}
|
||||
/// e^{-i \theta \sigma_x / 2} =
|
||||
/// \begin{bmatrix}
|
||||
/// \cos \frac{\theta}{2} & -i\sin \frac{\theta}{2} \\\\
|
||||
/// -i\sin \frac{\theta}{2} & \cos \frac{\theta}{2}
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## theta
|
||||
/// Angle about which the qubit is to be rotated.
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// R(PauliX, theta, qubit);
|
||||
/// ```
|
||||
operation Rx (theta : Double, qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body (...)
|
||||
{
|
||||
R(PauliX, theta, qubit);
|
||||
}
|
||||
|
||||
adjoint (...)
|
||||
{
|
||||
R(PauliX, -theta, qubit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies a rotation about the $y$-axis by a given angle.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// R_y(\theta) \mathrel{:=}
|
||||
/// e^{-i \theta \sigma_y / 2} =
|
||||
/// \begin{bmatrix}
|
||||
/// \cos \frac{\theta}{2} & -\sin \frac{\theta}{2} \\\\
|
||||
/// \sin \frac{\theta}{2} & \cos \frac{\theta}{2}
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## theta
|
||||
/// Angle about which the qubit is to be rotated.
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// R(PauliY, theta, qubit);
|
||||
/// ```
|
||||
operation Ry (theta : Double, qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body (...)
|
||||
{
|
||||
R(PauliY, theta, qubit);
|
||||
}
|
||||
|
||||
adjoint (...)
|
||||
{
|
||||
R(PauliY, -theta, qubit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies a rotation about the $z$-axis by a given angle.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// R_z(\theta) \mathrel{:=}
|
||||
/// e^{-i \theta \sigma_z / 2} =
|
||||
/// \begin{bmatrix}
|
||||
/// e^{-i \theta / 2} & 0 \\\\
|
||||
/// 0 & e^{i \theta / 2}
|
||||
/// \end{bmatrix}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## theta
|
||||
/// Angle about which the qubit is to be rotated.
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// R(PauliZ, theta, qubit);
|
||||
/// ```
|
||||
operation Rz (theta : Double, qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
body (...)
|
||||
{
|
||||
R(PauliZ, theta, qubit);
|
||||
}
|
||||
|
||||
adjoint (...)
|
||||
{
|
||||
R(PauliZ, -theta, qubit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies a rotation about the $\ket{1}$ state by a given angle.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// R_1(\theta) \mathrel{:=}
|
||||
/// \operatorname{diag}(1, e^{i\theta}).
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## theta
|
||||
/// Angle about which the qubit is to be rotated.
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// R(PauliZ, theta, qubit);
|
||||
/// R(PauliI, -theta, qubit);
|
||||
/// ```
|
||||
operation R1 (theta : Double, qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
|
||||
R(PauliZ, theta, qubit);
|
||||
R(PauliI, -theta, qubit);
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies a rotation about the $\ket{1}$ state by an angle specified
|
||||
/// as a dyadic fraction.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// R_1(n, k) \mathrel{:=}
|
||||
/// \operatorname{diag}(1, e^{i \pi k / 2^n}).
|
||||
/// \end{align}
|
||||
///
|
||||
/// > [!WARNING]
|
||||
/// > This operation uses the **opposite** sign convention from
|
||||
/// > @"microsoft.quantum.intrinsic.r", and does not include the
|
||||
/// > factor of $1/ 2$ included by @"microsoft.quantum.intrinsic.r1".
|
||||
///
|
||||
/// # Input
|
||||
/// ## numerator
|
||||
/// Numerator in the dyadic fraction representation of the angle
|
||||
/// by which the qubit is to be rotated.
|
||||
/// ## power
|
||||
/// Power of two specifying the denominator of the angle by which
|
||||
/// the qubit is to be rotated.
|
||||
/// ## qubit
|
||||
/// Qubit to which the gate should be applied.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// RFrac(PauliZ, -numerator, denominator + 1, qubit);
|
||||
/// RFrac(PauliI, numerator, denominator + 1, qubit);
|
||||
/// ```
|
||||
operation R1Frac (numerator : Int, power : Int, qubit : Qubit) : Unit
|
||||
is Adj + Ctl {
|
||||
|
||||
RFrac(PauliZ, -numerator, power + 1, qubit);
|
||||
RFrac(PauliI, numerator, power + 1, qubit);
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the exponential of a multi-qubit Pauli operator.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// e^{i \theta [P_0 \otimes P_1 \cdots P_{N-1}]},
|
||||
/// \end{align}
|
||||
/// where $P_i$ is the $i$th element of `paulis`, and where
|
||||
/// $N = $`Length(paulis)`.
|
||||
///
|
||||
/// # Input
|
||||
/// ## paulis
|
||||
/// Array of single-qubit Pauli values indicating the tensor product
|
||||
/// factors on each qubit.
|
||||
/// ## theta
|
||||
/// Angle about the given multi-qubit Pauli operator by which the
|
||||
/// target register is to be rotated.
|
||||
/// ## qubits
|
||||
/// Register to apply the given rotation to.
|
||||
operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit
|
||||
is Adj + Ctl {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Applies the exponential of a multi-qubit Pauli operator
|
||||
/// with an argument given by a dyadic fraction.
|
||||
///
|
||||
/// \begin{align}
|
||||
/// e^{i \pi k [P_0 \otimes P_1 \cdots P_{N-1}] / 2^n},
|
||||
/// \end{align}
|
||||
/// where $P_i$ is the $i$th element of `paulis`, and where
|
||||
/// $N = $`Length(paulis)`.
|
||||
///
|
||||
/// # Input
|
||||
/// ## paulis
|
||||
/// Array of single-qubit Pauli values indicating the tensor product
|
||||
/// factors on each qubit.
|
||||
/// ## numerator
|
||||
/// Numerator ($k$) in the dyadic fraction representation of the angle
|
||||
/// by which the qubit register is to be rotated.
|
||||
/// ## power
|
||||
/// Power of two ($n$) specifying the denominator of the angle by which
|
||||
/// the qubit register is to be rotated.
|
||||
/// ## qubits
|
||||
/// Register to apply the given rotation to.
|
||||
operation ExpFrac (paulis : Pauli[], numerator : Int, power : Int, qubits : Qubit[]) : Unit
|
||||
is Adj + Ctl {
|
||||
let angle = (PI() * IntAsDouble(numerator)) / IntAsDouble(2 ^ power);
|
||||
Exp(paulis, angle, qubits);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// Measurements
|
||||
//-------------------------------------------------
|
||||
|
||||
/// # Summary
|
||||
/// Performs a joint measurement of one or more qubits in the
|
||||
/// specified Pauli bases.
|
||||
///
|
||||
/// The output result is given by the distribution:
|
||||
/// \begin{align}
|
||||
/// \Pr(\texttt{Zero} | \ket{\psi}) =
|
||||
/// \frac12 \braket{
|
||||
/// \psi \mid|
|
||||
/// \left(
|
||||
/// \boldone + P_0 \otimes P_1 \otimes \cdots \otimes P_{N-1}
|
||||
/// \right) \mid|
|
||||
/// \psi
|
||||
/// },
|
||||
/// \end{align}
|
||||
/// where $P_i$ is the $i$th element of `bases`, and where
|
||||
/// $N = \texttt{Length}(\texttt{bases})$.
|
||||
/// That is, measurement returns a `Result` $d$ such that the eigenvalue of the
|
||||
/// observed measurement effect is $(-1)^d$.
|
||||
///
|
||||
/// # Input
|
||||
/// ## bases
|
||||
/// Array of single-qubit Pauli values indicating the tensor product
|
||||
/// factors on each qubit.
|
||||
/// ## qubits
|
||||
/// Register of qubits to be measured.
|
||||
///
|
||||
/// # Output
|
||||
/// `Zero` if the $+1$ eigenvalue is observed, and `One` if
|
||||
/// the $-1$ eigenvalue is observed.
|
||||
///
|
||||
/// # Remarks
|
||||
/// If the basis array and qubit array are different lengths, then the
|
||||
/// operation will fail.
|
||||
operation Measure (bases : Pauli[], qubits : Qubit[]) : Result {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Performs a measurement of a single qubit in the
|
||||
/// Pauli $Z$ basis.
|
||||
///
|
||||
/// The output result is given by
|
||||
/// the distribution
|
||||
/// \begin{align}
|
||||
/// \Pr(\texttt{Zero} | \ket{\psi}) =
|
||||
/// \braket{\psi | 0} \braket{0 | \psi}.
|
||||
/// \end{align}
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubit
|
||||
/// Qubit to be measured.
|
||||
///
|
||||
/// # Output
|
||||
/// `Zero` if the $+1$ eigenvalue is observed, and `One` if
|
||||
/// the $-1$ eigenvalue is observed.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Equivalent to:
|
||||
/// ```qsharp
|
||||
/// Measure([PauliZ], [qubit]);
|
||||
/// ```
|
||||
operation M (qubit : Qubit) : Result {
|
||||
return Measure([PauliZ], [qubit]);
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Given a single qubit, measures it and ensures it is in the |0⟩ state
|
||||
/// such that it can be safely released.
|
||||
///
|
||||
/// # Input
|
||||
/// ## target
|
||||
/// The qubit whose state is to be reset to $\ket{0}$.
|
||||
@RequiresCapability(
|
||||
"BasicQuantumFunctionality",
|
||||
"Reset is replaced by a supported implementation on all execution targets."
|
||||
)
|
||||
operation Reset (target : Qubit) : Unit {
|
||||
if (M(target) == One) {
|
||||
X(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Given an array of qubits, measure them and ensure they are in the |0⟩ state
|
||||
/// such that they can be safely released.
|
||||
///
|
||||
/// # Input
|
||||
/// ## qubits
|
||||
/// An array of qubits whose states are to be reset to $\ket{0}$.
|
||||
operation ResetAll (qubits : Qubit[]) : Unit {
|
||||
for (qubit in qubits) {
|
||||
Reset(qubit);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +1,13 @@
|
|||
<Project Sdk="Microsoft.Quantum.Sdk/0.13.2011.802-alpha">
|
||||
<Project Sdk="Microsoft.Quantum.Sdk/0.14.2012122063-beta">
|
||||
|
||||
<Import Project="..\Common\AssemblyCommon.props" />
|
||||
<Import Project="..\Common\DebugSymbols.props" />
|
||||
<Import Project="..\TargetDefinitions\TargetPackages\QSharpCore.Package.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<QSharpDocsGeneration>true</QSharpDocsGeneration>
|
||||
<CSharpGeneration>false</CSharpGeneration> <!-- we will provide our own -->
|
||||
<IncludeQSharpCorePackages>false</IncludeQSharpCorePackages>
|
||||
<QscVerbosity>detailed</QscVerbosity>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Authors>Microsoft</Authors>
|
||||
<Description>Core support for the Q# programming language.</Description>
|
||||
<PackageReleaseNotes>See: https://docs.microsoft.com/en-us/quantum/relnotes/</PackageReleaseNotes>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/microsoft/qsharp-runtime</PackageProjectUrl>
|
||||
<PackageIcon>qdk-nuget-icon.png</PackageIcon>
|
||||
<PackageTags>Quantum Q# QSharp</PackageTags>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<GenerateConcreteIntrinsic>true</GenerateConcreteIntrinsic>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\DelaySign.cs" Link="Properties\DelaySign.cs" />
|
||||
<ProjectReference Include="..\Simulators\Microsoft.Quantum.Simulators.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Microsoft.Quantum.Runtime.Core.csproj" />
|
||||
<ProjectReference Include="..\CSharpGeneration\Microsoft.Quantum.CSharpGeneration.fsproj" PrivateAssets="All" IsQscReference="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\build\assets\qdk-nuget-icon.png" Pack="true" Visible="false" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="BeforeCSharpCompile">
|
||||
<ItemGroup>
|
||||
<Compile Include="$(GeneratedFilesOutputPath)**/*.g.cs" Exclude="@(Compile)" AutoGen="true" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allow the simulator assembly to use our internal methods
|
||||
[assembly: InternalsVisibleTo("Microsoft.Quantum.Simulators" + SigningConstants.PUBLIC_KEY)]
|
|
@ -29,7 +29,8 @@ namespace Microsoft.Quantum.Simulation.QuantumProcessor
|
|||
/// <param name="quantumProcessor">An instance of a class implementing <see cref="IQuantumProcessor"/> interface to be wrapped.</param>
|
||||
/// <param name="qubitManager">An instance of a class implementing <see cref="IQubitManager"/> interface. If the parameter is null <see cref="QubitManager"/> is used.</param>
|
||||
/// <param name="randomSeed">A seed to be used by Q# <a href="https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.random">Microsoft.Quantum.Intrinsic.Random</a> operation.</param>
|
||||
public QuantumProcessorDispatcher(IQuantumProcessor quantumProcessor, IQubitManager? qubitManager = null, int? randomSeed = null)
|
||||
/// <param name="onlyOverrideBodyIntrinsic">A boolean that indicates whether only Q# callables that are defined as body intrinsic should be overridden. If false, the C# implementation will always override any Q# implementation. If true, the C# will only override Q# that does not have an implementation and is marked as body intrinsic. The value is false by default.</param>
|
||||
public QuantumProcessorDispatcher(IQuantumProcessor quantumProcessor, IQubitManager? qubitManager = null, int? randomSeed = null, bool onlyOverrideBodyIntrinsic = false)
|
||||
: base(
|
||||
qubitManager ?? new QubitManager(
|
||||
PreallocatedQubitCount,
|
|
@ -1,140 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.Quantum.Measurement {
|
||||
open Microsoft.Quantum.Intrinsic;
|
||||
open Microsoft.Quantum.Targeting;
|
||||
|
||||
internal operation BasisChangeZtoY(target : Qubit) : Unit is Adj + Ctl {
|
||||
H(target);
|
||||
S(target);
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Sets a qubit to a given computational basis state by measuring the
|
||||
/// qubit and applying a bit flip if needed.
|
||||
///
|
||||
/// # Input
|
||||
/// ## desired
|
||||
/// The basis state that the qubit should be set to.
|
||||
/// ## target
|
||||
/// The qubit whose state is to be set.
|
||||
///
|
||||
/// # Remarks
|
||||
/// As an invariant of this operation, calling `M(q)` immediately
|
||||
/// after `SetToBasisState(result, q)` will return `result`.
|
||||
operation SetToBasisState(desired : Result, target : Qubit) : Unit {
|
||||
if (desired != M(target)) {
|
||||
X(target);
|
||||
}
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
/// Measures a single qubit in the Z basis,
|
||||
/// and resets it to a fixed initial state
|
||||
/// following the measurement.
|
||||
///
|
||||
/// # Description
|
||||
/// Performs a single-qubit measurement in the $Z$-basis,
|
||||
/// and ensures that the qubit is returned to $\ket{0}$
|
||||
/// following the measurement.
|
||||
///
|
||||
/// # Input
|
||||
/// ## target
|
||||
/// A single qubit to be measured.
|
||||
///
|
||||
/// # Output
|
||||
/// The result of measuring `target` in the Pauli $Z$ basis.
|
||||
@RequiresCapability(
|
||||
"BasicQuantumFunctionality",
|
||||
"MResetZ is replaced by a supported implementation on all execution targets."
|
||||
)
|
||||
operation MResetZ (target : Qubit) : Result {
|
||||
let result = M(target);
|
||||
|
||||
if (result == One) {
|
||||
// Recall that the +1 eigenspace of a measurement operator corresponds to
|
||||
// the Result case Zero. Thus, if we see a One case, we must reset the state
|
||||
// have +1 eigenvalue.
|
||||
X(target);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Measures a single qubit in the X basis,
|
||||
/// and resets it to a fixed initial state
|
||||
/// following the measurement.
|
||||
///
|
||||
/// # Description
|
||||
/// Performs a single-qubit measurement in the $X$-basis,
|
||||
/// and ensures that the qubit is returned to $\ket{0}$
|
||||
/// following the measurement.
|
||||
///
|
||||
/// # Input
|
||||
/// ## target
|
||||
/// A single qubit to be measured.
|
||||
///
|
||||
/// # Output
|
||||
/// The result of measuring `target` in the Pauli $X$ basis.
|
||||
@RequiresCapability(
|
||||
"BasicQuantumFunctionality",
|
||||
"MResetX is replaced by a supported implementation on all execution targets."
|
||||
)
|
||||
operation MResetX (target : Qubit) : Result {
|
||||
let result = Measure([PauliX], [target]);
|
||||
|
||||
// We must return the qubit to the Z basis as well.
|
||||
H(target);
|
||||
|
||||
if (result == One) {
|
||||
// Recall that the +1 eigenspace of a measurement operator corresponds to
|
||||
// the Result case Zero. Thus, if we see a One case, we must reset the state
|
||||
// have +1 eigenvalue.
|
||||
X(target);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Measures a single qubit in the Y basis,
|
||||
/// and resets it to a fixed initial state
|
||||
/// following the measurement.
|
||||
///
|
||||
/// # Description
|
||||
/// Performs a single-qubit measurement in the $Y$-basis,
|
||||
/// and ensures that the qubit is returned to $\ket{0}$
|
||||
/// following the measurement.
|
||||
///
|
||||
/// # Input
|
||||
/// ## target
|
||||
/// A single qubit to be measured.
|
||||
///
|
||||
/// # Output
|
||||
/// The result of measuring `target` in the Pauli $Y$ basis.
|
||||
@RequiresCapability(
|
||||
"BasicQuantumFunctionality",
|
||||
"MResetY is replaced by a supported implementation on all execution targets."
|
||||
)
|
||||
operation MResetY (target : Qubit) : Result {
|
||||
let result = Measure([PauliY], [target]);
|
||||
|
||||
// We must return the qubit to the Z basis as well.
|
||||
Adjoint BasisChangeZtoY(target);
|
||||
|
||||
if (result == One) {
|
||||
// Recall that the +1 eigenspace of a measurement operator corresponds to
|
||||
// the Result case Zero. Thus, if we see a One case, we must reset the state
|
||||
// have +1 eigenvalue.
|
||||
X(target);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,9 +2,6 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.Quantum.Arrays {
|
||||
open Microsoft.Quantum.Intrinsic;
|
||||
open Microsoft.Quantum.Canon;
|
||||
|
||||
/// # Summary
|
||||
/// Given an array, returns a range over the indices of that array, suitable
|
||||
/// for use in a for loop.
|
||||
|
@ -29,5 +26,4 @@ namespace Microsoft.Quantum.Arrays {
|
|||
function IndexRange<'TElement>(array : 'TElement[]) : Range {
|
||||
return 0..(Length(array) - 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.Quantum.Intrinsic {
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertMeasurement")
|
||||
operation Assert (bases : Pauli[], qubits : Qubit[], result : Result, msg : String) : Unit
|
||||
is Adj + Ctl {
|
||||
Microsoft.Quantum.Diagnostics.AssertMeasurement(bases, qubits, result, msg);
|
||||
}
|
||||
|
||||
@Deprecated("Microsoft.Quantum.Diagnostics.AssertMeasurementProbability")
|
||||
operation AssertProb (bases : Pauli[], qubits : Qubit[], result : Result, prob : Double, msg : String, tol : Double) : Unit
|
||||
is Adj + Ctl {
|
||||
Microsoft.Quantum.Diagnostics.AssertMeasurementProbability(bases, qubits, result, prob, msg, tol);
|
||||
}
|
||||
}
|
|
@ -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.
|
|
@ -61,6 +61,10 @@ namespace Microsoft.Quantum.Core {
|
|||
/// # Summary
|
||||
/// Returns the defined start value of the given range.
|
||||
///
|
||||
/// # Input
|
||||
/// ## range
|
||||
/// Input range.
|
||||
///
|
||||
/// # Output
|
||||
/// The defined start value of the given range.
|
||||
///
|
||||
|
@ -81,7 +85,7 @@ namespace Microsoft.Quantum.Core {
|
|||
/// which is not necessarily the last element in the sequence.
|
||||
///
|
||||
/// # Input
|
||||
/// ## r
|
||||
/// ## range
|
||||
/// Input range.
|
||||
///
|
||||
/// # Output
|
||||
|
@ -103,7 +107,7 @@ namespace Microsoft.Quantum.Core {
|
|||
/// Returns the integer that specifies how the next value of a range is calculated.
|
||||
///
|
||||
/// # Input
|
||||
/// ## r
|
||||
/// ## range
|
||||
/// Input range.
|
||||
///
|
||||
/// # Output
|
||||
|
@ -121,7 +125,7 @@ namespace Microsoft.Quantum.Core {
|
|||
/// Returns a new range which is the reverse of the input range.
|
||||
///
|
||||
/// # Input
|
||||
/// ## r
|
||||
/// ## range
|
||||
/// Input range.
|
||||
///
|
||||
/// # Output
|
||||
|
@ -130,7 +134,7 @@ namespace Microsoft.Quantum.Core {
|
|||
/// # Remarks
|
||||
/// Note that the reverse of a range is not simply `end`..`-step`..`start`, because
|
||||
/// the actual last element of a range may not be the same as `end`.
|
||||
function RangeReverse(r : Range) : Range {
|
||||
function RangeReverse(range : Range) : Range {
|
||||
body intrinsic;
|
||||
}
|
||||
|
|
@ -2,9 +2,6 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.Quantum.Diagnostics {
|
||||
open Microsoft.Quantum.Intrinsic;
|
||||
open Microsoft.Quantum.Canon;
|
||||
|
||||
/// # Summary
|
||||
/// Asserts that measuring the given qubits in the given Pauli basis will
|
||||
/// always have the given result.
|
|
@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Diagnostics {
|
|||
/// Assert that given qubits are all in $\ket{0}$ state.
|
||||
///
|
||||
/// # Input
|
||||
/// ## target
|
||||
/// ## qubits
|
||||
/// Qubits that are asserted to be in $\ket{0}$ state.
|
||||
///
|
||||
/// # See Also
|
|
@ -22,7 +22,7 @@ namespace Microsoft.Quantum.Diagnostics {
|
|||
/// <xref:microsoft.quantum.diagnostics.assertqubitisinstatewithintolerance> allows for asserting
|
||||
/// arbitrary qubit states rather than only $Z$ eigenstates.
|
||||
operation AssertQubit (expected : Result, q : Qubit) : Unit {
|
||||
Assert([PauliZ], [q], expected, $"Qubit in invalid state. Expecting: {expected}");
|
||||
AssertMeasurement([PauliZ], [q], expected, $"Qubit in invalid state. Expecting: {expected}");
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
|
@ -47,7 +47,7 @@ namespace Microsoft.Quantum.Diagnostics {
|
|||
/// <xref:microsoft.quantum.diagnostics.assertqubitisinstatewithintolerance> allows for asserting
|
||||
/// arbitrary qubit states rather than only $Z$ eigenstates.
|
||||
operation AssertQubitWithinTolerance(expected : Result, q : Qubit, tolerance : Double) : Unit {
|
||||
AssertProb([PauliZ], [q], expected, 1.0, $"Qubit in invalid state. Expecting: {expected} with tolerance {tolerance}", tolerance);
|
||||
AssertMeasurementProbability([PauliZ], [q], expected, 1.0, $"Qubit in invalid state. Expecting: {expected} with tolerance {tolerance}", tolerance);
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
|
@ -126,10 +126,10 @@ namespace Microsoft.Quantum.Diagnostics {
|
|||
// Probability of getting outcome One in measuring PauliZ is Tr(M(I-Z)/2) = (mi-mz)/2.0
|
||||
// similarly, we find the probabilities for measuring PauliX,PauliY
|
||||
let tol = tolerance / 2.0;
|
||||
AssertProb([PauliX], [register], Zero, (mi + mx) / 2.0, $"Qubit Zero probability on X basis failed", tol);
|
||||
AssertProb([PauliY], [register], Zero, (mi + my) / 2.0, $"Qubit Zero probability on Y basis failed", tol);
|
||||
AssertProb([PauliZ], [register], Zero, (mi + mz) / 2.0, $"Qubit Zero probability on Z basis failed", tol);
|
||||
AssertProb([PauliZ], [register], One, (mi - mz) / 2.0, $"Qubit One probability on Z basis failed", tol);
|
||||
AssertMeasurementProbability([PauliX], [register], Zero, (mi + mx) / 2.0, $"Qubit Zero probability on X basis failed", tol);
|
||||
AssertMeasurementProbability([PauliY], [register], Zero, (mi + my) / 2.0, $"Qubit Zero probability on Y basis failed", tol);
|
||||
AssertMeasurementProbability([PauliZ], [register], Zero, (mi + mz) / 2.0, $"Qubit Zero probability on Z basis failed", tol);
|
||||
AssertMeasurementProbability([PauliZ], [register], One, (mi - mz) / 2.0, $"Qubit One probability on Z basis failed", tol);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ namespace Microsoft.Quantum.Diagnostics {
|
|||
/// one-dimensional array of complex numbers, in which each element represents
|
||||
/// the amplitudes of the probability of measuring the corresponding state.
|
||||
function DumpMachine<'T> (location : 'T) : Unit {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
|
@ -56,6 +57,7 @@ namespace Microsoft.Quantum.Diagnostics {
|
|||
/// If the given qubits are entangled with some other qubit and their
|
||||
/// state can't be separated, it just reports that the qubits are entangled.
|
||||
function DumpRegister<'T> (location : 'T, qubits : Qubit[]) : Unit {
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ namespace Microsoft.Quantum.Environment {
|
|||
/// # See Also
|
||||
/// - GetQubitsAvailableToBorrow
|
||||
operation GetQubitsAvailableToUse () : Int {
|
||||
return -1;
|
||||
body intrinsic;
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
|
@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Environment {
|
|||
/// # See Also
|
||||
/// - GetQubitsAvailableToUse
|
||||
operation GetQubitsAvailableToBorrow () : Int {
|
||||
return -1;
|
||||
body intrinsic;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<Project Sdk="Microsoft.Quantum.Sdk/0.14.2012122063-beta">
|
||||
|
||||
<Import Project="..\Common\AssemblyCommon.props" />
|
||||
<Import Project="..\Common\DebugSymbols.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<QSharpDocsGeneration>true</QSharpDocsGeneration>
|
||||
<CSharpGeneration>false</CSharpGeneration> <!-- we will provide our own -->
|
||||
<IncludeQSharpCorePackages>false</IncludeQSharpCorePackages>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Foundation implementation for the Q# programming language.</Description>
|
||||
<PackageTags>Quantum Q# QSharp</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\DelaySign.cs" Link="Properties\DelaySign.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Microsoft.Quantum.Runtime.Core.csproj" />
|
||||
<ProjectReference Include="..\CSharpGeneration\Microsoft.Quantum.CSharpGeneration.fsproj" PrivateAssets="All" IsQscReference="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\build\assets\qdk-nuget-icon.png" Pack="true" Visible="false" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="BeforeCSharpCompile">
|
||||
<ItemGroup>
|
||||
<Compile Include="$(GeneratedFilesOutputPath)**/*.g.cs" Exclude="@(Compile)" AutoGen="true" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// 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`.
|
||||
@Deprecated("Microsoft.Quantum.Random.DrawCategorical")
|
||||
operation Random (probs : Double[]) : Int {
|
||||
body intrinsic;
|
||||
}
|
||||
}
|
|
@ -3,4 +3,4 @@
|
|||
<appSettings>
|
||||
<add key="xunit.methodDisplay" value="method"/>
|
||||
</appSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
|
||||
</configuration>
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
open Microsoft.Quantum.Intrinsic;
|
||||
open Microsoft.Quantum.Math;
|
||||
open Microsoft.Quantum.Diagnostics;
|
||||
open Microsoft.Quantum.Simulation.TestSuite;
|
||||
open Microsoft.Quantum.Measurement;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -28,14 +28,14 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
let q1 = qubits[0];
|
||||
let (a, b) = expected;
|
||||
let (p, r) = start;
|
||||
SetQubit(r, q1);
|
||||
SetToBasisState(r, q1);
|
||||
|
||||
if (p == PauliX) {
|
||||
H(q1);
|
||||
}
|
||||
|
||||
// Make sure we start in correct state.
|
||||
Assert([p], [q1], r, $"Qubit in invalid state.");
|
||||
AssertMeasurement([p], [q1], r, $"Qubit in invalid state.");
|
||||
|
||||
// Apply the gate, make sure it's in the right state
|
||||
gate(q1);
|
||||
|
@ -43,7 +43,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
|
||||
// Apply Adjoint, back to Zero:
|
||||
Adjoint gate(q1);
|
||||
Assert([p], [q1], r, $"Qubit in invalid state.");
|
||||
AssertMeasurement([p], [q1], r, $"Qubit in invalid state.");
|
||||
|
||||
// When no control qubits, it should be equivalent to just calling the gate:
|
||||
Controlled gate(new Qubit[0], q1);
|
||||
|
@ -51,7 +51,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
|
||||
// Apply Adjoint, back to Zero:
|
||||
Controlled (Adjoint gate)(new Qubit[0], q1);
|
||||
Assert([p], [q1], r, $"Qubit in invalid state.");
|
||||
AssertMeasurement([p], [q1], r, $"Qubit in invalid state.");
|
||||
|
||||
// Now test control... We'll have 3 control qubits.
|
||||
// We will run the test with 1..3 controls at a time.
|
||||
|
@ -62,18 +62,18 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
for (i in 0 .. ctrlsCount - 1) {
|
||||
|
||||
// We're starting fresh
|
||||
Assert([p], [q1], r, $"Qubit in invalid state.");
|
||||
AssertMeasurement([p], [q1], r, $"Qubit in invalid state.");
|
||||
|
||||
// Get a subset for control and initialize them to zero:
|
||||
let c = ctrls[0 .. i];
|
||||
|
||||
for (j in 0 .. i) {
|
||||
SetQubit(Zero, c[j]);
|
||||
SetToBasisState(Zero, c[j]);
|
||||
}
|
||||
|
||||
// Noop when ctrls are all zero.
|
||||
Controlled gate(c, q1);
|
||||
Assert([p], [q1], r, $"Qubit in invalid state.");
|
||||
AssertMeasurement([p], [q1], r, $"Qubit in invalid state.");
|
||||
|
||||
// turn on each of the controls one by one
|
||||
for (j in 1 .. Length(c)) {
|
||||
|
@ -85,7 +85,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
AssertQubitIsInStateWithinTolerance(expected, q1, tolerance);
|
||||
}
|
||||
else {
|
||||
Assert([p], [q1], r, $"Qubit in invalid state.");
|
||||
AssertMeasurement([p], [q1], r, $"Qubit in invalid state.");
|
||||
}
|
||||
|
||||
Adjoint Controlled gate(c, q1);
|
||||
|
@ -96,8 +96,8 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
}
|
||||
|
||||
// We're back where we started.
|
||||
Assert([p], [q1], r, $"Qubit in invalid state.");
|
||||
SetQubit(r, q1);
|
||||
AssertMeasurement([p], [q1], r, $"Qubit in invalid state.");
|
||||
SetToBasisState(r, q1);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests
|
|||
{
|
||||
var _ = AbstractCallable._;
|
||||
|
||||
var dump = qsim.Get<ICallable>(typeof(Microsoft.Quantum.Extensions.Diagnostics.DumpMachine<>));
|
||||
var dump = qsim.Get<ICallable>(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>));
|
||||
var trace = qsim.Get<IUnitary>(typeof(Circuits.Generics.Trace<>));
|
||||
var x = qsim.Get<Intrinsic.X>();
|
||||
var q2 = new FreeQubit(2) as Qubit;
|
||||
|
@ -223,7 +223,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests
|
|||
{
|
||||
Helper.RunWithMultipleSimulators((qsim) =>
|
||||
{
|
||||
var dump = qsim.Get<ICallable>(typeof(Microsoft.Quantum.Extensions.Diagnostics.DumpMachine<>)) as GenericCallable;
|
||||
var dump = qsim.Get<ICallable>(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable;
|
||||
var trace = qsim.Get<IUnitary>(typeof(Circuits.Generics.Trace<>)) as GenericCallable;
|
||||
var gen3 = qsim.Get<IControllable>(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable;
|
||||
|
||||
|
@ -231,7 +231,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests
|
|||
TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Adjoint, "T => () : Adjoint, Controlled", trace.Adjoint);
|
||||
TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Controlled, "(Qubit[],T) => () : Adjoint, Controlled", trace.Controlled);
|
||||
TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.ControlledAdjoint, "(Qubit[],T) => () : Adjoint, Controlled", trace.Adjoint.Controlled);
|
||||
TestOneProxy("DumpMachine", "Microsoft.Quantum.Extensions.Diagnostics.DumpMachine", OperationFunctor.Body, "T => ()", dump);
|
||||
TestOneProxy("DumpMachine", "Microsoft.Quantum.Diagnostics.DumpMachine", OperationFunctor.Body, "T => ()", dump);
|
||||
TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Body, "(__T1,(__T2,__T3),Result) => () : Controlled", gen3);
|
||||
TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Controlled, "(Qubit[],(__T1,(__T2,__T3),Result)) => () : Controlled", gen3.Controlled);
|
||||
});
|
||||
|
@ -252,7 +252,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests
|
|||
{
|
||||
var _ = AbstractCallable._;
|
||||
|
||||
var dump = qsim.Get<ICallable>(typeof(Microsoft.Quantum.Extensions.Diagnostics.DumpMachine<>)) as GenericCallable;
|
||||
var dump = qsim.Get<ICallable>(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable;
|
||||
var trace = qsim.Get<IUnitary>(typeof(Circuits.Generics.Trace<>)) as GenericCallable;
|
||||
var gen3 = qsim.Get<IControllable>(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable;
|
||||
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче