diff --git a/AdvantageBenchmark/privateBuild/host.csproj b/AdvantageBenchmark/privateBuild/host.csproj
index 73723279d53..9eac18bfca4 100644
--- a/AdvantageBenchmark/privateBuild/host.csproj
+++ b/AdvantageBenchmark/privateBuild/host.csproj
@@ -8,4 +8,8 @@
false
+
+
+
+
diff --git a/Simulation.sln b/Simulation.sln
index 8b4957e793d..ef74245467b 100644
--- a/Simulation.sln
+++ b/Simulation.sln
@@ -83,6 +83,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProject
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}") = "Microsoft.Quantum.Simulators.Type1", "src\Simulation\Simulators.Type1\Microsoft.Quantum.Simulators.Type1.csproj", "{F995209F-FEE1-4083-ABD9-4998563E0070}"
+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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -575,6 +581,54 @@ Global
{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
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|x64.Build.0 = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|x64.Build.0 = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|x64.ActiveCfg = Release|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|x64.Build.0 = Release|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
+ {F995209F-FEE1-4083-ABD9-4998563E0070}.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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -614,6 +668,9 @@ Global
{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}
+ {F995209F-FEE1-4083-ABD9-4998563E0070} = {9008B252-2DF7-404B-B626-D4497BB70A05}
+ {EB6E3DBD-C884-4241-9BC4-8281191D1F53} = {9008B252-2DF7-404B-B626-D4497BB70A05}
+ {E1A463D7-2E23-4134-BE04-1EFF7A546813} = {9008B252-2DF7-404B-B626-D4497BB70A05}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821}
diff --git a/bootstrap.ps1 b/bootstrap.ps1
index 251698dff4f..2a74594cf2f 100644
--- a/bootstrap.ps1
+++ b/bootstrap.ps1
@@ -11,6 +11,10 @@ Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators.Core")
.\FindNuspecReferences.ps1
Pop-Location
+Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators.Type1")
+ .\FindNuspecReferences.ps1
+Pop-Location
+
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators.Type2")
.\FindNuspecReferences.ps1
Pop-Location
diff --git a/build/manifest.ps1 b/build/manifest.ps1
index fbe7f793736..f8cb1ec7c07 100644
--- a/build/manifest.ps1
+++ b/build/manifest.ps1
@@ -10,8 +10,12 @@
"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.Simulators.Type1",
+ "Microsoft.Quantum.Simulators.Type2",
"Microsoft.Quantum.Xunit"
);
Assemblies = @(
@@ -22,10 +26,13 @@
".\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.Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.Common.dll",
".\src\Simulation\Simulators.Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll",
".\src\Simulation\Simulators.Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.dll",
+ ".\src\Simulation\Simulators.Type1\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.Type1.dll",
".\src\Simulation\Simulators.Type2\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.Type2.dll",
".\src\Xunit\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Xunit.dll"
) | ForEach-Object { Get-Item (Join-Path $PSScriptRoot (Join-Path ".." $_)) };
diff --git a/build/pack.ps1 b/build/pack.ps1
index 65dc7d01a94..283085f64ca 100644
--- a/build/pack.ps1
+++ b/build/pack.ps1
@@ -66,8 +66,10 @@ Pack-Dotnet '../src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriv
Pack-Dotnet '../src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj'
Pack-Dotnet '../src/Simulation/QSharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj'
Pack-Dotnet '../src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj'
+Pack-Dotnet '../src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj'
Pack-Dotnet '../src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj'
Pack-One '../src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec'
+Pack-One '../src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.nuspec'
Pack-One '../src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec'
Pack-One '../src/Quantum.Development.Kit/Microsoft.Quantum.Development.Kit.nuspec'
Pack-One '../src/Xunit/Microsoft.Quantum.Xunit.csproj'
diff --git a/src/Simulation/Common/Simulators.Dev.props b/src/Simulation/Common/Simulators.Dev.props
index ee61a11c722..80151763c82 100644
--- a/src/Simulation/Common/Simulators.Dev.props
+++ b/src/Simulation/Common/Simulators.Dev.props
@@ -20,10 +20,7 @@
-
-
-
diff --git a/src/Simulation/Common/Simulators.Impl.props b/src/Simulation/Common/Simulators.Impl.props
new file mode 100644
index 00000000000..07f50298499
--- /dev/null
+++ b/src/Simulation/Common/Simulators.Impl.props
@@ -0,0 +1,53 @@
+
+
+
+
+ $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\))
+
+
+
+
+
+
+
+ netstandard2.1
+ false
+ false
+
+
+
+ 8.0
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ runtimes\win-x64\native\%(RecursiveDir)%(FileName)%(Extension)
+ PreserveNewest
+ false
+
+
+ runtimes\osx-x64\native\%(RecursiveDir)%(FileName)%(Extension)
+ PreserveNewest
+ false
+
+
+ runtimes\linux-x64\native\%(RecursiveDir)%(FileName)%(Extension)
+ PreserveNewest
+ false
+
+
+
+
diff --git a/src/Simulation/Common/Simulators.Test.props b/src/Simulation/Common/Simulators.Test.props
new file mode 100644
index 00000000000..6e2cf7b766f
--- /dev/null
+++ b/src/Simulation/Common/Simulators.Test.props
@@ -0,0 +1,34 @@
+
+
+
+
+ $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\))
+
+
+
+
+
+
+
+ netcoreapp3.1
+ false
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/Common/Simulators.Type2.Dev.props b/src/Simulation/Common/Simulators.Type2.Dev.props
deleted file mode 100644
index ce27923c3fd..00000000000
--- a/src/Simulation/Common/Simulators.Type2.Dev.props
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
- bin\$(BuildConfiguration)\$(TargetFramework)\$(AssemblyName).xml
- $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\))
- $([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/Native/build/))
-
-
-
- $([MSBuild]::NormalizePath($(NativeBuildPath)/libMicrosoft.Quantum.Simulator.Runtime.dylib))
- $([MSBuild]::NormalizePath($(NativeBuildPath)/libMicrosoft.Quantum.Simulator.Runtime.so))
- $([MSBuild]::NormalizePath($(NativeBuildPath)/Release/Microsoft.Quantum.Simulator.Runtime.dll))
- $([MSBuild]::NormalizePath($(NativeBuildPath)/Debug/Microsoft.Quantum.Simulator.Runtime.dll))
- $(QsimDllMac)
- $(QsimDllLinux)
- $(QsimDllWindowsRelease)
- $(QsimDllWindowsDebug)
-
-
-
-
-
-
-
-
-
-
-
- Microsoft.Quantum.Simulator.Runtime.dll
- PreserveNewest
- false
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Simulation/Core/Properties/AssemblyInfo.cs b/src/Simulation/Core/Properties/AssemblyInfo.cs
index 4ecfaf27ed6..c2a5d12dced 100644
--- a/src/Simulation/Core/Properties/AssemblyInfo.cs
+++ b/src/Simulation/Core/Properties/AssemblyInfo.cs
@@ -7,4 +7,3 @@
// Allow the test assembly to use our internal methods
[assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators" + SigningConstants.PUBLIC_KEY)]
-[assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators.Type2" + SigningConstants.PUBLIC_KEY)]
diff --git a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj
index ba121246d35..9b472054974 100644
--- a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj
+++ b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj
@@ -13,6 +13,7 @@
+
diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj
index 472d183c70a..d8c9fcea638 100644
--- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj
+++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj
@@ -1,47 +1,10 @@
-
-
-
- netstandard2.1
- true
- false
- false
-
-
-
- Microsoft
Core support for the Q# programming language.
- See: https://docs.microsoft.com/en-us/quantum/relnotes/
- MIT
- https://github.com/microsoft/qsharp-runtime
- qdk-nuget-icon.png
- Quantum Q# Qsharp
- true
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs b/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..109c9a91f80
--- /dev/null
+++ b/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs
@@ -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)]
\ No newline at end of file
diff --git a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj
index e8f9263ae20..8226d6b2192 100644
--- a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj
+++ b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj
@@ -1,23 +1,9 @@
-
-
-
-
-
- netstandard2.1
- false
- false
-
-
-
- 8.0
- enable
-
+
-
@@ -25,29 +11,8 @@
-
-
-
-
-
-
-
-
-
- runtimes\win-x64\native\%(RecursiveDir)%(FileName)%(Extension)
- PreserveNewest
- false
-
-
- runtimes\osx-x64\native\%(RecursiveDir)%(FileName)%(Extension)
- PreserveNewest
- false
-
-
- runtimes\linux-x64\native\%(RecursiveDir)%(FileName)%(Extension)
- PreserveNewest
- false
-
+
+
diff --git a/src/Simulation/Simulators.Tests/App.config b/src/Simulation/Simulators.Tests/App.config
index 94ce1a2b94f..b65f2762470 100644
--- a/src/Simulation/Simulators.Tests/App.config
+++ b/src/Simulation/Simulators.Tests/App.config
@@ -3,4 +3,7 @@
-
+
+
+
+
diff --git a/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs
index 477571f7024..e35e7f207a2 100644
--- a/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs
+++ b/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs
@@ -27,13 +27,18 @@ public static void RunWithMultipleSimulators(Action test)
foreach (var s in simulators)
{
- InitSimulator(s);
+ try
+ {
+ InitSimulator(s);
- test(s);
-
- if (s is IDisposable sim)
+ test(s);
+ }
+ finally
{
- sim.Dispose();
+ if (s is IDisposable sim)
+ {
+ sim.Dispose();
+ }
}
}
}
diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj
index 6fa960aef8f..9a97d67614a 100644
--- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj
+++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj
@@ -1,15 +1,6 @@
-
-
-
-
-
- netcoreapp3.1
- false
- false
- false
-
+
@@ -18,8 +9,7 @@
-
-
+
false
@@ -28,16 +18,6 @@
-
-
-
-
-
-
-
-
-
-
<_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\
diff --git a/src/Simulation/Simulators.Type1.Tests/App.config b/src/Simulation/Simulators.Type1.Tests/App.config
new file mode 100644
index 00000000000..b65f2762470
--- /dev/null
+++ b/src/Simulation/Simulators.Type1.Tests/App.config
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs
new file mode 100644
index 00000000000..cce2bfaa09a
--- /dev/null
+++ b/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs
@@ -0,0 +1,39 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using System;
+using Microsoft.Quantum.Simulation.Common;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators.Tests
+{
+ static partial class OperationsTestHelper
+ {
+ private static void InitSimulator(SimulatorBase sim)
+ {
+ sim.InitBuiltinOperations(typeof(OperationsTestHelper));
+ }
+
+ public static void RunWithMultipleSimulators(Action test)
+ {
+ var simulators = new SimulatorBase[] { new QuantumSimulator() };
+
+ foreach (var s in simulators)
+ {
+ try
+ {
+ InitSimulator(s);
+
+ test(s);
+ }
+ finally
+ {
+ if (s is IDisposable sim)
+ {
+ sim.Dispose();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj b/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj
new file mode 100644
index 00000000000..5c0863c42af
--- /dev/null
+++ b/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/Simulators.Type1/.gitignore b/src/Simulation/Simulators.Type1/.gitignore
new file mode 100644
index 00000000000..1624c7f7e14
--- /dev/null
+++ b/src/Simulation/Simulators.Type1/.gitignore
@@ -0,0 +1 @@
+Microsoft.Quantum.Simulators.Type1.nuspec
\ No newline at end of file
diff --git a/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1
new file mode 100644
index 00000000000..9f0fdbaa3d0
--- /dev/null
+++ b/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1
@@ -0,0 +1,101 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+########################################
+# .Description
+# When creating a package with dotnet pack, nuget changes every ProjectReference to be itself
+# a PackageReference (without checking if that project has a corresponding package).
+# This is problematic because we currently don't want to create a package for every dll.
+#
+# On the other hand, when creating a package using nuget pack, nuget does not
+# identify PackageReferences defined in the csproj, so all the dependencies
+# are not listed and the package doesn't work.
+#
+# We don't want to hardcode the list of dependencies on the .nuspec, as they can
+# quickly become out-of-sync.
+# This script will find the PackageReferences recursively on the simulation projects and add them
+# to the nuspec, so we can then create the package using nuget pack with the corresponding
+# dependencies listed.
+#
+# nuget is tracking this problem at: https://github.com/NuGet/Home/issues/4491
+########################################
+
+$target = Join-Path $PSScriptRoot "Microsoft.Quantum.Simulators.Type1.nuspec"
+
+if (Test-Path $target) {
+ Write-Host "$target exists. Skipping generating new one."
+ exit
+ }
+
+
+# Start with the nuspec template
+$nuspec = [xml](Get-Content (Join-Path $PSScriptRoot "Microsoft.Quantum.Simulators.Type1.nuspec.template"))
+$dep = $nuspec.CreateElement('dependencies', $nuspec.package.metadata.NamespaceURI)
+
+function Add-PackageReferenceIfNew($ref) {
+ # Identify package's id either from "Include" or "Update" attribute:
+ $id = $ref.Include
+ $version = $ref.Version
+
+ if ($id -eq $null -or $id -eq "") {
+ $id = $ref.Update
+ }
+ if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj')) {
+ $id = [System.IO.Path]::GetFileNameWithoutExtension($id)
+ }
+
+ if ("$version" -eq "") {
+ $version = '$version$'
+ }
+
+ # Check if package already added as dependency, only add if new:
+ $added = $dep.dependency | Where { $_.id -eq $id }
+ if (!$added) {
+ Write-Host "Adding $id (version: $version)"
+ $onedependency = $dep.AppendChild($nuspec.CreateElement('dependency', $nuspec.package.metadata.NamespaceURI))
+ $onedependency.SetAttribute('id', $id)
+ $onedependency.SetAttribute('version', $version)
+ }
+}
+
+# Recursively find PackageReferences on all ProjectReferences:
+function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) {
+ Write-Host "`nFinding dependencies for $PathToCsproj"
+ $csproj = [xml](Get-Content $PathToCsproj)
+
+ # Find all PackageReferences nodes:
+ $packageDependency = $csproj.Project.ItemGroup.PackageReference | Where-Object { $null -ne $_ }
+ $packageDependency | ForEach-Object {
+ $id = $_.Include
+ Write-Host "Detected package dependencies: $id"
+ }
+
+ $packageDependency | ForEach-Object {
+ Add-PackageReferenceIfNew $_
+ }
+
+ $projectDependency = $csproj.Project.ItemGroup.ProjectReference | Where-Object { $null -ne $_ }
+ $projectDependency | ForEach-Object {
+ $id = $_.Include
+ Write-Host "Detected project dependencies: $id"
+ }
+
+ # Assume there is a package for project references that are not tagged as to be included in the simulator package:
+ $projectDependency | Where-Object {$_.IncludeInSimulatorPackage -ne 'true' -and $_.IsQscReference -ne 'true'} | ForEach-Object {
+ Add-PackageReferenceIfNew $_
+ }
+
+ # Recursively check on project references if they are private:
+ $projectDependency | Where-Object {$_.IncludeInSimulatorPackage -eq 'true' -and $_.IsQscReference -ne 'true'} | ForEach-Object {
+ $id = $_.Include
+ Write-Host "Recurring for $id"
+ Add-NuGetDependencyFromCsprojToNuspec $_.Include
+ }
+}
+
+# Find all dependencies packaged as part of Microsoft.Quantum.Simulators.Type1
+Add-NuGetDependencyFromCsprojToNuspec "Microsoft.Quantum.Simulators.Type1.csproj"
+
+# Save into .nuspec file:
+$nuspec.package.metadata.AppendChild($dep)
+$nuspec.Save($target)
diff --git a/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj
new file mode 100644
index 00000000000..d9cec682ccc
--- /dev/null
+++ b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.nuspec.template b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.nuspec.template
new file mode 100644
index 00000000000..1d7a7445bfc
--- /dev/null
+++ b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.nuspec.template
@@ -0,0 +1,31 @@
+
+
+
+ Microsoft.Quantum.Simulators.Type1
+ $version$
+ $title$
+ Microsoft
+ QuantumEngineering, Microsoft
+ MIT
+ https://docs.microsoft.com/en-us/quantum
+ images\qdk-nuget-icon.png
+ false
+ Type1 simulators of quantum computers for the Q# programming language.
+ See: https://docs.microsoft.com/en-us/quantum/relnotes/
+ © Microsoft Corporation. All rights reserved.
+ Quantum Q# Qsharp
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs b/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..ed47130ca02
--- /dev/null
+++ b/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs
@@ -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 test assembly to use our internal methods
+[assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators.Type1" + SigningConstants.PUBLIC_KEY)]
\ No newline at end of file
diff --git a/src/Simulation/Simulators.Type2.Tests/App.config b/src/Simulation/Simulators.Type2.Tests/App.config
index 94ce1a2b94f..b65f2762470 100644
--- a/src/Simulation/Simulators.Type2.Tests/App.config
+++ b/src/Simulation/Simulators.Type2.Tests/App.config
@@ -3,4 +3,7 @@
-
+
+
+
+
diff --git a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs
index d6abcc6ed50..b89d8ba181f 100644
--- a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs
+++ b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs
@@ -20,13 +20,18 @@ public static void RunWithMultipleSimulators(Action test)
foreach (var s in simulators)
{
- InitSimulator(s);
-
- test(s);
+ try
+ {
+ InitSimulator(s);
- if (s is IDisposable sim)
+ test(s);
+ }
+ finally
{
- sim.Dispose();
+ if (s is IDisposable sim)
+ {
+ sim.Dispose();
+ }
}
}
}
diff --git a/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj
index adf546c4aab..90dc3a3bc22 100644
--- a/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj
+++ b/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj
@@ -1,23 +1,9 @@
-
-
-
-
-
- netcoreapp3.1
- false
- false
- false
-
-
-
-
-
-
+
-
+
@@ -31,27 +17,6 @@
-
-
-
-
-
-
-
-
- <_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\
- <_TargetedExeDir>$(MSBuildThisFileDirectory)TestProjects\TargetedExe\built\
-
-
- <_ExeFiles Include="$(_ExeDir)*" />
- <_TargetedExeFiles Include="$(_TargetedExeDir)*" />
-
-
-
-
-
-
-
diff --git a/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1
index 3c86d876ef3..80ec6dd6238 100644
--- a/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1
+++ b/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1
@@ -1,7 +1,8 @@
-# Copyright (c) Microsoft Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
########################################
+# .Description
# When creating a package with dotnet pack, nuget changes every ProjectReference to be itself
# a PackageReference (without checking if that project has a corresponding package).
# This is problematic because we currently don't want to create a package for every dll.
@@ -31,8 +32,7 @@ if (Test-Path $target) {
$nuspec = [xml](Get-Content (Join-Path $PSScriptRoot "Microsoft.Quantum.Simulators.Type2.nuspec.template"))
$dep = $nuspec.CreateElement('dependencies', $nuspec.package.metadata.NamespaceURI)
-function Add-PackageReferenceIfNew($ref)
-{
+function Add-PackageReferenceIfNew($ref) {
# Identify package's id either from "Include" or "Update" attribute:
$id = $ref.Include
$version = $ref.Version
@@ -40,8 +40,7 @@ function Add-PackageReferenceIfNew($ref)
if ($id -eq $null -or $id -eq "") {
$id = $ref.Update
}
- if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj'))
- {
+ if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj')) {
$id = [System.IO.Path]::GetFileNameWithoutExtension($id)
}
@@ -60,8 +59,7 @@ function Add-PackageReferenceIfNew($ref)
}
# Recursively find PackageReferences on all ProjectReferences:
-function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj)
-{
+function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) {
Write-Host "`nFinding dependencies for $PathToCsproj"
$csproj = [xml](Get-Content $PathToCsproj)
diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj
index a10fef46f36..3fb63e0fb7d 100644
--- a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj
+++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj
@@ -1,42 +1,9 @@
-
-
-
-
-
- netstandard2.1
-
-
-
- 8.0
- enable
-
-
-
-
-
-
-
-
-
+
-
- runtimes\win-x64\native\%(RecursiveDir)%(FileName)%(Extension)
- PreserveNewest
- false
-
-
- runtimes\osx-x64\native\%(RecursiveDir)%(FileName)%(Extension)
- PreserveNewest
- false
-
-
- runtimes\linux-x64\native\%(RecursiveDir)%(FileName)%(Extension)
- PreserveNewest
- false
-
+
diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template
index 0259a979f74..aa78d359d19 100644
--- a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template
+++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template
@@ -1,7 +1,7 @@
- Microsoft.Quantum.Simulators
+ Microsoft.Quantum.Simulators.Type2
$version$
$title$
Microsoft
diff --git a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs
index 5f75f95fb02..3a3a2fb9899 100644
--- a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs
+++ b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs
@@ -2,7 +2,7 @@
// Licensed under the MIT License.
namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Circuits {
- operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
Exp([PauliX, PauliX], theta * 2.0, [qubit0, qubit1]);
}
}
\ No newline at end of file
diff --git a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs
index 9315f86ef86..78484a19d3d 100644
--- a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs
+++ b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs
@@ -2,7 +2,7 @@
// Licensed under the MIT License.
namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Circuits {
- operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
Exp([PauliY, PauliY], theta * 2.0, [qubit0, qubit1]);
}
}
\ No newline at end of file
diff --git a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs
index c6f7a753326..797f7986f71 100644
--- a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs
+++ b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs
@@ -2,7 +2,7 @@
// Licensed under the MIT License.
namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Circuits {
- operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
Exp([PauliZ, PauliZ], theta * 2.0, [qubit0, qubit1]);
}
}
\ No newline at end of file
diff --git a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs
index cd6b69c4de8..c86ca5d553a 100644
--- a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs
+++ b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs
@@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Implementati
{
public partial class QCTraceSimulatorImpl
{
- public class QCTracesimulatorImplCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness
+ internal class QCTracesimulatorImplCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness
{
public QCTracesimulatorImplCheckQubitUniqueness(QCTraceSimulatorImpl m) : base(m)
{
@@ -28,7 +28,7 @@ public QCTracesimulatorImplCheckQubitUniqueness(QCTraceSimulatorImpl m) : base(m
};
}
- public class QCTracesimulatorImplRotationAngleValidation : Intrinsic.RotationAngleValidation
+ internal class QCTracesimulatorImplRotationAngleValidation : Intrinsic.RotationAngleValidation
{
public QCTracesimulatorImplRotationAngleValidation(QCTraceSimulatorImpl m) : base(m)
{
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs
new file mode 100644
index 00000000000..835f6fa80cb
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyControlledX : Intrinsic.ApplyControlledX
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCX")]
+ private static extern void MCX(uint id, uint count, uint[] ctrls, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+ public QSimApplyControlledX(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func<(Qubit, Qubit), QVoid> __Body__ => (args) =>
+ {
+ var (control, target) = args;
+
+ Simulator.CheckQubits(new QArray(new Qubit[]{ control, target }));
+
+ MCX(Simulator.Id, 1, new uint[]{(uint)control.Id}, (uint)target.Id);
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs
new file mode 100644
index 00000000000..5bf1b755cab
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyControlledZ : Intrinsic.ApplyControlledZ
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCZ")]
+ private static extern void MCZ(uint id, uint count, uint[] ctrls, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+ public QSimApplyControlledZ(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func<(Qubit, Qubit), QVoid> __Body__ => (args) =>
+ {
+ var (control, target) = args;
+
+ Simulator.CheckQubits(new QArray(new Qubit[]{ control, target }));
+
+ MCZ(Simulator.Id, 1, new uint[]{(uint)control.Id}, (uint)target.Id);
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs
new file mode 100644
index 00000000000..de3859e9f69
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs
@@ -0,0 +1,35 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledH : Intrinsic.ApplyUncontrolledH
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "H")]
+ private static extern void H(uint id, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+
+ public QSimApplyUncontrolledH(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func __Body__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ H(Simulator.Id, (uint)q1.Id);
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs
new file mode 100644
index 00000000000..067f1294654
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs
@@ -0,0 +1,42 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledRx : Intrinsic.ApplyUncontrolledRx
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")]
+ private static extern void R(uint id, Pauli basis, double angle, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+ public QSimApplyUncontrolledRx(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func<(double, Qubit), QVoid> __Body__ => (args) =>
+ {
+ var (angle, target) = args;
+ Simulator.CheckQubit(target, nameof(target));
+ CheckAngle(angle);
+ R(Simulator.Id, Pauli.PauliX, angle, (uint)target.Id);
+ return QVoid.Instance;
+ };
+
+ public override Func<(double, Qubit), QVoid> __AdjointBody__ => (_args) =>
+ {
+ var (angle, q1) = _args;
+
+ return this.__Body__.Invoke((-angle, q1));
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs
new file mode 100644
index 00000000000..25e79b98468
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs
@@ -0,0 +1,42 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledRy : Intrinsic.ApplyUncontrolledRy
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")]
+ private static extern void R(uint id, Pauli basis, double angle, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+ public QSimApplyUncontrolledRy(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func<(double, Qubit), QVoid> __Body__ => (args) =>
+ {
+ var (angle, target) = args;
+ Simulator.CheckQubit(target, nameof(target));
+ CheckAngle(angle);
+ R(Simulator.Id, Pauli.PauliY, angle, (uint)target.Id);
+ return QVoid.Instance;
+ };
+
+ public override Func<(double, Qubit), QVoid> __AdjointBody__ => (_args) =>
+ {
+ var (angle, q1) = _args;
+
+ return this.__Body__.Invoke((-angle, q1));
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs
new file mode 100644
index 00000000000..4b1f3196daf
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs
@@ -0,0 +1,42 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledRz : Intrinsic.ApplyUncontrolledRz
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")]
+ private static extern void R(uint id, Pauli basis, double angle, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+ public QSimApplyUncontrolledRz(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func<(double, Qubit), QVoid> __Body__ => (args) =>
+ {
+ var (angle, target) = args;
+ Simulator.CheckQubit(target, nameof(target));
+ CheckAngle(angle);
+ R(Simulator.Id, Pauli.PauliZ, angle, (uint)target.Id);
+ return QVoid.Instance;
+ };
+
+ public override Func<(double, Qubit), QVoid> __AdjointBody__ => (_args) =>
+ {
+ var (angle, q1) = _args;
+
+ return this.__Body__.Invoke((-angle, q1));
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs
new file mode 100644
index 00000000000..19c92deb736
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs
@@ -0,0 +1,47 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledS : Intrinsic.ApplyUncontrolledS
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "S")]
+ private static extern void S(uint id, uint qubit);
+
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AdjS")]
+ private static extern void AdjS(uint id, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+
+ public QSimApplyUncontrolledS(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func __Body__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ S(Simulator.Id, (uint)q1.Id);
+
+ return QVoid.Instance;
+ };
+
+ public override Func __AdjointBody__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ AdjS(Simulator.Id, (uint)q1.Id);
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs
new file mode 100644
index 00000000000..94d626d53bb
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs
@@ -0,0 +1,45 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledT : Intrinsic.ApplyUncontrolledT
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "T")]
+ private static extern void T(uint id, uint qubit);
+
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AdjT")]
+ private static extern void AdjT(uint id, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+
+ public QSimApplyUncontrolledT(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func __Body__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ T(Simulator.Id, (uint)q1.Id);
+ return QVoid.Instance;
+ };
+
+ public override Func __AdjointBody__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ AdjT(this.Simulator.Id, (uint)q1.Id);
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs
new file mode 100644
index 00000000000..e2f9efa7347
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs
@@ -0,0 +1,35 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledX : Intrinsic.ApplyUncontrolledX
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "X")]
+ private static extern void X(uint id, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+
+ public QSimApplyUncontrolledX(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func __Body__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ X(Simulator.Id, (uint)q1.Id);
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs
new file mode 100644
index 00000000000..8aa4c4b641e
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs
@@ -0,0 +1,35 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledY : Intrinsic.ApplyUncontrolledY
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Y")]
+ private static extern void Y(uint id, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+
+ public QSimApplyUncontrolledY(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func __Body__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ Y(Simulator.Id, (uint)q1.Id);
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs
new file mode 100644
index 00000000000..1dc626a959b
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs
@@ -0,0 +1,35 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ internal class QSimApplyUncontrolledZ : Intrinsic.ApplyUncontrolledZ
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Z")]
+ private static extern void Z(uint id, uint qubit);
+
+ private QuantumSimulator Simulator { get; }
+
+
+ public QSimApplyUncontrolledZ(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func __Body__ => (q1) =>
+ {
+ Simulator.CheckQubit(q1);
+
+ Z(Simulator.Id, (uint)q1.Id);
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/Simulators/QuantumSimulator/Checks.cs b/src/Simulation/Simulators/QuantumSimulator/Checks.cs
index 544c18ad998..7fef67d5700 100644
--- a/src/Simulation/Simulators/QuantumSimulator/Checks.cs
+++ b/src/Simulation/Simulators/QuantumSimulator/Checks.cs
@@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators
{
public partial class QuantumSimulator
{
- public class QSimCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness
+ internal class QSimCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness
{
private QuantumSimulator Simulator { get; }
public QSimCheckQubitUniqueness(QuantumSimulator m) : base(m)
@@ -31,7 +31,7 @@ public QSimCheckQubitUniqueness(QuantumSimulator m) : base(m)
};
}
- public class QSimRotationAngleValidation : Intrinsic.RotationAngleValidation
+ internal class QSimRotationAngleValidation : Intrinsic.RotationAngleValidation
{
public QSimRotationAngleValidation(QuantumSimulator m) : base(m)
{
diff --git a/src/Simulation/Simulators/QuantumSimulator/Extensions.cs b/src/Simulation/Simulators/QuantumSimulator/Extensions.cs
index d2d098812d0..f3fda609b3f 100644
--- a/src/Simulation/Simulators/QuantumSimulator/Extensions.cs
+++ b/src/Simulation/Simulators/QuantumSimulator/Extensions.cs
@@ -39,8 +39,12 @@ public static void InitBuiltinOperations(this AbstractFactory factory, Typ
InitBuiltinOperations(factory, t.BaseType);
+ var overrideTypes = t.GetNestedTypes(
+ System.Reflection.BindingFlags.Public |
+ System.Reflection.BindingFlags.NonPublic);
+
var ops =
- from op in t.GetNestedTypes()
+ from op in overrideTypes
where op.IsSubclassOf(typeof(T))
select op;
diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs
index a2822981eb4..16672d025b0 100644
--- a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs
+++ b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs
@@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators
public partial class QuantumSimulator
{
- public class QSimIsingXX : Intrinsic.IsingXX
+ internal class QSimIsingXX : Intrinsic.IsingXX
{
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Exp")]
private static extern void Exp(uint id, uint n, Pauli[] paulis, double angle, uint[] ids);
diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs
index a73ea00ff9f..1a22e5a1a62 100644
--- a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs
+++ b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs
@@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators
public partial class QuantumSimulator
{
- public class QSimIsingYY : Intrinsic.IsingYY
+ internal class QSimIsingYY : Intrinsic.IsingYY
{
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Exp")]
private static extern void Exp(uint id, uint n, Pauli[] paulis, double angle, uint[] ids);
diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs
index 20bb062470a..faf9df00312 100644
--- a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs
+++ b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs
@@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators
public partial class QuantumSimulator
{
- public class QSimIsingZZ : Intrinsic.IsingZZ
+ internal class QSimIsingZZ : Intrinsic.IsingZZ
{
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Exp")]
private static extern void Exp(uint id, uint n, Pauli[] paulis, double angle, uint[] ids);
diff --git a/src/Simulation/Simulators/QuantumSimulator/Reset.cs b/src/Simulation/Simulators/QuantumSimulator/Reset.cs
new file mode 100644
index 00000000000..9f6d2d6501e
--- /dev/null
+++ b/src/Simulation/Simulators/QuantumSimulator/Reset.cs
@@ -0,0 +1,43 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Quantum.Simulation.Core;
+
+namespace Microsoft.Quantum.Simulation.Simulators
+{
+ public partial class QuantumSimulator
+ {
+ public class QSimReset : Intrinsic.Reset
+ {
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "X")]
+ private static extern void X(uint id, uint qubit);
+
+ [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "M")]
+ private static extern uint M(uint id, uint q);
+
+ private QuantumSimulator Simulator { get; }
+
+
+ public QSimReset(QuantumSimulator m) : base(m)
+ {
+ this.Simulator = m;
+ }
+
+ public override Func __Body__ => (q1) =>
+ {
+ // The native simulator doesn't have a reset operation, so simulate
+ // it via an M follow by a conditional X.
+ Simulator.CheckQubit(q1);
+ var res = M(Simulator.Id, (uint)q1.Id);
+ if (res == 1)
+ {
+ X(Simulator.Id, (uint)q1.Id);
+ }
+
+ return QVoid.Instance;
+ };
+ }
+ }
+}
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs
new file mode 100644
index 00000000000..4bf60fd83dd
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs
@@ -0,0 +1,39 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the controlled-X (or CNOT) gate to a pair of qubits. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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
+ /// CNOT(control, target);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX")
+ internal operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj {
+ CNOT(control, target);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs
new file mode 100644
index 00000000000..70cb2a6d068
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the controlled-Z (CZ) gate to a pair of qubits. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// $$
+ /// \begin{align}
+ /// 1 & 0 & 0 & 0 \\\\
+ /// 0 & 1 & 0 & 0 \\\\
+ /// 0 & 0 & 1 & 0 \\\\
+ /// 0 & 0 & 0 & -1
+ /// \end{align},
+ /// $$
+ /// where rows and columns are organized as in the quantum concepts guide.
+ ///
+ /// # Input
+ /// ## control
+ /// Control qubit for the CZ gate.
+ /// ## target
+ /// Target qubit for the CZ gate.
+ ///
+ /// # Remarks
+ /// Equivalent to:
+ /// ```qsharp
+ /// Controlled Z([control], target);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ")
+ internal operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj {
+ Controlled Z([control], target);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs
new file mode 100644
index 00000000000..74a4e5f61fa
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs
@@ -0,0 +1,28 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Hadamard transformation to a single qubit. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledH")
+ internal operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj {
+ H(qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs
new file mode 100644
index 00000000000..8db8b3733a1
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $x$-axis by a given angle. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRx")
+ internal operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj {
+ Rx(theta, qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs
new file mode 100644
index 00000000000..bd72cde1e7e
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $y$-axis by a given angle. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRy")
+ internal operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj {
+ Ry(theta, qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs
new file mode 100644
index 00000000000..5c864aae74f
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $z$-axis by a given angle. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRz")
+ internal operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj {
+ Rz(theta, qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs
new file mode 100644
index 00000000000..1b64c5e7839
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs
@@ -0,0 +1,27 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the π/4 phase gate to a single qubit. Note that the Controlled functor
+ /// is not supported.
+ ///
+ /// # Description
+ /// \begin{align}
+ /// S \mathrel{:=}
+ /// \begin{bmatrix}
+ /// 1 & 0 \\\\
+ /// 0 & i
+ /// \end{bmatrix}.
+ /// \end{align}
+ ///
+ /// # Input
+ /// ## qubit
+ /// Qubit to which the gate should be applied.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS")
+ internal operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj {
+ S(qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs
new file mode 100644
index 00000000000..60cf1ecd7b8
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs
@@ -0,0 +1,27 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the π/8 gate to a single qubit. Note that the Controlled functor is
+ /// not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT")
+ internal operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj {
+ T(qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs
new file mode 100644
index 00000000000..08a566bc840
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs
@@ -0,0 +1,26 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $X$ gate. Note that the Controlled functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledX")
+ internal operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj {
+ X(qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs
new file mode 100644
index 00000000000..bee6d1fb7b3
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs
@@ -0,0 +1,26 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $Y$ gate. Note that the Controlled functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledY")
+ internal operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj {
+ Y(qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs
new file mode 100644
index 00000000000..ffb10e7e364
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs
@@ -0,0 +1,26 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $Z$ gate. Note that the Controlled functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledZ")
+ internal operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj {
+ Z(qubit);
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs b/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs
new file mode 100644
index 00000000000..5b1601c799b
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs
@@ -0,0 +1,39 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # 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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.CCNOT")
+ operation CCNOT (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ // [Page 15 of arXiv:1206.0758v3](https://arxiv.org/pdf/1206.0758v3.pdf#page=15)
+ within {
+ H(target);
+ }
+ apply {
+ Controlled Z([control1, control2], target);
+ }
+ }
+ controlled (ctls, ...) {
+ Controlled X (ctls + [control1, control2], target);
+ }
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs
similarity index 95%
rename from src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs
rename to src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs
index 229edf4c658..e447f0fc760 100644
--- a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs
+++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs
@@ -31,7 +31,7 @@ namespace Microsoft.Quantum.Intrinsic {
/// Register to apply the given rotation to.
@EnableTestingViaName("Test.TargetDefinitions.ExpFrac")
operation ExpFrac (paulis : Pauli[], numerator : Int, power : Int, qubits : Qubit[]) : Unit is Adj + Ctl {
- body(...) {
+ body (...) {
CheckQubitUniqueness(qubits);
if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'target' must have the same length"; }
@@ -44,7 +44,7 @@ namespace Microsoft.Quantum.Intrinsic {
let (kModPositive, n) = ReducedDyadicFractionPeriodic(numerator, power); // k is odd, in the range [1,2*2^n-1] or (k,n) are both 0
let numeratorD = PI() * IntAsDouble(kModPositive);
let theta = numeratorD * PowD(2.0, IntAsDouble(-n));
- ExpNoIdUtil(newPaulis, theta, newQubits, RFrac(_, numerator, power, _));
+ ExpUtil(newPaulis, theta, newQubits, RFrac(_, numerator, power, _));
}
else {
ApplyGlobalPhaseFracWithR1Frac(numerator, power);
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs
similarity index 93%
rename from src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs
rename to src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs
index 5a9fee5ab2e..5f6c7b8ad60 100644
--- a/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs
+++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs
@@ -25,14 +25,14 @@ namespace Microsoft.Quantum.Intrinsic {
/// Register to apply the given rotation to.
@EnableTestingViaName("Test.TargetDefinitions.Exp")
operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit is Adj + Ctl {
- body(...) {
+ body (...) {
CheckQubitUniqueness(qubits);
RotationAngleValidation(theta);
if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'qubits' must have the same length"; }
let (newPaulis, newQubits) = RemovePauliI(paulis, qubits);
if (Length(newPaulis) != 0) {
- ExpNoIdUtil(newPaulis, theta , newQubits, R(_, -2.0 * theta, _));
+ ExpUtil(newPaulis, theta , newQubits, R(_, -2.0 * theta, _));
}
else {
ApplyGlobalPhase(theta);
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs
new file mode 100644
index 00000000000..5131ac27048
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs
@@ -0,0 +1,31 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ @EnableTestingViaName("Test.TargetDefinitions.ExpUtil")
+ internal operation ExpUtil (paulis : Pauli[], theta : Double, qubits : Qubit[], rotation : ((Pauli, Qubit) => Unit is Adj + Ctl)) : Unit is Ctl {
+ if (Length(paulis) != Length(qubits)) { fail "Arrays 'paulis' and 'qubits' must have the same length"; }
+ if (Length(paulis) == 1) {
+ rotation(paulis[0], qubits[0]);
+ }
+ else { // Length(paulis) > 1
+ within {
+ for (i in 0 .. Length(paulis) - 1) {
+ MapPauli(qubits[i], PauliZ, paulis[i]);
+ }
+ }
+ apply {
+ within {
+ SpreadZ(qubits[0], qubits[ 1 .. Length(qubits) - 1]);
+ }
+ apply {
+ rotation(PauliZ, qubits[0]);
+ }
+ }
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs
new file mode 100644
index 00000000000..b1bbc9d0dc4
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs
@@ -0,0 +1,46 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ @EnableTestingViaName("Test.TargetDefinitions.ExpUtil")
+ internal operation ExpUtil (paulis : Pauli[], theta : Double, qubits : Qubit[], rotation : ((Pauli, Qubit) => Unit is Adj + Ctl)) : Unit is Ctl {
+ if (Length(paulis) != Length(qubits)) { fail "Arrays 'paulis' and 'qubits' must have the same length"; }
+ if (Length(paulis) == 1) {
+ rotation(paulis[0], qubits[0]);
+ }
+ elif (Length(paulis) == 2) {
+ within {
+ MapPauli(qubits[1], paulis[0], paulis[1]);
+ }
+ apply {
+ if (paulis[0] == PauliX) {
+ IsingXX(theta / 2.0, qubits[0], qubits[1]);
+ } elif (paulis[0] == PauliY) {
+ IsingYY(theta / 2.0, qubits[0], qubits[1]);
+ } elif (paulis[0] == PauliZ) {
+ IsingZZ(theta / 2.0, qubits[0], qubits[1]);
+ } else {
+ fail "Type2 decompositions do not support PauliI as an input to Exp";
+ }
+ }
+ }
+ else { // Length(paulis) > 2
+ within {
+ for (i in 0 .. Length(paulis) - 1) {
+ MapPauli(qubits[i], PauliZ, paulis[i]);
+ }
+ }
+ apply {
+ within {
+ SpreadZ(qubits[1], qubits[2 .. Length(qubits) - 1]);
+ }
+ apply {
+ IsingZZ(theta / 2.0, qubits[0], qubits[1]);
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs
new file mode 100644
index 00000000000..dd07dd4eced
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs
@@ -0,0 +1,48 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Hadamard transformation to a single qubit.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.H")
+ operation H (qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledH(qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledH(qubit);
+ }
+ elif (Length(ctls) == 1) {
+ within{
+ S(qubit);
+ H(qubit);
+ T(qubit);
+ } apply {
+ CNOT(ctls[0], qubit);
+ }
+ }
+ else {
+ ApplyWithLessControlsA(Controlled H, (ctls, qubit));
+ }
+ }
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs b/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs
index a527a86a634..2c4b93c4ad1 100644
--- a/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs
+++ b/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs
@@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic {
/// ## qubit1
/// The second qubit input to the gate.
@EnableTestingViaName("Test.TargetDefinitions.IsingXX")
- operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
Exp([PauliX, PauliX], theta * 2.0, [qubit0, qubit1]);
}
}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs b/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs
index fe33783729a..51d3a76c929 100644
--- a/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs
+++ b/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs
@@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic {
/// ## qubit1
/// The second qubit input to the gate.
@EnableTestingViaName("Test.TargetDefinitions.IsingYY")
- operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
Exp([PauliY, PauliY], theta * 2.0, [qubit0, qubit1]);
}
}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs b/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs
index 3534019b726..16649bcffd6 100644
--- a/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs
+++ b/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs
@@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic {
/// ## qubit1
/// The second qubit input to the gate.
@EnableTestingViaName("Test.TargetDefinitions.IsingZZ")
- operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
Exp([PauliZ, PauliZ], theta * 2.0, [qubit0, qubit1]);
}
}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs
new file mode 100644
index 00000000000..d853dc9e8e5
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs
@@ -0,0 +1,31 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Measurement {
+ open Microsoft.Quantum.Intrinsic;
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # 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.
+ @EnableTestingViaName("Test.TargetDefinitions.MResetX")
+ operation MResetX (target : Qubit) : Result {
+ MapPauli(target, PauliZ, PauliX);
+ let result = M(target);
+ Reset(target);
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs
new file mode 100644
index 00000000000..1bb586cfb8e
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs
@@ -0,0 +1,31 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Measurement {
+ open Microsoft.Quantum.Intrinsic;
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # 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.
+ @EnableTestingViaName("Test.TargetDefinitions.MResetY")
+ operation MResetY (target : Qubit) : Result {
+ MapPauli(target, PauliZ, PauliY);
+ let result = M(target);
+ Reset(target);
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs
new file mode 100644
index 00000000000..53dac30786f
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs
@@ -0,0 +1,30 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Measurement {
+ open Microsoft.Quantum.Intrinsic;
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # 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.
+ @EnableTestingViaName("Test.TargetDefinitions.MResetZ")
+ operation MResetZ (target : Qubit) : Result {
+ let result = M(target);
+ Reset(target);
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/Measure.qs b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs
new file mode 100644
index 00000000000..e450a547657
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs
@@ -0,0 +1,71 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Performs a joint measurement of one or more qubits in the
+ /// specified Pauli bases.
+ ///
+ /// # Description
+ /// 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.
+ @EnableTestingViaName("Test.TargetDefinitions.Measure")
+ operation Measure (bases : Pauli[], qubits : Qubit[]) : Result {
+ CheckQubitUniqueness(qubits);
+ if (Length(bases) != Length(qubits)) { fail "Arrays 'bases' and 'qubits' must be of the same length."; }
+ mutable res = One;
+ if( Length(bases) == 1 ) {
+ within {
+ MapPauli(qubits[0], PauliZ, bases[0]);
+ }
+ apply {
+ set res = M(qubits[0]);
+ PreparePostM(res, qubits[0]);
+ }
+ }
+ else {
+ using( q = Qubit() ) {
+ H(q);
+ for( k in 0 .. Length(bases) - 1 ) {
+ if( bases[k] == PauliX ) { Controlled X ([qubits[k]], q); }
+ if( bases[k] == PauliZ ) { Controlled Z ([qubits[k]], q); }
+ if( bases[k] == PauliY ) { Controlled Y ([qubits[k]], q); }
+ }
+ H(q);
+ set res = M(q);
+ Reset(q);
+ }
+ }
+ return res;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs b/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs
new file mode 100644
index 00000000000..680d9d74faf
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs
@@ -0,0 +1,16 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ @EnableTestingViaName("Test.TargetDefinitions.PreparePostM")
+ internal operation PreparePostM(result : Result, qubit : Qubit) : Unit {
+ // This platform requires reset after measurement, and then must
+ // re-prepare the measured state in the qubit.
+ Reset(qubit);
+ if (result == One) {
+ X(qubit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs b/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs
new file mode 100644
index 00000000000..fb5dc304282
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs
@@ -0,0 +1,12 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ @EnableTestingViaName("Test.TargetDefinitions.PreparePostM")
+ internal operation PreparePostM(result : Result, qubit : Qubit) : Unit {
+ // This platform does not require any post-measurement reset, so
+ // no additional work is needed.
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs
new file mode 100644
index 00000000000..3ca0d96e0fb
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs
@@ -0,0 +1,58 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # SummaRx
+ /// Applies a rotation about the $x$-axis by a given angle.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.Rx")
+ operation Rx (theta : Double, qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledRx(theta, qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ RotationAngleValidation(theta);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledRx(theta, qubit);
+ }
+ elif (Length(ctls) == 1) {
+ within {
+ MapPauli(qubit, PauliZ, PauliX);
+ }
+ apply {
+ Controlled Rz(ctls, (theta, qubit));
+ }
+ }
+ else {
+ ApplyWithLessControlsA(Controlled Rx, (ctls, (theta, qubit)));
+ }
+ }
+ adjoint (...) {
+ Rx(-theta, qubit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs
new file mode 100644
index 00000000000..a3b70b732a2
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs
@@ -0,0 +1,58 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $y$-axis by a given angle.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.Ry")
+ operation Ry (theta : Double, qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledRy(theta, qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ RotationAngleValidation(theta);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledRy(theta, qubit);
+ }
+ elif (Length(ctls) == 1) {
+ within {
+ MapPauli(qubit, PauliZ, PauliY);
+ }
+ apply {
+ Controlled Rz(ctls, (theta, qubit));
+ }
+ }
+ else {
+ ApplyWithLessControlsA(Controlled Ry, (ctls, (theta, qubit)));
+ }
+ }
+ adjoint (...) {
+ Ry(-theta, qubit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs
new file mode 100644
index 00000000000..4806f04134e
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs
@@ -0,0 +1,56 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $z$-axis by a given angle.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.Rz")
+ operation Rz (theta : Double, qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledRz(theta, qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ RotationAngleValidation(theta);
+ if (Length(ctls) == 0) {
+ Rz(theta, qubit);
+ }
+ elif (Length(ctls) == 1) {
+ Rz(theta/2.0, qubit);
+ CNOT(ctls[0], qubit);
+ Rz(-theta/2.0, qubit);
+ CNOT(ctls[0], qubit);
+ }
+ else {
+ ApplyWithLessControlsA(Controlled Rz, (ctls, (theta, qubit)));
+ }
+ }
+ adjoint (...) {
+ Rz(-theta, qubit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs
new file mode 100644
index 00000000000..315b3f3b6f7
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs
@@ -0,0 +1,44 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the π/4 phase gate to a single qubit.
+ ///
+ /// # Description
+ /// \begin{align}
+ /// S \mathrel{:=}
+ /// \begin{bmatrix}
+ /// 1 & 0 \\\\
+ /// 0 & i
+ /// \end{bmatrix}.
+ /// \end{align}
+ ///
+ /// # Input
+ /// ## qubit
+ /// Qubit to which the gate should be applied.
+ @EnableTestingViaName("Test.TargetDefinitions.S")
+ operation S (qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledS(qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledS(qubit);
+ }
+ elif (Length(ctls) == 1) {
+ T(ctls[0]);
+ T(qubit);
+ CNOT(ctls[0], qubit);
+ Adjoint T(qubit);
+ CNOT(ctls[0], qubit);
+ }
+ else {
+ ApplyWithLessControlsA(Controlled S, (ctls, qubit));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs
new file mode 100644
index 00000000000..c4f23981e90
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs
@@ -0,0 +1,44 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the π/8 gate to a single qubit.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.T")
+ operation T (qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledT(qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledT(qubit);
+ }
+ elif (Length(ctls) == 1) {
+ R1Frac(1, 3, ctls[0]);
+ R1Frac(1, 3, qubit);
+ CNOT(ctls[0], qubit);
+ Adjoint R1Frac(1, 3, qubit);
+ CNOT(ctls[0], qubit);
+ }
+ else {
+ ApplyWithLessControlsA(Controlled T, (ctls, qubit));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs
index f0c38c1bfc0..d2808323a0d 100644
--- a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs
+++ b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs
@@ -4,41 +4,6 @@
namespace Microsoft.Quantum.Intrinsic {
open Microsoft.Quantum.Diagnostics;
- @EnableTestingViaName("Test.TargetDefinitions.ExpNoIdUtil")
- internal operation ExpNoIdUtil (paulis : Pauli[], theta : Double, qubits : Qubit[], rotation : ((Pauli, Qubit) => Unit is Adj + Ctl)) : Unit is Ctl {
- if (Length(paulis) != Length(qubits)) { fail "Arrays 'paulis' and 'qubits' must have the same length"; }
- if (Length(paulis) == 1) {
- rotation(paulis[0], qubits[0]);
- }
- elif (Length(paulis) == 2) {
- within {
- MapPauli(qubits[1], paulis[0], paulis[1]);
- }
- apply {
- if (paulis[0] == PauliX) {
- IsingXX(theta / 2.0, qubits[0], qubits[1]);
- } elif (paulis[0] == PauliY) {
- IsingYY(theta / 2.0, qubits[0], qubits[1]);
- } elif (paulis[0] == PauliZ) {
- IsingZZ(theta / 2.0, qubits[0], qubits[1]);
- } else {
- fail "Type2 decompositions do not support PauliI as an input to Exp";
- }
- }
- }
- else { // Length(paulis) > 2
- within {
- for (i in 0 .. Length(paulis) - 1) {
- MapPauli(qubits[i], PauliZ, paulis[i]);
- }
- SpreadZ(qubits[1], qubits[2 .. Length(qubits) - 1]);
- }
- apply {
- IsingZZ(theta / 2.0, qubits[0], qubits[1]);
- }
- }
- }
-
@EnableTestingViaName("Test.TargetDefinitions.SpreadZ")
internal operation SpreadZ (from : Qubit, to : Qubit[]) : Unit is Adj {
if (Length(to) > 0) {
@@ -53,8 +18,8 @@ namespace Microsoft.Quantum.Intrinsic {
@EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhase")
internal operation ApplyGlobalPhase (theta : Double) : Unit is Ctl + Adj {
- body(...) {}
- controlled(controls, (...)) {
+ body (...) {}
+ controlled (controls, (...)) {
if (Length(controls) > 0) {
let qubit = controls[0];
let rest = controls[1...];
@@ -67,8 +32,8 @@ namespace Microsoft.Quantum.Intrinsic {
@EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhaseFracWithR1Frac")
internal operation ApplyGlobalPhaseFracWithR1Frac (numerator : Int, power : Int) : Unit is Adj + Ctl {
- body(...) {}
- controlled(ctrls, ... ) {
+ body (...) {}
+ controlled (ctrls, ...) {
let numControls = Length(ctrls);
if (numControls > 0 ) {
// Invoke Controlled R1Frac, which will recursively call back into ApplyGlobalPhase.
@@ -106,6 +71,41 @@ namespace Microsoft.Quantum.Intrinsic {
}
}
+ /// Given a multiply-controlled operation that requires k controls
+ /// applies it using ceiling(k/2) controls and using floor(k/2) temporary qubits
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyWithLessControlsA")
+ internal operation ApplyWithLessControlsA<'T> (op : ((Qubit[],'T) => Unit is Adj), (controls : Qubit[], arg : 'T)) : Unit is Adj {
+ let numControls = Length(controls);
+ let numControlPairs = numControls / 2;
+ using (temps = Qubit[numControlPairs]) {
+ within {
+ for (numPair in 0 .. numControlPairs - 1) { // constant depth
+ PhaseCCX(controls[2*numPair], controls[2*numPair + 1], temps[numPair]);
+ }
+ }
+ apply {
+ let newControls = numControls % 2 == 0 ? temps | temps + [controls[numControls - 1]];
+ op(newControls, arg);
+ }
+ }
+ }
+
+ @EnableTestingViaName("Test.TargetDefinitions.PhaseCCX")
+ internal operation PhaseCCX (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj {
+ // https://arxiv.org/pdf/1210.0974.pdf#page=2
+ H(target);
+ CNOT(target,control1);
+ CNOT(control1,control2);
+ T(control2);
+ Adjoint T(control1);
+ T(target);
+ CNOT(target,control1);
+ CNOT(control1,control2);
+ Adjoint T(control2);
+ CNOT(target,control2);
+ H(target);
+ }
+
@EnableTestingViaName("Test.TargetDefinitions.ReducedDyadicFraction")
internal function ReducedDyadicFraction (numerator : Int, denominatorPowerOfTwo : Int) : (Int, Int) {
if (numerator == 0) { return (0,0); }
@@ -142,7 +142,7 @@ namespace Microsoft.Quantum.Intrinsic {
}
@EnableTestingViaName("Test.TargetDefinitions.IndicesOfNonIdentity")
- internal function IndicesOfNonIdentity(paulies : Pauli[]) : Int[] {
+ internal function IndicesOfNonIdentity (paulies : Pauli[]) : Int[] {
mutable nonIdPauliCount = 0;
for (i in 0 .. Length(paulies) - 1) {
@@ -163,7 +163,7 @@ namespace Microsoft.Quantum.Intrinsic {
}
@EnableTestingViaName("Test.TargetDefinitions.RemovePauliI")
- internal function RemovePauliI(paulis : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) {
+ internal function RemovePauliI (paulis : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) {
let indices = IndicesOfNonIdentity(paulis);
let newPaulis = Subarray(indices, paulis);
let newQubits = Subarray(indices, qubits);
diff --git a/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs
new file mode 100644
index 00000000000..05fd24f9a3a
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs
@@ -0,0 +1,44 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $X$ gate.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.X")
+ operation X (qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledX(qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledX(qubit);
+ }
+ elif (Length(ctls) == 1) {
+ ApplyControlledX(ctls[0], qubit);
+ }
+ elif (Length(ctls) == 2) {
+ CCNOT(ctls[0], ctls[1], qubit);
+ }
+ else {
+ ApplyWithLessControlsA(Controlled X, (ctls, qubit));
+ }
+ }
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs
new file mode 100644
index 00000000000..de7c394852b
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs
@@ -0,0 +1,54 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $Y$ gate.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.Y")
+ operation Y (qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledY(qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledY(qubit);
+ }
+ elif (Length(ctls) == 1) {
+ within {
+ MapPauli(qubit, PauliX, PauliY);
+ }
+ apply {
+ CNOT(ctls[0], qubit);
+ }
+ }
+ elif (Length(ctls) == 2) {
+ within {
+ MapPauli(qubit, PauliZ, PauliY);
+ }
+ apply {
+ Controlled Z(ctls, qubit);
+ }
+ }
+ else {
+ ApplyWithLessControlsA(Controlled Y, (ctls, qubit));
+ }
+ }
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs
new file mode 100644
index 00000000000..cce75a840e5
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs
@@ -0,0 +1,57 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $Z$ gate.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.Z")
+ operation Z (qubit : Qubit) : Unit is Adj + Ctl {
+ body (...) {
+ ApplyUncontrolledZ(qubit);
+ }
+ controlled (ctls, ...) {
+ CheckQubitUniqueness(ctls + [qubit]);
+ if (Length(ctls) == 0) {
+ ApplyUncontrolledZ(qubit);
+ }
+ elif (Length(ctls) == 1) {
+ ApplyControlledZ(ctls[0], qubit);
+ }
+ elif (Length(ctls) == 2) {
+ // [Page 15 of arXiv:1206.0758v3](https://arxiv.org/pdf/1206.0758v3.pdf#page=15)
+ Adjoint T(ctls[0]);
+ Adjoint T(ctls[1]);
+ CNOT(qubit, ctls[0]);
+ T(ctls[0]);
+ CNOT(ctls[1], qubit);
+ CNOT(ctls[1], ctls[0]);
+ T(qubit);
+ Adjoint T(ctls[0]);
+ CNOT(ctls[1], qubit);
+ CNOT(qubit, ctls[0]);
+ Adjoint T(qubit);
+ T(ctls[0]);
+ CNOT(ctls[1], ctls[0]);
+ }
+ else {
+ ApplyWithLessControlsA(Controlled Z, (ctls, qubit));
+ }
+ }
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs
new file mode 100644
index 00000000000..0c5417ada18
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs
@@ -0,0 +1,40 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the controlled-X (or CNOT) gate to a pair of qubits. Does not support
+ /// the Controlled functor.
+ ///
+ /// # Description
+ /// \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
+ /// CNOT(control, target);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX")
+ internal operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs
new file mode 100644
index 00000000000..c91154afdab
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the controlled-Z (CZ) gate to a pair of qubits.
+ ///
+ /// $$
+ /// \begin{align}
+ /// 1 & 0 & 0 & 0 \\\\
+ /// 0 & 1 & 0 & 0 \\\\
+ /// 0 & 0 & 1 & 0 \\\\
+ /// 0 & 0 & 0 & -1
+ /// \end{align},
+ /// $$
+ /// where rows and columns are organized as in the quantum concepts guide.
+ ///
+ /// # Input
+ /// ## control
+ /// Control qubit for the CZ gate.
+ /// ## target
+ /// Target qubit for the CZ gate.
+ ///
+ /// # Remarks
+ /// Equivalent to:
+ /// ```qsharp
+ /// Controlled Z([control], target);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ")
+ internal operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs
new file mode 100644
index 00000000000..8b0f82af9c2
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs
@@ -0,0 +1,29 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Hadamard transformation to a single qubit. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledH")
+ internal operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs
new file mode 100644
index 00000000000..215b8014710
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $x$-axis by a given angle. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRx")
+ internal operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs
new file mode 100644
index 00000000000..7f70a7f60d5
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $y$-axis by a given angle. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRy")
+ internal operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs
new file mode 100644
index 00000000000..14e5d95a414
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies a rotation about the $z$-axis by a given angle. Note that the Controlled
+ /// functor is not supported.
+ ///
+ /// # Description
+ /// \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);
+ /// ```
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRz")
+ internal operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs
new file mode 100644
index 00000000000..530c0e3397b
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs
@@ -0,0 +1,28 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the π/4 phase gate to a single qubit. Note that the Controlled functor
+ /// is not supported.
+ ///
+ /// # Description
+ /// \begin{align}
+ /// S \mathrel{:=}
+ /// \begin{bmatrix}
+ /// 1 & 0 \\\\
+ /// 0 & i
+ /// \end{bmatrix}.
+ /// \end{align}
+ ///
+ /// # Input
+ /// ## qubit
+ /// Qubit to which the gate should be applied.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS")
+ internal operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs
new file mode 100644
index 00000000000..820b5cb7eda
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs
@@ -0,0 +1,28 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the π/8 gate to a single qubit. Note that the Controlled functor is
+ /// not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT")
+ internal operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs
new file mode 100644
index 00000000000..45a27d9a5f6
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs
@@ -0,0 +1,27 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $X$ gate. Note that the Controlled functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledX")
+ internal operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs
new file mode 100644
index 00000000000..8e9a2fe20bb
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs
@@ -0,0 +1,27 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $Y$ gate. Note that the Controlled functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledY")
+ internal operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs
new file mode 100644
index 00000000000..302252cf68e
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs
@@ -0,0 +1,27 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Applies the Pauli $Z$ gate. Note that the Controlled functor is not supported.
+ ///
+ /// # Description
+ /// \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.
+ @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledZ")
+ internal operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj {
+ body intrinsic;
+ adjoint self;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs
index 37bcc86889b..3f772bb6819 100644
--- a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs
+++ b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs
@@ -8,18 +8,14 @@ namespace Microsoft.Quantum.Intrinsic {
/// Checks that all qubits operated on are unique.
///
/// # Description
- /// \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)`.
+ /// Will fail if any qubits are repeated or null.
///
/// # Input
/// ## qubits
/// The array of qubits to verify for uniqueness. In the controlled variant
/// the full list of qubits among targets and controls are verified to be unique.
@EnableTestingViaName("Test.TargetDefinitions.CheckQubitUniqueness")
- operation CheckQubitUniqueness (qubits : Qubit[]) : Unit is Adj + Ctl{
+ internal operation CheckQubitUniqueness (qubits : Qubit[]) : Unit is Adj + Ctl{
body intrinsic;
adjoint self;
}
@@ -29,13 +25,13 @@ namespace Microsoft.Quantum.Intrinsic {
/// Validates that the given angle is a Double that can be used for rotation.
///
/// # Description
- /// Validates that the value of theDouble representing a rotation angle is neither infinite nor NaN.
+ /// Validates that the value of the Double representing a rotation angle is neither infinite nor NaN.
///
/// # Input
/// ## angle
/// The Double to validate.
@EnableTestingViaName("Test.TargetDefinitions.RotationAngleValidation")
- function RotationAngleValidation (angle : Double) : Unit {
+ internal function RotationAngleValidation (angle : Double) : Unit {
body intrinsic;
}
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs
index 51a88e4ac9a..c20f4c56731 100644
--- a/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs
+++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs
@@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic {
/// ## qubit1
/// The second qubit input to the gate.
@EnableTestingViaName("Test.TargetDefinitions.IsingXX")
- operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
body intrinsic;
}
}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs
index 03e1e7b7fa2..39fe3a24ff5 100644
--- a/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs
+++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs
@@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic {
/// ## qubit1
/// The second qubit input to the gate.
@EnableTestingViaName("Test.TargetDefinitions.IsingYY")
- operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
body intrinsic;
}
}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs
index ae5c0f86ec7..c800c2b92f2 100644
--- a/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs
+++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs
@@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic {
/// ## qubit1
/// The second qubit input to the gate.
@EnableTestingViaName("Test.TargetDefinitions.IsingZZ")
- operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
+ internal operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl {
body intrinsic;
}
}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs b/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs
new file mode 100644
index 00000000000..7531b828982
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs
@@ -0,0 +1,18 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Quantum.Intrinsic {
+ open Microsoft.Quantum.Diagnostics;
+
+ /// # Summary
+ /// Given a single qubit, measures it and ensures it is in the |0⟩ state
+ /// such that it can be safely released.
+ ///
+ /// # Input
+ /// ## qubit
+ /// The qubit whose state is to be reset to $\ket{0}$.
+ @EnableTestingViaName("Test.TargetDefinitions.Reset")
+ operation Reset (target : Qubit) : Unit {
+ body intrinsic;
+ }
+}
\ No newline at end of file
diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Common.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Common.Package.props
new file mode 100644
index 00000000000..a53c8f9abbe
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/TargetPackages/Common.Package.props
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+ netstandard2.1
+ true
+ false
+ false
+
+
+
+ Microsoft
+ See: https://docs.microsoft.com/en-us/quantum/relnotes/
+ MIT
+ https://github.com/microsoft/qsharp-runtime
+ qdk-nuget-icon.png
+ Quantum Q# Qsharp
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props
index bf9a8f3b89c..1cd2cc765e2 100644
--- a/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props
+++ b/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props
@@ -1,6 +1,8 @@
+
+
@@ -17,6 +19,17 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props
new file mode 100644
index 00000000000..f6bbf7afc2e
--- /dev/null
+++ b/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props
index be0f1d9635e..dcd2ce6ca94 100644
--- a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props
+++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props
@@ -1,6 +1,8 @@
+
+
@@ -22,12 +24,24 @@
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
diff --git a/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj
new file mode 100644
index 00000000000..b10dbda60de
--- /dev/null
+++ b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj
@@ -0,0 +1,10 @@
+
+
+
+
+
+ Type1 Targeting support for the Q# programming language.
+
+
+
+
diff --git a/src/Simulation/Type1Core/Properties/AssemblyInfo.cs b/src/Simulation/Type1Core/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..0420d9b3e57
--- /dev/null
+++ b/src/Simulation/Type1Core/Properties/AssemblyInfo.cs
@@ -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.Type1" + SigningConstants.PUBLIC_KEY)]
\ No newline at end of file
diff --git a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj
index c4bff35d9b4..487b58c4c69 100644
--- a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj
+++ b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj
@@ -1,47 +1,10 @@
-
-
-
- netstandard2.1
- true
- false
- false
-
-
-
- Microsoft
Type2 Targeting support for the Q# programming language.
- See: https://docs.microsoft.com/en-us/quantum/relnotes/
- MIT
- https://github.com/microsoft/qsharp-runtime
- qdk-nuget-icon.png
- Quantum Q# Qsharp
- true
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Simulation/Type2Core/Properties/AssemblyInfo.cs b/src/Simulation/Type2Core/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..39993b2efbb
--- /dev/null
+++ b/src/Simulation/Type2Core/Properties/AssemblyInfo.cs
@@ -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.Type2" + SigningConstants.PUBLIC_KEY)]
\ No newline at end of file