diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000000..bc9cabd0ec5 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,8 @@ +FROM mcr.microsoft.com/dotnet/sdk:3.1-focal +RUN apt update \ + && apt-get install -y cmake \ + && apt-get install -y ninja-build \ + && apt-get install -y clang-11 \ + && apt-get install -y clang-tidy-11 +RUN apt-get install -y build-essential +CMD [ "pwsh" ] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000..a2ff6028b9a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,5 @@ +{ + "build": { + "dockerfile": "Dockerfile" + } +} \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..f272b39d58c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,61 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto +*.sh text eol=lf + +############################################################################### +# diff behavior for some non-binary formats +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +*.md diff=astextplain +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8ed0e07dbcc..f77b7e72b01 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ bld/ [Oo]bj/ [Ll]og/ [Dd]rops/ +**/qir-gen.ll # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/AdvantageBenchmark/privateBuild/host.csproj b/AdvantageBenchmark/privateBuild/host.csproj index 5fbd6838ee9..422cd590f67 100644 --- a/AdvantageBenchmark/privateBuild/host.csproj +++ b/AdvantageBenchmark/privateBuild/host.csproj @@ -1,4 +1,4 @@ - + diff --git a/AdvantageBenchmark/releasedBuild/quantum/quantum.csproj b/AdvantageBenchmark/releasedBuild/quantum/quantum.csproj index b7284bec583..50c82fa9032 100644 --- a/AdvantageBenchmark/releasedBuild/quantum/quantum.csproj +++ b/AdvantageBenchmark/releasedBuild/quantum/quantum.csproj @@ -1,4 +1,4 @@ - + diff --git a/build/build.ps1 b/build/build.ps1 index 3af9ece1dc0..9ff2e82b758 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -16,18 +16,6 @@ if ($Env:ENABLE_NATIVE -ne "false") { Write-Host "Skipping build of native simulator because ENABLE_NATIVE variable is set to: $Env:ENABLE_NATIVE." } - -if ($Env:ENABLE_QIRRUNTIME -eq "true") { - $qirRuntime = (Join-Path $PSScriptRoot "../src/QirRuntime") - & "$qirRuntime/build-qir-runtime.ps1" - if ($LastExitCode -ne 0) { - $script:all_ok = $False - } -} else { - Write-Host "Skipping build of qir runtime because ENABLE_QIRRUNTIME variable is set to: $Env:ENABLE_QIRRUNTIME" -} - - function Build-One { param( [string]$action, @@ -57,6 +45,16 @@ Build-One 'publish' '../src/Simulation/CSharpGeneration.App' Build-One 'build' '../Simulation.sln' +if ($Env:ENABLE_QIRRUNTIME -eq "true") { + $qirRuntime = (Join-Path $PSScriptRoot "../src/QirRuntime") + & "$qirRuntime/build-qir-runtime.ps1" + if ($LastExitCode -ne 0) { + $script:all_ok = $False + } +} else { + Write-Host "Skipping build of qir runtime because ENABLE_QIRRUNTIME variable is set to: $Env:ENABLE_QIRRUNTIME" +} + if (-not $all_ok) { throw "At least one project failed to compile. Check the logs." } diff --git a/build/ci.yml b/build/ci.yml index 662f7f6f33b..111b68c0595 100644 --- a/build/ci.yml +++ b/build/ci.yml @@ -22,7 +22,7 @@ variables: Drops.Dir: $(Build.ArtifactStagingDirectory)/drops Drop.Native: $(System.DefaultWorkingDirectory)/xplat CI: "true" - ENABLE_QIRRUNTIME: "true" + ENABLE_QIRRUNTIME: "false" jobs: - job: build diff --git a/build/set-env.ps1 b/build/set-env.ps1 index fe39a1224ec..9d9e79c6c83 100644 --- a/build/set-env.ps1 +++ b/build/set-env.ps1 @@ -11,10 +11,8 @@ If ($Env:BUILD_VERBOSITY -eq $null) { $Env:BUILD_VERBOSITY ="m" } If ($Env:ASSEMBLY_VERSION -eq $null) { $Env:ASSEMBLY_VERSION ="$Env:BUILD_BUILDNUMBER" } If ($Env:NUGET_VERSION -eq $null) { $Env:NUGET_VERSION ="$Env:ASSEMBLY_VERSION-alpha" } -If ($Env:ENABLE_QIRRUNTIME -eq "true") { - If (($Env:ENABLE_NATIVE -ne "false") -and ($Env:NATIVE_SIMULATOR -eq $null) ) { - $Env:NATIVE_SIMULATOR = (Join-Path $PSScriptRoot "..\src\Simulation\Native\build\drop") - } +If (($Env:ENABLE_NATIVE -ne "false") -and ($Env:NATIVE_SIMULATOR -eq $null) ) { + $Env:NATIVE_SIMULATOR = (Join-Path $PSScriptRoot "..\src\Simulation\Native\build\drop") } If ($Env:DROPS_DIR -eq $null) { $Env:DROPS_DIR = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\drops")) } diff --git a/build/steps.yml b/build/steps.yml index 89e377bfb6e..77054f58a30 100644 --- a/build/steps.yml +++ b/build/steps.yml @@ -5,18 +5,18 @@ steps: - template: steps-init.yml -- powershell: ./build.ps1 +- pwsh: ./build.ps1 displayName: "Building Q# runtime" workingDirectory: $(System.DefaultWorkingDirectory)/build -- powershell: ./test.ps1 +- pwsh: ./test.ps1 displayName: "Testing Q# runtime" workingDirectory: $(System.DefaultWorkingDirectory)/build condition: and(succeeded(), ne(variables['Skip.Tests'], 'true')) -- powershell: ./pack.ps1 +- pwsh: ./pack.ps1 displayName: "Pack Q# runtime (Windows only)" condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT')) workingDirectory: $(System.DefaultWorkingDirectory)/build diff --git a/build/test.ps1 b/build/test.ps1 index d1941939ecd..cc2e0507a28 100644 --- a/build/test.ps1 +++ b/build/test.ps1 @@ -13,18 +13,6 @@ if ($Env:ENABLE_NATIVE -ne "false") { } else { Write-Host "Skipping test of native simulator because ENABLE_NATIVE variable is set to: $Env:ENABLE_NATIVE." } - -if (($Env:ENABLE_NATIVE -ne "false") -and ($Env:ENABLE_QIRRUNTIME -eq "true")) { - $qirRuntime = (Join-Path $PSScriptRoot "../src/QirRuntime") - & "$qirRuntime/test-qir-runtime.ps1" - if ($LastExitCode -ne 0) { - $script:all_ok = $False - } -} else { - Write-Host "Skipping test of qir runtime because ENABLE_QIRRUNTIME variable is set to: $Env:ENABLE_QIRRUNTIME ` - and ENABLE_NATIVE variable is set to: $Env:ENABLE_NATIVE." -} - function Test-One { Param($project) @@ -49,6 +37,17 @@ function Test-One { Test-One '../Simulation.sln' +if (($Env:ENABLE_NATIVE -ne "false") -and ($Env:ENABLE_QIRRUNTIME -eq "true")) { + $qirRuntime = (Join-Path $PSScriptRoot "../src/QirRuntime") + & "$qirRuntime/test-qir-runtime.ps1" + if ($LastExitCode -ne 0) { + $script:all_ok = $False + } +} else { + Write-Host "Skipping test of qir runtime because ENABLE_QIRRUNTIME variable is set to: $Env:ENABLE_QIRRUNTIME ` + and ENABLE_NATIVE variable is set to: $Env:ENABLE_NATIVE." +} + if (-not $all_ok) { throw "At least one project failed during testing. Check the logs." } diff --git a/src/QirRuntime/CMakeLists.txt b/src/QirRuntime/CMakeLists.txt index 28ea5e8c349..06f29c7fe5c 100644 --- a/src/QirRuntime/CMakeLists.txt +++ b/src/QirRuntime/CMakeLists.txt @@ -27,99 +27,21 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") set(public_includes "${PROJECT_SOURCE_DIR}/public") -set(test_includes "${PROJECT_SOURCE_DIR}/externals/catch2" "${PROJECT_SOURCE_DIR}/test") -#=============================================================================== -# testing related -# -include(CTest) -macro(add_unit_test target) - add_test( - NAME ${target} - COMMAND ${target} ~[skip] -o "${target}_results.xml" -r junit - ) - - # set the environment path for loading shared libs the tests are using - if(DEFINED ENV{NATIVE_SIMULATOR}) - set(TEST_DEPS1 $ENV{NATIVE_SIMULATOR}) - else() - set(TEST_DEPS1 "${PROJECT_SOURCE_DIR}/../Simulation/native/build/${CMAKE_BUILD_TYPE}") - endif() - - set(TEST_DEPS2 "${CMAKE_BINARY_DIR}/bin") - set_property(TEST ${target} PROPERTY ENVIRONMENT - "LD_LIBRARY_PATH=${TEST_DEPS1}:${TEST_DEPS2}:${LD_LIBRARY_PATH}" - "PATH=${TEST_DEPS1}\;${TEST_DEPS2}\;${PATH}" - "DYLD_LIBRARY_PATH=${TEST_DEPS1}:${TEST_DEPS2}:${DYLD_LIBRARY_PATH}" - ) -endmacro(add_unit_test) - -#=============================================================================== -# compiling from IR -# -# CMake doesn't support LLVM IR files as sources so we compile them with custom -# commands, which produce UTILITY libs that can only be linked in using abs paths -# (rather than the target name): -# Target "qir_bridge_qis" of type UTILITY may not be linked into another -# target. One may link only to INTERFACE, OBJECT, STATIC or SHARED -# libraries, or to executables with the ENABLE_EXPORTS property set. -# -macro(compile_from_qir source_file target) - set(CLANG_ARGS "-c") - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CLANG_ARGS - "${CLANG_ARGS}" - "-O0" - "-D_DEBUG" - ) - endif() - - set(INFILE - "${CMAKE_CURRENT_SOURCE_DIR}/${source_file}.ll" - ) - set(OBJFILE - "${CMAKE_CURRENT_BINARY_DIR}/${source_file}.obj" - ) - - set(OBJFILE_COMPILE "${source_file}-compile") - add_custom_command(OUTPUT ${OBJFILE_COMPILE} - COMMAND ${CMAKE_CXX_COMPILER} - ARGS ${CLANG_ARGS} ${INFILE} "-o" ${OBJFILE} - DEPENDS ${INFILE} - COMMENT "Compiling ${source_file}.ll" - VERBATIM - ) - - add_custom_target(${source_file}_compile DEPENDS ${OBJFILE_COMPILE}) - - if (WIN32) - set(QIR_UTILITY_LIB "${CMAKE_CURRENT_BINARY_DIR}/${source_file}-u.lib" ) - else() - set(QIR_UTILITY_LIB "${CMAKE_CURRENT_BINARY_DIR}/lib${source_file}-u.a") - endif() - - add_custom_command(OUTPUT ${QIR_UTILITY_LIB} - COMMAND ${CMAKE_AR} - ARGS "rc" ${QIR_UTILITY_LIB} ${OBJFILE} - DEPENDS ${source_file}_compile ${INFILE} - COMMENT "Creating a lib from ${source_file}.ll" - VERBATIM - ) - - if (NOT ${target} STREQUAL "") - add_custom_target(${target} DEPENDS ${QIR_UTILITY_LIB}) - endif() -endmacro(compile_from_qir) +include(qir_cmake_include) if (WIN32) set(QIR_BRIDGE_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QIR/bridge-rt-u.lib") - set(QIR_BRIDGE_QIS_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QIR/bridge-qis-u.lib") + set(QSHARP_FOUNDATION_BRIDGE_QIS_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QSharpFoundation/qsharp-foundation-qis-u.lib") + set(QSHARP_CORE_BRIDGE_QIS_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QSharpCore/qsharp-core-qis-u.lib") + set(QIR_BRIDGE_TRACER_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/Tracer/tracer-bridge-u.lib") else() set(QIR_BRIDGE_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QIR/libbridge-rt-u.a") - set(QIR_BRIDGE_QIS_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QIR/libbridge-qis-u.a") + set(QSHARP_FOUNDATION_BRIDGE_QIS_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QSharpFoundation/libqsharp-foundation-qis-u.a") + set(QSHARP_CORE_BRIDGE_QIS_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/QSharpCore/libqsharp-core-qis-u.a") + set(QIR_BRIDGE_TRACER_UTILITY_LIB "${PROJECT_BINARY_DIR}/lib/Tracer/libtracer-bridge-u.a") endif() - add_subdirectory(lib) +add_subdirectory(samples) add_subdirectory(test) - diff --git a/src/QirRuntime/README.md b/src/QirRuntime/README.md index 856bdbf0ce0..3a7f2e4b69b 100644 --- a/src/QirRuntime/README.md +++ b/src/QirRuntime/README.md @@ -11,7 +11,7 @@ This folder contains QIR runtime project, which includes implementation of the ## Build -The QirRuntime project is using CMake (3.17) + Ninja(1.10.0) + Clang++(10.0.0). Other versions of the tools might work +The QirRuntime project is using CMake (3.17) + Ninja(1.10.0) + Clang++(11.0.0). Other versions of the tools might work but haven't been tested. Only x64 architecture is supported. You can use CMake directly. For example, to produce a release build: @@ -22,40 +22,36 @@ You can use CMake directly. For example, to produce a release build: 4. cmake -G Ninja -DCMAKE_BUILD_TYPE=Release .. 5. cmake --build . -Or you can run `build.py` script from QirRuntime folder. The default options for the script are `make debug`. +Or you can run `build-qir-runtime.ps1` script from QirRuntime folder. The script will place the build artifacts into `build/[Debug|Release]` folder. We strongly recommend doing local builds using the build script because it also runs clang-tidy if it is installed. -- (Windows) `python build.py [make/nomake] [debug|release]` -- (Linux) `python3 build.py [make/nomake] [debug|release]` +CI builds and tests are enabled for this project. The build for `test/QIR-static/qsharp/qir-gen.csproj` has project dependencies on other parts of the runtime and may trigger a build for those components, while some of the tests depend on `Microsoft.Quantum.Simulator.Runtime` dynamic library built from. -The script will place the build artifacts into `build/[Windows|Linux]/[Debug|Release]` folder. We strongly recommend - doing local builds using the build script because it also runs clang-tidy. - -CI builds and tests are enabled for this project. The build has no external dependencies, but some of the tests depend - on `Microsoft.Quantum.Simulator.Runtime` library. +To install prerequisite tools for building the QIR runtime, you can set the `ENABLE_QIRRUNTIME` environment variable to the string `"true"` and run `prerequisites.ps1` or manually install pre-reqs with the steps listed below (Windows script relies on [Chocolatey](https://chocolatey.org/) for installation). ### Windows pre-reqs -1. Install Clang, Ninja and CMake from the public distros. -2. Add all three to your/system `%PATH%`. -3. Install VS 2019 and enable "Desktop development with C++" component (Clang uses MSVC's standard library on Windows). -4. Install clang-tidy and clang-format if your Clang/LLVM packages didn't include the tools. -5. <_optional_> To use build/test scripts install Python 3.8. +1. Install Clang 11, Ninja and CMake from the public distros. +1. Add all three to your/system `%PATH%`. +1. Install VS 2019 and enable "Desktop development with C++" component (Clang uses MSVC's standard library on Windows). +1. Install clang-tidy and clang-format if your Clang/LLVM packages didn't include the tools. +1. Install the same version of dotnet as specified by qsharp-runtime [README](../../README.md) *Building from Visual Studio and VS Code is **not** supported. Running cmake from the editors will likely default to MSVC or clang-cl and fail.* ### Linux via WSL pre-reqs -1. On the host Windows machine [enable WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10) and install Ubuntu 20.04 LTS. -2. In the Ubuntu's terminal: +1. On the host Windows machine [enable WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10) and install + Ubuntu 20.04 LTS. +1. In the Ubuntu's terminal: 1. `$ sudo apt install cmake` (`$ cmake --version` should return 3.16.3) - 2. `$ sudo apt-get install ninja-build` (`$ ninja --version` should return 1.10.0) - 3. `$ sudo apt install clang` (`$ clang++ --version` should return 10.0.0) - 4. Set Clang as the preferred C/C++ compiler: - - $ export CC=/usr/bin/clang - - $ export CXX=/usr/bin/clang++ - 5. `$ sudo apt install clang-tidy` (`$ clang-tidy --version` should return 'LLVM version 10.0.0') - 6. <_optional_> To use build/test scripts, check that you have python3 installed (it should be by default). + 1. `$ sudo apt-get install ninja-build` (`$ ninja --version` should return 1.10.0) + 1. `$ sudo apt install clang-11` (`$ clang++-11 --version` should return 11.0.0) + 1. Set Clang as the preferred C/C++ compiler: + - $ export CC=/usr/bin/clang-11 + - $ export CXX=/usr/bin/clang++-11 + 1. `$ sudo apt install clang-tidy-11` (`$ clang-tidy-11 --version` should return 'LLVM version 11.0.0') + 1. Install the same version of dotnet as specified by qsharp-runtime [README](../../README.md) See [https://code.visualstudio.com/docs/remote/wsl] on how to use VS Code with WSL. @@ -65,6 +61,11 @@ Some of the tests depend on Microsoft.Quantum.Simulator.Runtime library. To run from this repository or provide your own version of the library in a folder the OS would search during dynamic library lookup. +Some of the tests use generated QIR (*.ll) files as build input. Currently the files are checked-in as part of the project + but in the future they will be replaced by automatic generation during build. To regenerate the files, run generateqir.py + or build/test scripts without specifying `noqirgen`. To use the checked-in files without regenerating them, run build/test + scripts with `noqirgen` argument. + ### Running tests with test.py To execute all tests locally run `test.py` from the project's root folder: @@ -162,8 +163,6 @@ CMake doesn't support using LLVM's IR files as input so instead we invoke Clang 1. All functionality related to BigInt type (including `__quantum__rt__bigint_to_string`) NYI. 1. QIR is assumed to be __single threaded__. No effort was made to make the bridge and runtime thread safe. 1. Strings are implemented as a thin wrapper over std::string with virtually no optimizations. -1. `__quantum__rt__string_create` currently doesn't conform to the spec (it expects a null terminated string rather than - a string of specified length). 1. Variadic functions (e.g. `__quantum__rt__array_create`) require platform specific bridges. The currently implemented bridge is for Windows. 1. Qubit borrowing NYI (needs both bridge and simulator's support). diff --git a/src/QirRuntime/build-qir-runtime.ps1 b/src/QirRuntime/build-qir-runtime.ps1 index ea0654513e8..f7e4388b884 100644 --- a/src/QirRuntime/build-qir-runtime.ps1 +++ b/src/QirRuntime/build-qir-runtime.ps1 @@ -1,54 +1,92 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -if ($Env:ENABLE_QIRRUNTIME -eq "true") { - Write-Host "##[info]Build QIR Runtime" - $oldCC = $env:CC - $oldCXX = $env:CXX - $oldRC = $env:RC - - if (($IsMacOS) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) - { - Write-Host "On MacOS build QIR Runtim using the default C/C++ compiler (should be AppleClang)" - } - elseif (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin")))) - { - Write-Host "On Linux build QIR Runtime using Clang" - $env:CC = "/usr/bin/clang" - $env:CXX = "/usr/bin/clang++" - $env:RC = "/usr/bin/clang++" - } - elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) - { - Write-Host "On Windows build QIR Runtime using Clang" - $env:CC = "C:\Program Files\LLVM\bin\clang.exe" - $env:CXX = "C:\Program Files\LLVM\bin\clang++.exe" - $env:RC = "C:\Program Files\LLVM\bin\clang++.exe" - $llvmExtras = (Join-Path $PSScriptRoot "externals/LLVM") - $env:PATH += ";$llvmExtras" - } else { - Write-Host "##vso[task.logissue type=error;]Failed to identify the OS. Will use default CXX compiler" - } - - $qirRuntimeBuildFolder = (Join-Path $PSScriptRoot "build\$Env:BUILD_CONFIGURATION") - if (-not (Test-Path $qirRuntimeBuildFolder)) { - New-Item -Path $qirRuntimeBuildFolder -ItemType "directory" - } +& (Join-Path $PSScriptRoot .. .. build set-env.ps1) +Write-Host "##[info]Compile Q# Projects into QIR" +$qirStaticPath = Join-Path $PSScriptRoot test QIR-static qsharp +dotnet build $qirStaticPath -c $Env:BUILD_CONFIGURATION -v $Env:BUILD_VERBOSITY +if ($LastExitCode -ne 0) { + Write-Host "##vso[task.logissue type=error;]Failed to compile Q# project at '$qirStaticPath' into QIR." + return +} +Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination (Split-Path $qirStaticPath -Parent) +# Also copy to drops so it ends up in build artifacts, for easier post-build debugging. +Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination $Env:DROPS_DIR - Push-Location $qirRuntimeBuildFolder +Write-Host "##[info]Build QIR Runtime" +$oldCC = $env:CC +$oldCXX = $env:CXX +$oldRC = $env:RC - cmake -G Ninja -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" ../.. - cmake --build . --target install +$clangTidy = "" - Pop-Location +if (($IsMacOS) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) +{ + Write-Host "On MacOS build QIR Runtime using the default C/C++ compiler (should be AppleClang)" +} +elseif (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin")))) +{ + Write-Host "On Linux build QIR Runtime using Clang" + $env:CC = "clang-11" + $env:CXX = "clang++-11" + $env:RC = "clang++-11" + $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy-11" +} +elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) +{ + Write-Host "On Windows build QIR Runtime using Clang" + $env:CC = "clang.exe" + $env:CXX = "clang++.exe" + $env:RC = "clang++.exe" - $env:CC = $oldCC - $env:CXX = $oldCXX - $env:RC = $oldRC + if (!(Get-Command clang -ErrorAction SilentlyContinue) -and (choco find --idonly -l llvm) -contains "llvm") { + # LLVM was installed by Chocolatey, so add the install location to the path. + $env:PATH += ";$($env:SystemDrive)\Program Files\LLVM\bin" + } - if ($LastExitCode -ne 0) { - Write-Host "##vso[task.logissue type=error;]Failed to build QIR Runtime." + if (Get-Command clang-tidy -ErrorAction SilentlyContinue) { + # Only run clang-tidy if it's installed. This is because the package used by chocolatey on + # the build pipeline doesn't include clang-tidy, so we allow skipping that there and let + # the Linux build catch tidy issues. + $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy" } } else { - Write-Host "To enable build of QIR Runtime set ENABLE_QIRRUNTIME environment variable to 'true'" + Write-Host "##vso[task.logissue type=error;]Failed to identify the OS. Will use default CXX compiler" +} + +$qirRuntimeBuildFolder = (Join-Path $PSScriptRoot "build\$Env:BUILD_CONFIGURATION") +if (-not (Test-Path $qirRuntimeBuildFolder)) { + New-Item -Path $qirRuntimeBuildFolder -ItemType "directory" +} + +Push-Location $qirRuntimeBuildFolder + +cmake -G Ninja $clangTidy -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" ../.. +if ($LastExitCode -ne 0) { + Write-Host "##vso[task.logissue type=error;]Failed to generate QIR Runtime." +} +cmake --build . --target install +if ($LastExitCode -ne 0) { + Write-Host "##vso[task.logissue type=error;]Failed to build QIR Runtime." } + +$os = "win" +$pattern = @("*.dll", "*.lib") +if ($IsMacOS) { + $os = "osx" + $pattern = @("*.dylib") +} elseif ($IsLinux) { + $os = "linux" + $pattern = @("*.so") +} +$osQirDropFolder = Join-Path $Env:DROPS_DIR QIR $os +if (!(Test-Path $osQirDropFolder)) { + New-Item -Path $osQirDropFolder -ItemType "directory" +} +$pattern | Foreach-Object { Copy-Item (Join-Path . bin $_) $osQirDropFolder } + +Pop-Location + +$env:CC = $oldCC +$env:CXX = $oldCXX +$env:RC = $oldRC diff --git a/src/QirRuntime/build.py b/src/QirRuntime/build.py index f4c52a32483..5b6c1646a19 100644 --- a/src/QirRuntime/build.py +++ b/src/QirRuntime/build.py @@ -1,7 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -import sys, os, platform, subprocess, datetime +import sys, os, platform, subprocess, datetime, shutil +import generateqir # ============================================================================= # The script will create [root]\build\[OS]\[Debug|Release] folder for the output. @@ -44,10 +45,14 @@ def do_build(root_dir, should_make, should_build, flavor): flavorWithDebInfo = flavor if flavor == "Release" : - flavorWithDebInfo = "RelWithDebInfo" + flavorWithDebInfo = "RelWithDebInfo" + + clangTidy = "clang-tidy" + if platform.system() == "Linux" : + clangTidy = "clang-tidy-11" if should_make: - cmd = "cmake -G Ninja -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_BUILD_TYPE=" + flavorWithDebInfo + " ../../.." + cmd = "cmake -G Ninja -DCMAKE_CXX_CLANG_TIDY=" + clangTidy + " -DCMAKE_BUILD_TYPE=" + flavorWithDebInfo + " ../../.." log("running: " + cmd) result = subprocess.run(cmd, shell = True) if result.returncode != 0: @@ -67,6 +72,7 @@ def do_build(root_dir, should_make, should_build, flavor): flavor = "Debug" should_make = True should_build = True + noqirgen = False for arg in sys.argv: arg = arg.lower() @@ -80,9 +86,17 @@ def do_build(root_dir, should_make, should_build, flavor): should_make = False elif arg == "make": should_build = False + elif arg == "noqirgen": + noqirgen = True else: log("unrecognized argument: " + arg) sys.exit() root_dir = os.path.dirname(os.path.abspath(__file__)) + + if not noqirgen: + if generateqir.do_generate_all(root_dir) != 0: + log("Aborting build due to failures in QIR generation") + sys.exit() + do_build(root_dir, should_make, should_build, flavor) \ No newline at end of file diff --git a/src/QirRuntime/cmake/qir_cmake_include.cmake b/src/QirRuntime/cmake/qir_cmake_include.cmake new file mode 100644 index 00000000000..7328a745ee0 --- /dev/null +++ b/src/QirRuntime/cmake/qir_cmake_include.cmake @@ -0,0 +1,68 @@ +#=============================================================================== +# compiling from IR +# +# CMake doesn't support LLVM IR files as sources so we compile them with custom +# commands, which produce UTILITY libs that can only be linked in using abs paths +# (rather than the target name): +# Target "qir_bridge_qis" of type UTILITY may not be linked into another +# target. One may link only to INTERFACE, OBJECT, STATIC or SHARED +# libraries, or to executables with the ENABLE_EXPORTS property set. +# +macro(compile_from_qir source_file target) + set(CLANG_ARGS "-c") + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CLANG_ARGS + "${CLANG_ARGS}" + "-O0" + "-D_DEBUG" + ) + endif() + + set(INFILE + "${CMAKE_CURRENT_SOURCE_DIR}/${source_file}.ll" + ) + set(OBJFILE + "${CMAKE_CURRENT_BINARY_DIR}/${source_file}.obj" + ) + + set(OBJFILE_COMPILE "${source_file}-compile") + add_custom_command(OUTPUT ${OBJFILE_COMPILE} + COMMAND ${CMAKE_CXX_COMPILER} + ARGS ${CLANG_ARGS} ${INFILE} "-o" ${OBJFILE} + DEPENDS ${INFILE} + BYPRODUCTS ${OBJFILE} + COMMENT "Compiling ${source_file}.ll" + VERBATIM + ) + + add_custom_target(${source_file}_compile DEPENDS ${OBJFILE_COMPILE}) + + if (WIN32) + set(QIR_UTILITY_LIB "${CMAKE_CURRENT_BINARY_DIR}/${source_file}-u.lib" ) + else() + set(QIR_UTILITY_LIB "${CMAKE_CURRENT_BINARY_DIR}/lib${source_file}-u.a") + endif() + + add_custom_command(OUTPUT ${QIR_UTILITY_LIB} + COMMAND ${CMAKE_AR} + ARGS "rc" ${QIR_UTILITY_LIB} ${OBJFILE} + DEPENDS ${source_file}_compile ${INFILE} + COMMENT "Creating a lib from ${source_file}.ll" + VERBATIM + ) + + if (NOT ${target} STREQUAL "") + add_custom_target(${target} DEPENDS ${QIR_UTILITY_LIB}) + endif() +endmacro(compile_from_qir) + +macro(target_source_from_qir_obj target_name source_file) + set_source_files_properties( + "${source_file}.obj" + PROPERTIES + EXTERNAL_OBJECT true + ) + target_sources(${target_name} PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/${source_file}.obj" + ) +endmacro() \ No newline at end of file diff --git a/src/QirRuntime/cmake/unit_test_include.cmake b/src/QirRuntime/cmake/unit_test_include.cmake new file mode 100644 index 00000000000..b4ac9de981e --- /dev/null +++ b/src/QirRuntime/cmake/unit_test_include.cmake @@ -0,0 +1,23 @@ +set(test_includes "${PROJECT_SOURCE_DIR}/externals/catch2" "${PROJECT_SOURCE_DIR}/test") + +include(CTest) +macro(add_unit_test target) + add_test( + NAME ${target} + COMMAND ${target} ~[skip] -o "${target}_results.xml" -r junit + ) + + # set the environment path for loading shared libs the tests are using + if(DEFINED ENV{NATIVE_SIMULATOR}) + set(TEST_DEPS1 $ENV{NATIVE_SIMULATOR}) + else() + set(TEST_DEPS1 "${PROJECT_SOURCE_DIR}/../Simulation/native/build/${CMAKE_BUILD_TYPE}") + endif() + + set(TEST_DEPS2 "${CMAKE_BINARY_DIR}/bin") + set_property(TEST ${target} PROPERTY ENVIRONMENT + "LD_LIBRARY_PATH=${TEST_DEPS1}:${TEST_DEPS2}:${LD_LIBRARY_PATH}" + "PATH=${TEST_DEPS1}\;${TEST_DEPS2}\;${PATH}" + "DYLD_LIBRARY_PATH=${TEST_DEPS1}:${TEST_DEPS2}:${DYLD_LIBRARY_PATH}" + ) +endmacro(add_unit_test) diff --git a/src/QirRuntime/externals/CLI11/CLI11.hpp b/src/QirRuntime/externals/CLI11/CLI11.hpp new file mode 100644 index 00000000000..68244d3864d --- /dev/null +++ b/src/QirRuntime/externals/CLI11/CLI11.hpp @@ -0,0 +1,8258 @@ +#pragma once + +// CLI11: Version 1.9.1 +// Originally designed by Henry Schreiner +// https://github.com/CLIUtils/CLI11 +// +// This is a standalone header file generated by MakeSingleHeader.py in CLI11/scripts +// from: v1.9.1 +// +// From LICENSE: +// +// CLI11 1.8 Copyright (c) 2017-2019 University of Cincinnati, developed by Henry +// Schreiner under NSF AWARD 1414736. All rights reserved. +// +// Redistribution and use in source and binary forms of CLI11, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its contributors +// may be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +// Standard combined includes: + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// Verbatim copy from Version.hpp: + + +#define CLI11_VERSION_MAJOR 1 +#define CLI11_VERSION_MINOR 9 +#define CLI11_VERSION_PATCH 1 +#define CLI11_VERSION "1.9.1" + + + + +// Verbatim copy from Macros.hpp: + + +// The following version macro is very similar to the one in PyBind11 +#if !(defined(_MSC_VER) && __cplusplus == 199711L) && !defined(__INTEL_COMPILER) +#if __cplusplus >= 201402L +#define CLI11_CPP14 +#if __cplusplus >= 201703L +#define CLI11_CPP17 +#if __cplusplus > 201703L +#define CLI11_CPP20 +#endif +#endif +#endif +#elif defined(_MSC_VER) && __cplusplus == 199711L +// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented) +// Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer +#if _MSVC_LANG >= 201402L +#define CLI11_CPP14 +#if _MSVC_LANG > 201402L && _MSC_VER >= 1910 +#define CLI11_CPP17 +#if __MSVC_LANG > 201703L && _MSC_VER >= 1910 +#define CLI11_CPP20 +#endif +#endif +#endif +#endif + +#if defined(CLI11_CPP14) +#define CLI11_DEPRECATED(reason) [[deprecated(reason)]] +#elif defined(_MSC_VER) +#define CLI11_DEPRECATED(reason) __declspec(deprecated(reason)) +#else +#define CLI11_DEPRECATED(reason) __attribute__((deprecated(reason))) +#endif + + + + +// Verbatim copy from Validators.hpp: + + +// C standard library +// Only needed for existence checking +#if defined CLI11_CPP17 && defined __has_include && !defined CLI11_HAS_FILESYSTEM +#if __has_include() +// Filesystem cannot be used if targeting macOS < 10.15 +#if defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 +#define CLI11_HAS_FILESYSTEM 0 +#else +#include +#if defined __cpp_lib_filesystem && __cpp_lib_filesystem >= 201703 +#if defined _GLIBCXX_RELEASE && _GLIBCXX_RELEASE >= 9 +#define CLI11_HAS_FILESYSTEM 1 +#elif defined(__GLIBCXX__) +// if we are using gcc and Version <9 default to no filesystem +#define CLI11_HAS_FILESYSTEM 0 +#else +#define CLI11_HAS_FILESYSTEM 1 +#endif +#else +#define CLI11_HAS_FILESYSTEM 0 +#endif +#endif +#endif +#endif + +#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 +#include // NOLINT(build/include) +#else +#include +#include +#endif + + + +// From Version.hpp: + + + +// From Macros.hpp: + + + +// From StringTools.hpp: + +namespace CLI { + +/// Include the items in this namespace to get free conversion of enums to/from streams. +/// (This is available inside CLI as well, so CLI11 will use this without a using statement). +namespace enums { + +/// output streaming for enumerations +template ::value>::type> +std::ostream &operator<<(std::ostream &in, const T &item) { + // make sure this is out of the detail namespace otherwise it won't be found when needed + return in << static_cast::type>(item); +} + +} // namespace enums + +/// Export to CLI namespace +using enums::operator<<; + +namespace detail { +/// a constant defining an expected max vector size defined to be a big number that could be multiplied by 4 and not +/// produce overflow for some expected uses +constexpr int expected_max_vector_size{1 << 29}; +// Based on http://stackoverflow.com/questions/236129/split-a-string-in-c +/// Split a string by a delim +inline std::vector split(const std::string &s, char delim) { + std::vector elems; + // Check to see if empty string, give consistent result + if(s.empty()) { + elems.emplace_back(); + } else { + std::stringstream ss; + ss.str(s); + std::string item; + while(std::getline(ss, item, delim)) { + elems.push_back(item); + } + } + return elems; +} + +/// Simple function to join a string +template std::string join(const T &v, std::string delim = ",") { + std::ostringstream s; + auto beg = std::begin(v); + auto end = std::end(v); + if(beg != end) + s << *beg++; + while(beg != end) { + s << delim << *beg++; + } + return s.str(); +} + +/// Simple function to join a string from processed elements +template ::value>::type> +std::string join(const T &v, Callable func, std::string delim = ",") { + std::ostringstream s; + auto beg = std::begin(v); + auto end = std::end(v); + if(beg != end) + s << func(*beg++); + while(beg != end) { + s << delim << func(*beg++); + } + return s.str(); +} + +/// Join a string in reverse order +template std::string rjoin(const T &v, std::string delim = ",") { + std::ostringstream s; + for(std::size_t start = 0; start < v.size(); start++) { + if(start > 0) + s << delim; + s << v[v.size() - start - 1]; + } + return s.str(); +} + +// Based roughly on http://stackoverflow.com/questions/25829143/c-trim-whitespace-from-a-string + +/// Trim whitespace from left of string +inline std::string <rim(std::string &str) { + auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace(ch, std::locale()); }); + str.erase(str.begin(), it); + return str; +} + +/// Trim anything from left of string +inline std::string <rim(std::string &str, const std::string &filter) { + auto it = std::find_if(str.begin(), str.end(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); + str.erase(str.begin(), it); + return str; +} + +/// Trim whitespace from right of string +inline std::string &rtrim(std::string &str) { + auto it = std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace(ch, std::locale()); }); + str.erase(it.base(), str.end()); + return str; +} + +/// Trim anything from right of string +inline std::string &rtrim(std::string &str, const std::string &filter) { + auto it = + std::find_if(str.rbegin(), str.rend(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); + str.erase(it.base(), str.end()); + return str; +} + +/// Trim whitespace from string +inline std::string &trim(std::string &str) { return ltrim(rtrim(str)); } + +/// Trim anything from string +inline std::string &trim(std::string &str, const std::string filter) { return ltrim(rtrim(str, filter), filter); } + +/// Make a copy of the string and then trim it +inline std::string trim_copy(const std::string &str) { + std::string s = str; + return trim(s); +} + +/// remove quotes at the front and back of a string either '"' or '\'' +inline std::string &remove_quotes(std::string &str) { + if(str.length() > 1 && (str.front() == '"' || str.front() == '\'')) { + if(str.front() == str.back()) { + str.pop_back(); + str.erase(str.begin(), str.begin() + 1); + } + } + return str; +} + +/// Make a copy of the string and then trim it, any filter string can be used (any char in string is filtered) +inline std::string trim_copy(const std::string &str, const std::string &filter) { + std::string s = str; + return trim(s, filter); +} +/// Print a two part "help" string +inline std::ostream &format_help(std::ostream &out, std::string name, std::string description, std::size_t wid) { + name = " " + name; + out << std::setw(static_cast(wid)) << std::left << name; + if(!description.empty()) { + if(name.length() >= wid) + out << "\n" << std::setw(static_cast(wid)) << ""; + for(const char c : description) { + out.put(c); + if(c == '\n') { + out << std::setw(static_cast(wid)) << ""; + } + } + } + out << "\n"; + return out; +} + +/// Verify the first character of an option +template bool valid_first_char(T c) { + return std::isalnum(c, std::locale()) || c == '_' || c == '?' || c == '@'; +} + +/// Verify following characters of an option +template bool valid_later_char(T c) { return valid_first_char(c) || c == '.' || c == '-'; } + +/// Verify an option name +inline bool valid_name_string(const std::string &str) { + if(str.empty() || !valid_first_char(str[0])) + return false; + for(auto c : str.substr(1)) + if(!valid_later_char(c)) + return false; + return true; +} + +/// Verify that str consists of letters only +inline bool isalpha(const std::string &str) { + return std::all_of(str.begin(), str.end(), [](char c) { return std::isalpha(c, std::locale()); }); +} + +/// Return a lower case version of a string +inline std::string to_lower(std::string str) { + std::transform(std::begin(str), std::end(str), std::begin(str), [](const std::string::value_type &x) { + return std::tolower(x, std::locale()); + }); + return str; +} + +/// remove underscores from a string +inline std::string remove_underscore(std::string str) { + str.erase(std::remove(std::begin(str), std::end(str), '_'), std::end(str)); + return str; +} + +/// Find and replace a substring with another substring +inline std::string find_and_replace(std::string str, std::string from, std::string to) { + + std::size_t start_pos = 0; + + while((start_pos = str.find(from, start_pos)) != std::string::npos) { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); + } + + return str; +} + +/// check if the flag definitions has possible false flags +inline bool has_default_flag_values(const std::string &flags) { + return (flags.find_first_of("{!") != std::string::npos); +} + +inline void remove_default_flag_values(std::string &flags) { + auto loc = flags.find_first_of('{'); + while(loc != std::string::npos) { + auto finish = flags.find_first_of("},", loc + 1); + if((finish != std::string::npos) && (flags[finish] == '}')) { + flags.erase(flags.begin() + static_cast(loc), + flags.begin() + static_cast(finish) + 1); + } + loc = flags.find_first_of('{', loc + 1); + } + flags.erase(std::remove(flags.begin(), flags.end(), '!'), flags.end()); +} + +/// Check if a string is a member of a list of strings and optionally ignore case or ignore underscores +inline std::ptrdiff_t find_member(std::string name, + const std::vector names, + bool ignore_case = false, + bool ignore_underscore = false) { + auto it = std::end(names); + if(ignore_case) { + if(ignore_underscore) { + name = detail::to_lower(detail::remove_underscore(name)); + it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { + return detail::to_lower(detail::remove_underscore(local_name)) == name; + }); + } else { + name = detail::to_lower(name); + it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { + return detail::to_lower(local_name) == name; + }); + } + + } else if(ignore_underscore) { + name = detail::remove_underscore(name); + it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { + return detail::remove_underscore(local_name) == name; + }); + } else { + it = std::find(std::begin(names), std::end(names), name); + } + + return (it != std::end(names)) ? (it - std::begin(names)) : (-1); +} + +/// Find a trigger string and call a modify callable function that takes the current string and starting position of the +/// trigger and returns the position in the string to search for the next trigger string +template inline std::string find_and_modify(std::string str, std::string trigger, Callable modify) { + std::size_t start_pos = 0; + while((start_pos = str.find(trigger, start_pos)) != std::string::npos) { + start_pos = modify(str, start_pos); + } + return str; +} + +/// Split a string '"one two" "three"' into 'one two', 'three' +/// Quote characters can be ` ' or " +inline std::vector split_up(std::string str, char delimiter = '\0') { + + const std::string delims("\'\"`"); + auto find_ws = [delimiter](char ch) { + return (delimiter == '\0') ? (std::isspace(ch, std::locale()) != 0) : (ch == delimiter); + }; + trim(str); + + std::vector output; + bool embeddedQuote = false; + char keyChar = ' '; + while(!str.empty()) { + if(delims.find_first_of(str[0]) != std::string::npos) { + keyChar = str[0]; + auto end = str.find_first_of(keyChar, 1); + while((end != std::string::npos) && (str[end - 1] == '\\')) { // deal with escaped quotes + end = str.find_first_of(keyChar, end + 1); + embeddedQuote = true; + } + if(end != std::string::npos) { + output.push_back(str.substr(1, end - 1)); + str = str.substr(end + 1); + } else { + output.push_back(str.substr(1)); + str = ""; + } + } else { + auto it = std::find_if(std::begin(str), std::end(str), find_ws); + if(it != std::end(str)) { + std::string value = std::string(str.begin(), it); + output.push_back(value); + str = std::string(it + 1, str.end()); + } else { + output.push_back(str); + str = ""; + } + } + // transform any embedded quotes into the regular character + if(embeddedQuote) { + output.back() = find_and_replace(output.back(), std::string("\\") + keyChar, std::string(1, keyChar)); + embeddedQuote = false; + } + trim(str); + } + return output; +} + +/// Add a leader to the beginning of all new lines (nothing is added +/// at the start of the first line). `"; "` would be for ini files +/// +/// Can't use Regex, or this would be a subs. +inline std::string fix_newlines(const std::string &leader, std::string input) { + std::string::size_type n = 0; + while(n != std::string::npos && n < input.size()) { + n = input.find('\n', n); + if(n != std::string::npos) { + input = input.substr(0, n + 1) + leader + input.substr(n + 1); + n += leader.size(); + } + } + return input; +} + +/// This function detects an equal or colon followed by an escaped quote after an argument +/// then modifies the string to replace the equality with a space. This is needed +/// to allow the split up function to work properly and is intended to be used with the find_and_modify function +/// the return value is the offset+1 which is required by the find_and_modify function. +inline std::size_t escape_detect(std::string &str, std::size_t offset) { + auto next = str[offset + 1]; + if((next == '\"') || (next == '\'') || (next == '`')) { + auto astart = str.find_last_of("-/ \"\'`", offset - 1); + if(astart != std::string::npos) { + if(str[astart] == ((str[offset] == '=') ? '-' : '/')) + str[offset] = ' '; // interpret this as a space so the split_up works properly + } + } + return offset + 1; +} + +/// Add quotes if the string contains spaces +inline std::string &add_quotes_if_needed(std::string &str) { + if((str.front() != '"' && str.front() != '\'') || str.front() != str.back()) { + char quote = str.find('"') < str.find('\'') ? '\'' : '"'; + if(str.find(' ') != std::string::npos) { + str.insert(0, 1, quote); + str.append(1, quote); + } + } + return str; +} + +} // namespace detail + +} // namespace CLI + +// From Error.hpp: + +namespace CLI { + +// Use one of these on all error classes. +// These are temporary and are undef'd at the end of this file. +#define CLI11_ERROR_DEF(parent, name) \ + protected: \ + name(std::string ename, std::string msg, int exit_code) : parent(std::move(ename), std::move(msg), exit_code) {} \ + name(std::string ename, std::string msg, ExitCodes exit_code) \ + : parent(std::move(ename), std::move(msg), exit_code) {} \ + \ + public: \ + name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \ + name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {} + +// This is added after the one above if a class is used directly and builds its own message +#define CLI11_ERROR_SIMPLE(name) \ + explicit name(std::string msg) : name(#name, msg, ExitCodes::name) {} + +/// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, +/// int values from e.get_error_code(). +enum class ExitCodes { + Success = 0, + IncorrectConstruction = 100, + BadNameString, + OptionAlreadyAdded, + FileError, + ConversionError, + ValidationError, + RequiredError, + RequiresError, + ExcludesError, + ExtrasError, + ConfigError, + InvalidError, + HorribleError, + OptionNotFound, + ArgumentMismatch, + BaseClass = 127 +}; + +// Error definitions + +/// @defgroup error_group Errors +/// @brief Errors thrown by CLI11 +/// +/// These are the errors that can be thrown. Some of them, like CLI::Success, are not really errors. +/// @{ + +/// All errors derive from this one +class Error : public std::runtime_error { + int actual_exit_code; + std::string error_name{"Error"}; + + public: + int get_exit_code() const { return actual_exit_code; } + + std::string get_name() const { return error_name; } + + Error(std::string name, std::string msg, int exit_code = static_cast(ExitCodes::BaseClass)) + : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {} + + Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast(exit_code)) {} +}; + +// Note: Using Error::Error constructors does not work on GCC 4.7 + +/// Construction errors (not in parsing) +class ConstructionError : public Error { + CLI11_ERROR_DEF(Error, ConstructionError) +}; + +/// Thrown when an option is set to conflicting values (non-vector and multi args, for example) +class IncorrectConstruction : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, IncorrectConstruction) + CLI11_ERROR_SIMPLE(IncorrectConstruction) + static IncorrectConstruction PositionalFlag(std::string name) { + return IncorrectConstruction(name + ": Flags cannot be positional"); + } + static IncorrectConstruction Set0Opt(std::string name) { + return IncorrectConstruction(name + ": Cannot set 0 expected, use a flag instead"); + } + static IncorrectConstruction SetFlag(std::string name) { + return IncorrectConstruction(name + ": Cannot set an expected number for flags"); + } + static IncorrectConstruction ChangeNotVector(std::string name) { + return IncorrectConstruction(name + ": You can only change the expected arguments for vectors"); + } + static IncorrectConstruction AfterMultiOpt(std::string name) { + return IncorrectConstruction( + name + ": You can't change expected arguments after you've changed the multi option policy!"); + } + static IncorrectConstruction MissingOption(std::string name) { + return IncorrectConstruction("Option " + name + " is not defined"); + } + static IncorrectConstruction MultiOptionPolicy(std::string name) { + return IncorrectConstruction(name + ": multi_option_policy only works for flags and exact value options"); + } +}; + +/// Thrown on construction of a bad name +class BadNameString : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, BadNameString) + CLI11_ERROR_SIMPLE(BadNameString) + static BadNameString OneCharName(std::string name) { return BadNameString("Invalid one char name: " + name); } + static BadNameString BadLongName(std::string name) { return BadNameString("Bad long name: " + name); } + static BadNameString DashesOnly(std::string name) { + return BadNameString("Must have a name, not just dashes: " + name); + } + static BadNameString MultiPositionalNames(std::string name) { + return BadNameString("Only one positional name allowed, remove: " + name); + } +}; + +/// Thrown when an option already exists +class OptionAlreadyAdded : public ConstructionError { + CLI11_ERROR_DEF(ConstructionError, OptionAlreadyAdded) + explicit OptionAlreadyAdded(std::string name) + : OptionAlreadyAdded(name + " is already added", ExitCodes::OptionAlreadyAdded) {} + static OptionAlreadyAdded Requires(std::string name, std::string other) { + return OptionAlreadyAdded(name + " requires " + other, ExitCodes::OptionAlreadyAdded); + } + static OptionAlreadyAdded Excludes(std::string name, std::string other) { + return OptionAlreadyAdded(name + " excludes " + other, ExitCodes::OptionAlreadyAdded); + } +}; + +// Parsing errors + +/// Anything that can error in Parse +class ParseError : public Error { + CLI11_ERROR_DEF(Error, ParseError) +}; + +// Not really "errors" + +/// This is a successful completion on parsing, supposed to exit +class Success : public ParseError { + CLI11_ERROR_DEF(ParseError, Success) + Success() : Success("Successfully completed, should be caught and quit", ExitCodes::Success) {} +}; + +/// -h or --help on command line +class CallForHelp : public ParseError { + CLI11_ERROR_DEF(ParseError, CallForHelp) + CallForHelp() : CallForHelp("This should be caught in your main function, see examples", ExitCodes::Success) {} +}; + +/// Usually something like --help-all on command line +class CallForAllHelp : public ParseError { + CLI11_ERROR_DEF(ParseError, CallForAllHelp) + CallForAllHelp() + : CallForAllHelp("This should be caught in your main function, see examples", ExitCodes::Success) {} +}; + +/// Does not output a diagnostic in CLI11_PARSE, but allows to return from main() with a specific error code. +class RuntimeError : public ParseError { + CLI11_ERROR_DEF(ParseError, RuntimeError) + explicit RuntimeError(int exit_code = 1) : RuntimeError("Runtime error", exit_code) {} +}; + +/// Thrown when parsing an INI file and it is missing +class FileError : public ParseError { + CLI11_ERROR_DEF(ParseError, FileError) + CLI11_ERROR_SIMPLE(FileError) + static FileError Missing(std::string name) { return FileError(name + " was not readable (missing?)"); } +}; + +/// Thrown when conversion call back fails, such as when an int fails to coerce to a string +class ConversionError : public ParseError { + CLI11_ERROR_DEF(ParseError, ConversionError) + CLI11_ERROR_SIMPLE(ConversionError) + ConversionError(std::string member, std::string name) + : ConversionError("The value " + member + " is not an allowed value for " + name) {} + ConversionError(std::string name, std::vector results) + : ConversionError("Could not convert: " + name + " = " + detail::join(results)) {} + static ConversionError TooManyInputsFlag(std::string name) { + return ConversionError(name + ": too many inputs for a flag"); + } + static ConversionError TrueFalse(std::string name) { + return ConversionError(name + ": Should be true/false or a number"); + } +}; + +/// Thrown when validation of results fails +class ValidationError : public ParseError { + CLI11_ERROR_DEF(ParseError, ValidationError) + CLI11_ERROR_SIMPLE(ValidationError) + explicit ValidationError(std::string name, std::string msg) : ValidationError(name + ": " + msg) {} +}; + +/// Thrown when a required option is missing +class RequiredError : public ParseError { + CLI11_ERROR_DEF(ParseError, RequiredError) + explicit RequiredError(std::string name) : RequiredError(name + " is required", ExitCodes::RequiredError) {} + static RequiredError Subcommand(std::size_t min_subcom) { + if(min_subcom == 1) { + return RequiredError("A subcommand"); + } + return RequiredError("Requires at least " + std::to_string(min_subcom) + " subcommands", + ExitCodes::RequiredError); + } + static RequiredError + Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list) { + if((min_option == 1) && (max_option == 1) && (used == 0)) + return RequiredError("Exactly 1 option from [" + option_list + "]"); + if((min_option == 1) && (max_option == 1) && (used > 1)) { + return RequiredError("Exactly 1 option from [" + option_list + "] is required and " + std::to_string(used) + + " were given", + ExitCodes::RequiredError); + } + if((min_option == 1) && (used == 0)) + return RequiredError("At least 1 option from [" + option_list + "]"); + if(used < min_option) { + return RequiredError("Requires at least " + std::to_string(min_option) + " options used and only " + + std::to_string(used) + "were given from [" + option_list + "]", + ExitCodes::RequiredError); + } + if(max_option == 1) + return RequiredError("Requires at most 1 options be given from [" + option_list + "]", + ExitCodes::RequiredError); + + return RequiredError("Requires at most " + std::to_string(max_option) + " options be used and " + + std::to_string(used) + "were given from [" + option_list + "]", + ExitCodes::RequiredError); + } +}; + +/// Thrown when the wrong number of arguments has been received +class ArgumentMismatch : public ParseError { + CLI11_ERROR_DEF(ParseError, ArgumentMismatch) + CLI11_ERROR_SIMPLE(ArgumentMismatch) + ArgumentMismatch(std::string name, int expected, std::size_t received) + : ArgumentMismatch(expected > 0 ? ("Expected exactly " + std::to_string(expected) + " arguments to " + name + + ", got " + std::to_string(received)) + : ("Expected at least " + std::to_string(-expected) + " arguments to " + name + + ", got " + std::to_string(received)), + ExitCodes::ArgumentMismatch) {} + + static ArgumentMismatch AtLeast(std::string name, int num, std::size_t received) { + return ArgumentMismatch(name + ": At least " + std::to_string(num) + " required but received " + + std::to_string(received)); + } + static ArgumentMismatch AtMost(std::string name, int num, std::size_t received) { + return ArgumentMismatch(name + ": At Most " + std::to_string(num) + " required but received " + + std::to_string(received)); + } + static ArgumentMismatch TypedAtLeast(std::string name, int num, std::string type) { + return ArgumentMismatch(name + ": " + std::to_string(num) + " required " + type + " missing"); + } + static ArgumentMismatch FlagOverride(std::string name) { + return ArgumentMismatch(name + " was given a disallowed flag override"); + } +}; + +/// Thrown when a requires option is missing +class RequiresError : public ParseError { + CLI11_ERROR_DEF(ParseError, RequiresError) + RequiresError(std::string curname, std::string subname) + : RequiresError(curname + " requires " + subname, ExitCodes::RequiresError) {} +}; + +/// Thrown when an excludes option is present +class ExcludesError : public ParseError { + CLI11_ERROR_DEF(ParseError, ExcludesError) + ExcludesError(std::string curname, std::string subname) + : ExcludesError(curname + " excludes " + subname, ExitCodes::ExcludesError) {} +}; + +/// Thrown when too many positionals or options are found +class ExtrasError : public ParseError { + CLI11_ERROR_DEF(ParseError, ExtrasError) + explicit ExtrasError(std::vector args) + : ExtrasError((args.size() > 1 ? "The following arguments were not expected: " + : "The following argument was not expected: ") + + detail::rjoin(args, " "), + ExitCodes::ExtrasError) {} + ExtrasError(const std::string &name, std::vector args) + : ExtrasError(name, + (args.size() > 1 ? "The following arguments were not expected: " + : "The following argument was not expected: ") + + detail::rjoin(args, " "), + ExitCodes::ExtrasError) {} +}; + +/// Thrown when extra values are found in an INI file +class ConfigError : public ParseError { + CLI11_ERROR_DEF(ParseError, ConfigError) + CLI11_ERROR_SIMPLE(ConfigError) + static ConfigError Extras(std::string item) { return ConfigError("INI was not able to parse " + item); } + static ConfigError NotConfigurable(std::string item) { + return ConfigError(item + ": This option is not allowed in a configuration file"); + } +}; + +/// Thrown when validation fails before parsing +class InvalidError : public ParseError { + CLI11_ERROR_DEF(ParseError, InvalidError) + explicit InvalidError(std::string name) + : InvalidError(name + ": Too many positional arguments with unlimited expected args", ExitCodes::InvalidError) { + } +}; + +/// This is just a safety check to verify selection and parsing match - you should not ever see it +/// Strings are directly added to this error, but again, it should never be seen. +class HorribleError : public ParseError { + CLI11_ERROR_DEF(ParseError, HorribleError) + CLI11_ERROR_SIMPLE(HorribleError) +}; + +// After parsing + +/// Thrown when counting a non-existent option +class OptionNotFound : public Error { + CLI11_ERROR_DEF(Error, OptionNotFound) + explicit OptionNotFound(std::string name) : OptionNotFound(name + " not found", ExitCodes::OptionNotFound) {} +}; + +#undef CLI11_ERROR_DEF +#undef CLI11_ERROR_SIMPLE + +/// @} + +} // namespace CLI + +// From TypeTools.hpp: + +namespace CLI { + +// Type tools + +// Utilities for type enabling +namespace detail { +// Based generally on https://rmf.io/cxx11/almost-static-if +/// Simple empty scoped class +enum class enabler {}; + +/// An instance to use in EnableIf +constexpr enabler dummy = {}; +} // namespace detail + +/// A copy of enable_if_t from C++14, compatible with C++11. +/// +/// We could check to see if C++14 is being used, but it does not hurt to redefine this +/// (even Google does this: https://github.com/google/skia/blob/master/include/private/SkTLogic.h) +/// It is not in the std namespace anyway, so no harm done. +template using enable_if_t = typename std::enable_if::type; + +/// A copy of std::void_t from C++17 (helper for C++11 and C++14) +template struct make_void { using type = void; }; + +/// A copy of std::void_t from C++17 - same reasoning as enable_if_t, it does not hurt to redefine +template using void_t = typename make_void::type; + +/// A copy of std::conditional_t from C++14 - same reasoning as enable_if_t, it does not hurt to redefine +template using conditional_t = typename std::conditional::type; + +/// Check to see if something is a vector (fail check by default) +template struct is_vector : std::false_type {}; + +/// Check to see if something is a vector (true if actually a vector) +template struct is_vector> : std::true_type {}; + +/// Check to see if something is a vector (true if actually a const vector) +template struct is_vector> : std::true_type {}; + +/// Check to see if something is bool (fail check by default) +template struct is_bool : std::false_type {}; + +/// Check to see if something is bool (true if actually a bool) +template <> struct is_bool : std::true_type {}; + +/// Check to see if something is a shared pointer +template struct is_shared_ptr : std::false_type {}; + +/// Check to see if something is a shared pointer (True if really a shared pointer) +template struct is_shared_ptr> : std::true_type {}; + +/// Check to see if something is a shared pointer (True if really a shared pointer) +template struct is_shared_ptr> : std::true_type {}; + +/// Check to see if something is copyable pointer +template struct is_copyable_ptr { + static bool const value = is_shared_ptr::value || std::is_pointer::value; +}; + +/// This can be specialized to override the type deduction for IsMember. +template struct IsMemberType { using type = T; }; + +/// The main custom type needed here is const char * should be a string. +template <> struct IsMemberType { using type = std::string; }; + +namespace detail { + +// These are utilities for IsMember and other transforming objects + +/// Handy helper to access the element_type generically. This is not part of is_copyable_ptr because it requires that +/// pointer_traits be valid. + +/// not a pointer +template struct element_type { using type = T; }; + +template struct element_type::value>::type> { + using type = typename std::pointer_traits::element_type; +}; + +/// Combination of the element type and value type - remove pointer (including smart pointers) and get the value_type of +/// the container +template struct element_value_type { using type = typename element_type::type::value_type; }; + +/// Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost nothing. +template struct pair_adaptor : std::false_type { + using value_type = typename T::value_type; + using first_type = typename std::remove_const::type; + using second_type = typename std::remove_const::type; + + /// Get the first value (really just the underlying value) + template static auto first(Q &&pair_value) -> decltype(std::forward(pair_value)) { + return std::forward(pair_value); + } + /// Get the second value (really just the underlying value) + template static auto second(Q &&pair_value) -> decltype(std::forward(pair_value)) { + return std::forward(pair_value); + } +}; + +/// Adaptor for map-like structure (true version, must have key_type and mapped_type). +/// This wraps a mapped container in a few utilities access it in a general way. +template +struct pair_adaptor< + T, + conditional_t, void>> + : std::true_type { + using value_type = typename T::value_type; + using first_type = typename std::remove_const::type; + using second_type = typename std::remove_const::type; + + /// Get the first value (really just the underlying value) + template static auto first(Q &&pair_value) -> decltype(std::get<0>(std::forward(pair_value))) { + return std::get<0>(std::forward(pair_value)); + } + /// Get the second value (really just the underlying value) + template static auto second(Q &&pair_value) -> decltype(std::get<1>(std::forward(pair_value))) { + return std::get<1>(std::forward(pair_value)); + } +}; + +// Warning is suppressed due to "bug" in gcc<5.0 and gcc 7.0 with c++17 enabled that generates a Wnarrowing warning +// in the unevaluated context even if the function that was using this wasn't used. The standard says narrowing in +// brace initialization shouldn't be allowed but for backwards compatibility gcc allows it in some contexts. It is a +// little fuzzy what happens in template constructs and I think that was something GCC took a little while to work out. +// But regardless some versions of gcc generate a warning when they shouldn't from the following code so that should be +// suppressed +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnarrowing" +#endif +// check for constructibility from a specific type and copy assignable used in the parse detection +template class is_direct_constructible { + template + static auto test(int, std::true_type) -> decltype( +// NVCC warns about narrowing conversions here +#ifdef __CUDACC__ +#pragma diag_suppress 2361 +#endif + TT { std::declval() } +#ifdef __CUDACC__ +#pragma diag_default 2361 +#endif + , + std::is_move_assignable()); + + template static auto test(int, std::false_type) -> std::false_type; + + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0, typename std::is_constructible::type()))::value; +}; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + +// Check for output streamability +// Based on https://stackoverflow.com/questions/22758291/how-can-i-detect-if-a-type-can-be-streamed-to-an-stdostream + +template class is_ostreamable { + template + static auto test(int) -> decltype(std::declval() << std::declval(), std::true_type()); + + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0))::value; +}; + +/// Check for input streamability +template class is_istreamable { + template + static auto test(int) -> decltype(std::declval() >> std::declval(), std::true_type()); + + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0))::value; +}; + +/// Templated operation to get a value from a stream +template ::value, detail::enabler> = detail::dummy> +bool from_stream(const std::string &istring, T &obj) { + std::istringstream is; + is.str(istring); + is >> obj; + return !is.fail() && !is.rdbuf()->in_avail(); +} + +template ::value, detail::enabler> = detail::dummy> +bool from_stream(const std::string & /*istring*/, T & /*obj*/) { + return false; +} + +// Check for tuple like types, as in classes with a tuple_size type trait +template class is_tuple_like { + template + // static auto test(int) + // -> decltype(std::conditional<(std::tuple_size::value > 0), std::true_type, std::false_type>::type()); + static auto test(int) -> decltype(std::tuple_size::value, std::true_type{}); + template static auto test(...) -> std::false_type; + + public: + static constexpr bool value = decltype(test(0))::value; +}; + +/// Convert an object to a string (directly forward if this can become a string) +template ::value, detail::enabler> = detail::dummy> +auto to_string(T &&value) -> decltype(std::forward(value)) { + return std::forward(value); +} + +/// Construct a string from the object +template ::value && !std::is_convertible::value, + detail::enabler> = detail::dummy> +std::string to_string(const T &value) { + return std::string(value); +} + +/// Convert an object to a string (streaming must be supported for that type) +template ::value && !std::is_constructible::value && + is_ostreamable::value, + detail::enabler> = detail::dummy> +std::string to_string(T &&value) { + std::stringstream stream; + stream << value; + return stream.str(); +} + +/// If conversion is not supported, return an empty string (streaming is not supported for that type) +template ::value && !is_ostreamable::value && + !is_vector::type>::type>::value, + detail::enabler> = detail::dummy> +std::string to_string(T &&) { + return std::string{}; +} + +/// convert a vector to a string +template ::value && !is_ostreamable::value && + is_vector::type>::type>::value, + detail::enabler> = detail::dummy> +std::string to_string(T &&variable) { + std::vector defaults; + defaults.reserve(variable.size()); + auto cval = variable.begin(); + auto end = variable.end(); + while(cval != end) { + defaults.emplace_back(CLI::detail::to_string(*cval)); + ++cval; + } + return std::string("[" + detail::join(defaults) + "]"); +} + +/// special template overload +template ::value, detail::enabler> = detail::dummy> +auto checked_to_string(T &&value) -> decltype(to_string(std::forward(value))) { + return to_string(std::forward(value)); +} + +/// special template overload +template ::value, detail::enabler> = detail::dummy> +std::string checked_to_string(T &&) { + return std::string{}; +} +/// get a string as a convertible value for arithmetic types +template ::value, detail::enabler> = detail::dummy> +std::string value_string(const T &value) { + return std::to_string(value); +} +/// get a string as a convertible value for enumerations +template ::value, detail::enabler> = detail::dummy> +std::string value_string(const T &value) { + return std::to_string(static_cast::type>(value)); +} +/// for other types just use the regular to_string function +template ::value && !std::is_arithmetic::value, detail::enabler> = detail::dummy> +auto value_string(const T &value) -> decltype(to_string(value)) { + return to_string(value); +} + +/// This will only trigger for actual void type +template struct type_count { static const int value{0}; }; + +/// Set of overloads to get the type size of an object +template struct type_count::value>::type> { + static constexpr int value{std::tuple_size::value}; +}; +/// Type size for regular object types that do not look like a tuple +template +struct type_count< + T, + typename std::enable_if::value && !is_tuple_like::value && !std::is_void::value>::type> { + static constexpr int value{1}; +}; + +/// Type size of types that look like a vector +template struct type_count::value>::type> { + static constexpr int value{is_vector::value ? expected_max_vector_size + : type_count::value}; +}; + +/// This will only trigger for actual void type +template struct expected_count { static const int value{0}; }; + +/// For most types the number of expected items is 1 +template +struct expected_count::value && !std::is_void::value>::type> { + static constexpr int value{1}; +}; +/// number of expected items in a vector +template struct expected_count::value>::type> { + static constexpr int value{expected_max_vector_size}; +}; + +// Enumeration of the different supported categorizations of objects +enum class object_category : int { + integral_value = 2, + unsigned_integral = 4, + enumeration = 6, + boolean_value = 8, + floating_point = 10, + number_constructible = 12, + double_constructible = 14, + integer_constructible = 16, + vector_value = 30, + tuple_value = 35, + // string assignable or greater used in a condition so anything string like must come last + string_assignable = 50, + string_constructible = 60, + other = 200, + +}; + +/// some type that is not otherwise recognized +template struct classify_object { + static constexpr object_category value{object_category::other}; +}; + +/// Set of overloads to classify an object according to type +template +struct classify_object::value && std::is_signed::value && + !is_bool::value && !std::is_enum::value>::type> { + static constexpr object_category value{object_category::integral_value}; +}; + +/// Unsigned integers +template +struct classify_object< + T, + typename std::enable_if::value && std::is_unsigned::value && !is_bool::value>::type> { + static constexpr object_category value{object_category::unsigned_integral}; +}; + +/// Boolean values +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::boolean_value}; +}; + +/// Floats +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::floating_point}; +}; + +/// String and similar direct assignment +template +struct classify_object< + T, + typename std::enable_if::value && !std::is_integral::value && + std::is_assignable::value && !is_vector::value>::type> { + static constexpr object_category value{object_category::string_assignable}; +}; + +/// String and similar constructible and copy assignment +template +struct classify_object< + T, + typename std::enable_if::value && !std::is_integral::value && + !std::is_assignable::value && + std::is_constructible::value && !is_vector::value>::type> { + static constexpr object_category value{object_category::string_constructible}; +}; + +/// Enumerations +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::enumeration}; +}; + +/// Handy helper to contain a bunch of checks that rule out many common types (integers, string like, floating point, +/// vectors, and enumerations +template struct uncommon_type { + using type = typename std::conditional::value && !std::is_integral::value && + !std::is_assignable::value && + !std::is_constructible::value && !is_vector::value && + !std::is_enum::value, + std::true_type, + std::false_type>::type; + static constexpr bool value = type::value; +}; + +/// Assignable from double or int +template +struct classify_object::value && type_count::value == 1 && + is_direct_constructible::value && + is_direct_constructible::value>::type> { + static constexpr object_category value{object_category::number_constructible}; +}; + +/// Assignable from int +template +struct classify_object::value && type_count::value == 1 && + !is_direct_constructible::value && + is_direct_constructible::value>::type> { + static constexpr object_category value{object_category::integer_constructible}; +}; + +/// Assignable from double +template +struct classify_object::value && type_count::value == 1 && + is_direct_constructible::value && + !is_direct_constructible::value>::type> { + static constexpr object_category value{object_category::double_constructible}; +}; + +/// Tuple type +template +struct classify_object::value >= 2 && !is_vector::value) || + (is_tuple_like::value && uncommon_type::value && + !is_direct_constructible::value && + !is_direct_constructible::value)>::type> { + static constexpr object_category value{object_category::tuple_value}; +}; + +/// Vector type +template struct classify_object::value>::type> { + static constexpr object_category value{object_category::vector_value}; +}; + +// Type name print + +/// Was going to be based on +/// http://stackoverflow.com/questions/1055452/c-get-name-of-type-in-template +/// But this is cleaner and works better in this case + +template ::value == object_category::integral_value || + classify_object::value == object_category::integer_constructible, + detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "INT"; +} + +template ::value == object_category::unsigned_integral, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "UINT"; +} + +template ::value == object_category::floating_point || + classify_object::value == object_category::number_constructible || + classify_object::value == object_category::double_constructible, + detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "FLOAT"; +} + +/// Print name for enumeration types +template ::value == object_category::enumeration, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "ENUM"; +} + +/// Print name for enumeration types +template ::value == object_category::boolean_value, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "BOOLEAN"; +} + +/// Print for all other types +template ::value >= object_category::string_assignable, detail::enabler> = detail::dummy> +constexpr const char *type_name() { + return "TEXT"; +} + +/// Print name for single element tuple types +template ::value == object_category::tuple_value && type_count::value == 1, + detail::enabler> = detail::dummy> +inline std::string type_name() { + return type_name::type>(); +} + +/// Empty string if the index > tuple size +template +inline typename std::enable_if::value, std::string>::type tuple_name() { + return std::string{}; +} + +/// Recursively generate the tuple type name +template + inline typename std::enable_if < I::value, std::string>::type tuple_name() { + std::string str = std::string(type_name::type>()) + ',' + tuple_name(); + if(str.back() == ',') + str.pop_back(); + return str; +} + +/// Print type name for tuples with 2 or more elements +template ::value == object_category::tuple_value && type_count::value >= 2, + detail::enabler> = detail::dummy> +std::string type_name() { + auto tname = std::string(1, '[') + tuple_name(); + tname.push_back(']'); + return tname; +} + +/// This one should not be used normally, since vector types print the internal type +template ::value == object_category::vector_value, detail::enabler> = detail::dummy> +inline std::string type_name() { + return type_name(); +} + +// Lexical cast + +/// Convert a flag into an integer value typically binary flags +inline std::int64_t to_flag_value(std::string val) { + static const std::string trueString("true"); + static const std::string falseString("false"); + if(val == trueString) { + return 1; + } + if(val == falseString) { + return -1; + } + val = detail::to_lower(val); + std::int64_t ret; + if(val.size() == 1) { + if(val[0] >= '1' && val[0] <= '9') { + return (static_cast(val[0]) - '0'); + } + switch(val[0]) { + case '0': + case 'f': + case 'n': + case '-': + ret = -1; + break; + case 't': + case 'y': + case '+': + ret = 1; + break; + default: + throw std::invalid_argument("unrecognized character"); + } + return ret; + } + if(val == trueString || val == "on" || val == "yes" || val == "enable") { + ret = 1; + } else if(val == falseString || val == "off" || val == "no" || val == "disable") { + ret = -1; + } else { + ret = std::stoll(val); + } + return ret; +} + +/// Signed integers +template ::value == object_category::integral_value, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + try { + std::size_t n = 0; + std::int64_t output_ll = std::stoll(input, &n, 0); + output = static_cast(output_ll); + return n == input.size() && static_cast(output) == output_ll; + } catch(const std::invalid_argument &) { + return false; + } catch(const std::out_of_range &) { + return false; + } +} + +/// Unsigned integers +template ::value == object_category::unsigned_integral, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + if(!input.empty() && input.front() == '-') + return false; // std::stoull happily converts negative values to junk without any errors. + + try { + std::size_t n = 0; + std::uint64_t output_ll = std::stoull(input, &n, 0); + output = static_cast(output_ll); + return n == input.size() && static_cast(output) == output_ll; + } catch(const std::invalid_argument &) { + return false; + } catch(const std::out_of_range &) { + return false; + } +} + +/// Boolean values +template ::value == object_category::boolean_value, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + try { + auto out = to_flag_value(input); + output = (out > 0); + return true; + } catch(const std::invalid_argument &) { + return false; + } catch(const std::out_of_range &) { + // if the number is out of the range of a 64 bit value then it is still a number and for this purpose is still + // valid all we care about the sign + output = (input[0] != '-'); + return true; + } +} + +/// Floats +template ::value == object_category::floating_point, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + try { + std::size_t n = 0; + output = static_cast(std::stold(input, &n)); + return n == input.size(); + } catch(const std::invalid_argument &) { + return false; + } catch(const std::out_of_range &) { + return false; + } +} + +/// String and similar direct assignment +template ::value == object_category::string_assignable, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + output = input; + return true; +} + +/// String and similar constructible and copy assignment +template < + typename T, + enable_if_t::value == object_category::string_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + output = T(input); + return true; +} + +/// Enumerations +template ::value == object_category::enumeration, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + typename std::underlying_type::type val; + bool retval = detail::lexical_cast(input, val); + if(!retval) { + return false; + } + output = static_cast(val); + return true; +} + +/// Assignable from double or int +template < + typename T, + enable_if_t::value == object_category::number_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + int val; + if(lexical_cast(input, val)) { + output = T(val); + return true; + } else { + double dval; + if(lexical_cast(input, dval)) { + output = T{dval}; + return true; + } + } + return from_stream(input, output); +} + +/// Assignable from int +template < + typename T, + enable_if_t::value == object_category::integer_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + int val; + if(lexical_cast(input, val)) { + output = T(val); + return true; + } + return from_stream(input, output); +} + +/// Assignable from double +template < + typename T, + enable_if_t::value == object_category::double_constructible, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + double val; + if(lexical_cast(input, val)) { + output = T{val}; + return true; + } + return from_stream(input, output); +} + +/// Non-string parsable by a stream +template ::value == object_category::other, detail::enabler> = detail::dummy> +bool lexical_cast(const std::string &input, T &output) { + static_assert(is_istreamable::value, + "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it " + "is convertible from another type use the add_option(...) with XC being the known type"); + return from_stream(input, output); +} + +/// Assign a value through lexical cast operations +template < + typename T, + typename XC, + enable_if_t::value && (classify_object::value == object_category::string_assignable || + classify_object::value == object_category::string_constructible), + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, T &output) { + return lexical_cast(input, output); +} + +/// Assign a value through lexical cast operations +template ::value && classify_object::value != object_category::string_assignable && + classify_object::value != object_category::string_constructible, + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, T &output) { + if(input.empty()) { + output = T{}; + return true; + } + return lexical_cast(input, output); +} + +/// Assign a value converted from a string in lexical cast to the output value directly +template < + typename T, + typename XC, + enable_if_t::value && std::is_assignable::value, detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, T &output) { + XC val{}; + bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true; + if(parse_result) { + output = val; + } + return parse_result; +} + +/// Assign a value from a lexical cast through constructing a value and move assigning it +template ::value && !std::is_assignable::value && + std::is_move_assignable::value, + detail::enabler> = detail::dummy> +bool lexical_assign(const std::string &input, T &output) { + XC val{}; + bool parse_result = input.empty() ? true : lexical_cast(input, val); + if(parse_result) { + output = T(val); // use () form of constructor to allow some implicit conversions + } + return parse_result; +} +/// Lexical conversion if there is only one element +template < + typename T, + typename XC, + enable_if_t::value && !is_tuple_like::value && !is_vector::value && !is_vector::value, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + return lexical_assign(strings[0], output); +} + +/// Lexical conversion if there is only one element but the conversion type is for two call a two element constructor +template ::value == 1 && type_count::value == 2, detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + typename std::tuple_element<0, XC>::type v1; + typename std::tuple_element<1, XC>::type v2; + bool retval = lexical_assign(strings[0], v1); + if(strings.size() > 1) { + retval = retval && lexical_assign(strings[1], v2); + } + if(retval) { + output = T{v1, v2}; + } + return retval; +} + +/// Lexical conversion of a vector types +template ::value == expected_max_vector_size && + expected_count::value == expected_max_vector_size && type_count::value == 1, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + output.clear(); + output.reserve(strings.size()); + for(const auto &elem : strings) { + + output.emplace_back(); + bool retval = lexical_assign(elem, output.back()); + if(!retval) { + return false; + } + } + return (!output.empty()); +} + +/// Lexical conversion of a vector types with type size of two +template ::value == expected_max_vector_size && + expected_count::value == expected_max_vector_size && type_count::value == 2, + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + output.clear(); + for(std::size_t ii = 0; ii < strings.size(); ii += 2) { + + typename std::tuple_element<0, typename XC::value_type>::type v1; + typename std::tuple_element<1, typename XC::value_type>::type v2; + bool retval = lexical_assign(strings[ii], v1); + if(strings.size() > ii + 1) { + retval = retval && lexical_assign(strings[ii + 1], v2); + } + if(retval) { + output.emplace_back(v1, v2); + } else { + return false; + } + } + return (!output.empty()); +} + +/// Conversion to a vector type using a particular single type as the conversion type +template ::value == expected_max_vector_size) && (expected_count::value == 1) && + (type_count::value == 1), + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + bool retval = true; + output.clear(); + output.reserve(strings.size()); + for(const auto &elem : strings) { + + output.emplace_back(); + retval = retval && lexical_assign(elem, output.back()); + } + return (!output.empty()) && retval; +} +// This one is last since it can call other lexical_conversion functions +/// Lexical conversion if there is only one element but the conversion type is a vector +template ::value && !is_vector::value && is_vector::value, detail::enabler> = + detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + + if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) { + XC val; + auto retval = lexical_conversion(strings, val); + output = T{val}; + return retval; + } + output = T{}; + return true; +} + +/// function template for converting tuples if the static Index is greater than the tuple size +template +inline typename std::enable_if= type_count::value, bool>::type tuple_conversion(const std::vector &, + T &) { + return true; +} +/// Tuple conversion operation +template + inline typename std::enable_if < + I::value, bool>::type tuple_conversion(const std::vector &strings, T &output) { + bool retval = true; + if(strings.size() > I) { + retval = retval && lexical_assign::type, + typename std::conditional::value, + typename std::tuple_element::type, + XC>::type>(strings[I], std::get(output)); + } + retval = retval && tuple_conversion(strings, output); + return retval; +} + +/// Conversion for tuples +template ::value, detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + static_assert( + !is_tuple_like::value || type_count::value == type_count::value, + "if the conversion type is defined as a tuple it must be the same size as the type you are converting to"); + return tuple_conversion(strings, output); +} + +/// Lexical conversion of a vector types with type_size >2 +template ::value == expected_max_vector_size && + expected_count::value == expected_max_vector_size && (type_count::value > 2), + detail::enabler> = detail::dummy> +bool lexical_conversion(const std::vector &strings, T &output) { + bool retval = true; + output.clear(); + std::vector temp; + std::size_t ii = 0; + std::size_t icount = 0; + std::size_t xcm = type_count::value; + while(ii < strings.size()) { + temp.push_back(strings[ii]); + ++ii; + ++icount; + if(icount == xcm || temp.back().empty()) { + if(static_cast(xcm) == expected_max_vector_size) { + temp.pop_back(); + } + output.emplace_back(); + retval = retval && lexical_conversion(temp, output.back()); + temp.clear(); + if(!retval) { + return false; + } + icount = 0; + } + } + return retval; +} +/// Sum a vector of flag representations +/// The flag vector produces a series of strings in a vector, simple true is represented by a "1", simple false is +/// by +/// "-1" an if numbers are passed by some fashion they are captured as well so the function just checks for the most +/// common true and false strings then uses stoll to convert the rest for summing +template ::value && std::is_unsigned::value, detail::enabler> = detail::dummy> +void sum_flag_vector(const std::vector &flags, T &output) { + std::int64_t count{0}; + for(auto &flag : flags) { + count += detail::to_flag_value(flag); + } + output = (count > 0) ? static_cast(count) : T{0}; +} + +/// Sum a vector of flag representations +/// The flag vector produces a series of strings in a vector, simple true is represented by a "1", simple false is +/// by +/// "-1" an if numbers are passed by some fashion they are captured as well so the function just checks for the most +/// common true and false strings then uses stoll to convert the rest for summing +template ::value && std::is_signed::value, detail::enabler> = detail::dummy> +void sum_flag_vector(const std::vector &flags, T &output) { + std::int64_t count{0}; + for(auto &flag : flags) { + count += detail::to_flag_value(flag); + } + output = static_cast(count); +} + +} // namespace detail +} // namespace CLI + +// From Split.hpp: + +namespace CLI { +namespace detail { + +// Returns false if not a short option. Otherwise, sets opt name and rest and returns true +inline bool split_short(const std::string ¤t, std::string &name, std::string &rest) { + if(current.size() > 1 && current[0] == '-' && valid_first_char(current[1])) { + name = current.substr(1, 1); + rest = current.substr(2); + return true; + } + return false; +} + +// Returns false if not a long option. Otherwise, sets opt name and other side of = and returns true +inline bool split_long(const std::string ¤t, std::string &name, std::string &value) { + if(current.size() > 2 && current.substr(0, 2) == "--" && valid_first_char(current[2])) { + auto loc = current.find_first_of('='); + if(loc != std::string::npos) { + name = current.substr(2, loc - 2); + value = current.substr(loc + 1); + } else { + name = current.substr(2); + value = ""; + } + return true; + } + return false; +} + +// Returns false if not a windows style option. Otherwise, sets opt name and value and returns true +inline bool split_windows_style(const std::string ¤t, std::string &name, std::string &value) { + if(current.size() > 1 && current[0] == '/' && valid_first_char(current[1])) { + auto loc = current.find_first_of(':'); + if(loc != std::string::npos) { + name = current.substr(1, loc - 1); + value = current.substr(loc + 1); + } else { + name = current.substr(1); + value = ""; + } + return true; + } + return false; +} + +// Splits a string into multiple long and short names +inline std::vector split_names(std::string current) { + std::vector output; + std::size_t val; + while((val = current.find(",")) != std::string::npos) { + output.push_back(trim_copy(current.substr(0, val))); + current = current.substr(val + 1); + } + output.push_back(trim_copy(current)); + return output; +} + +/// extract default flag values either {def} or starting with a ! +inline std::vector> get_default_flag_values(const std::string &str) { + std::vector flags = split_names(str); + flags.erase(std::remove_if(flags.begin(), + flags.end(), + [](const std::string &name) { + return ((name.empty()) || (!(((name.find_first_of('{') != std::string::npos) && + (name.back() == '}')) || + (name[0] == '!')))); + }), + flags.end()); + std::vector> output; + output.reserve(flags.size()); + for(auto &flag : flags) { + auto def_start = flag.find_first_of('{'); + std::string defval = "false"; + if((def_start != std::string::npos) && (flag.back() == '}')) { + defval = flag.substr(def_start + 1); + defval.pop_back(); + flag.erase(def_start, std::string::npos); + } + flag.erase(0, flag.find_first_not_of("-!")); + output.emplace_back(flag, defval); + } + return output; +} + +/// Get a vector of short names, one of long names, and a single name +inline std::tuple, std::vector, std::string> +get_names(const std::vector &input) { + + std::vector short_names; + std::vector long_names; + std::string pos_name; + + for(std::string name : input) { + if(name.length() == 0) { + continue; + } + if(name.length() > 1 && name[0] == '-' && name[1] != '-') { + if(name.length() == 2 && valid_first_char(name[1])) + short_names.emplace_back(1, name[1]); + else + throw BadNameString::OneCharName(name); + } else if(name.length() > 2 && name.substr(0, 2) == "--") { + name = name.substr(2); + if(valid_name_string(name)) + long_names.push_back(name); + else + throw BadNameString::BadLongName(name); + } else if(name == "-" || name == "--") { + throw BadNameString::DashesOnly(name); + } else { + if(pos_name.length() > 0) + throw BadNameString::MultiPositionalNames(name); + pos_name = name; + } + } + + return std::tuple, std::vector, std::string>( + short_names, long_names, pos_name); +} + +} // namespace detail +} // namespace CLI + +// From ConfigFwd.hpp: + +namespace CLI { + +class App; + +/// Holds values to load into Options +struct ConfigItem { + /// This is the list of parents + std::vector parents{}; + + /// This is the name + std::string name{}; + + /// Listing of inputs + std::vector inputs{}; + + /// The list of parents and name joined by "." + std::string fullname() const { + std::vector tmp = parents; + tmp.emplace_back(name); + return detail::join(tmp, "."); + } +}; + +/// This class provides a converter for configuration files. +class Config { + protected: + std::vector items{}; + + public: + /// Convert an app into a configuration + virtual std::string to_config(const App *, bool, bool, std::string) const = 0; + + /// Convert a configuration into an app + virtual std::vector from_config(std::istream &) const = 0; + + /// Get a flag value + virtual std::string to_flag(const ConfigItem &item) const { + if(item.inputs.size() == 1) { + return item.inputs.at(0); + } + throw ConversionError::TooManyInputsFlag(item.fullname()); + } + + /// Parse a config file, throw an error (ParseError:ConfigParseError or FileError) on failure + std::vector from_file(const std::string &name) { + std::ifstream input{name}; + if(!input.good()) + throw FileError::Missing(name); + + return from_config(input); + } + + /// Virtual destructor + virtual ~Config() = default; +}; + +/// This converter works with INI/TOML files; to write proper TOML files use ConfigTOML +class ConfigBase : public Config { + protected: + /// the character used for comments + char commentChar = ';'; + /// the character used to start an array '\0' is a default to not use + char arrayStart = '\0'; + /// the character used to end an array '\0' is a default to not use + char arrayEnd = '\0'; + /// the character used to separate elements in an array + char arraySeparator = ' '; + /// the character used separate the name from the value + char valueDelimiter = '='; + + public: + std::string + to_config(const App * /*app*/, bool default_also, bool write_description, std::string prefix) const override; + + std::vector from_config(std::istream &input) const override; + /// Specify the configuration for comment characters + ConfigBase *comment(char cchar) { + commentChar = cchar; + return this; + } + /// Specify the start and end characters for an array + ConfigBase *arrayBounds(char aStart, char aEnd) { + arrayStart = aStart; + arrayEnd = aEnd; + return this; + } + /// Specify the delimiter character for an array + ConfigBase *arrayDelimiter(char aSep) { + arraySeparator = aSep; + return this; + } + /// Specify the delimiter between a name and value + ConfigBase *valueSeparator(char vSep) { + valueDelimiter = vSep; + return this; + } +}; + +/// the default Config is the INI file format +using ConfigINI = ConfigBase; + +/// ConfigTOML generates a TOML compliant output +class ConfigTOML : public ConfigINI { + + public: + ConfigTOML() { + commentChar = '#'; + arrayStart = '['; + arrayEnd = ']'; + arraySeparator = ','; + valueDelimiter = '='; + } +}; +} // namespace CLI + +// From Validators.hpp: + +namespace CLI { + +class Option; + +/// @defgroup validator_group Validators + +/// @brief Some validators that are provided +/// +/// These are simple `std::string(const std::string&)` validators that are useful. They return +/// a string if the validation fails. A custom struct is provided, as well, with the same user +/// semantics, but with the ability to provide a new type name. +/// @{ + +/// +class Validator { + protected: + /// This is the description function, if empty the description_ will be used + std::function desc_function_{[]() { return std::string{}; }}; + + /// This is the base function that is to be called. + /// Returns a string error message if validation fails. + std::function func_{[](std::string &) { return std::string{}; }}; + /// The name for search purposes of the Validator + std::string name_{}; + /// A Validator will only apply to an indexed value (-1 is all elements) + int application_index_ = -1; + /// Enable for Validator to allow it to be disabled if need be + bool active_{true}; + /// specify that a validator should not modify the input + bool non_modifying_{false}; + + public: + Validator() = default; + /// Construct a Validator with just the description string + explicit Validator(std::string validator_desc) : desc_function_([validator_desc]() { return validator_desc; }) {} + /// Construct Validator from basic information + Validator(std::function op, std::string validator_desc, std::string validator_name = "") + : desc_function_([validator_desc]() { return validator_desc; }), func_(std::move(op)), + name_(std::move(validator_name)) {} + /// Set the Validator operation function + Validator &operation(std::function op) { + func_ = std::move(op); + return *this; + } + /// This is the required operator for a Validator - provided to help + /// users (CLI11 uses the member `func` directly) + std::string operator()(std::string &str) const { + std::string retstring; + if(active_) { + if(non_modifying_) { + std::string value = str; + retstring = func_(value); + } else { + retstring = func_(str); + } + } + return retstring; + } + + /// This is the required operator for a Validator - provided to help + /// users (CLI11 uses the member `func` directly) + std::string operator()(const std::string &str) const { + std::string value = str; + return (active_) ? func_(value) : std::string{}; + } + + /// Specify the type string + Validator &description(std::string validator_desc) { + desc_function_ = [validator_desc]() { return validator_desc; }; + return *this; + } + /// Specify the type string + Validator description(std::string validator_desc) const { + Validator newval(*this); + newval.desc_function_ = [validator_desc]() { return validator_desc; }; + return newval; + } + /// Generate type description information for the Validator + std::string get_description() const { + if(active_) { + return desc_function_(); + } + return std::string{}; + } + /// Specify the type string + Validator &name(std::string validator_name) { + name_ = std::move(validator_name); + return *this; + } + /// Specify the type string + Validator name(std::string validator_name) const { + Validator newval(*this); + newval.name_ = std::move(validator_name); + return newval; + } + /// Get the name of the Validator + const std::string &get_name() const { return name_; } + /// Specify whether the Validator is active or not + Validator &active(bool active_val = true) { + active_ = active_val; + return *this; + } + /// Specify whether the Validator is active or not + Validator active(bool active_val = true) const { + Validator newval(*this); + newval.active_ = active_val; + return newval; + } + + /// Specify whether the Validator can be modifying or not + Validator &non_modifying(bool no_modify = true) { + non_modifying_ = no_modify; + return *this; + } + /// Specify the application index of a validator + Validator &application_index(int app_index) { + application_index_ = app_index; + return *this; + } + /// Specify the application index of a validator + Validator application_index(int app_index) const { + Validator newval(*this); + newval.application_index_ = app_index; + return newval; + } + /// Get the current value of the application index + int get_application_index() const { return application_index_; } + /// Get a boolean if the validator is active + bool get_active() const { return active_; } + + /// Get a boolean if the validator is allowed to modify the input returns true if it can modify the input + bool get_modifying() const { return !non_modifying_; } + + /// Combining validators is a new validator. Type comes from left validator if function, otherwise only set if the + /// same. + Validator operator&(const Validator &other) const { + Validator newval; + + newval._merge_description(*this, other, " AND "); + + // Give references (will make a copy in lambda function) + const std::function &f1 = func_; + const std::function &f2 = other.func_; + + newval.func_ = [f1, f2](std::string &input) { + std::string s1 = f1(input); + std::string s2 = f2(input); + if(!s1.empty() && !s2.empty()) + return std::string("(") + s1 + ") AND (" + s2 + ")"; + else + return s1 + s2; + }; + + newval.active_ = (active_ & other.active_); + newval.application_index_ = application_index_; + return newval; + } + + /// Combining validators is a new validator. Type comes from left validator if function, otherwise only set if the + /// same. + Validator operator|(const Validator &other) const { + Validator newval; + + newval._merge_description(*this, other, " OR "); + + // Give references (will make a copy in lambda function) + const std::function &f1 = func_; + const std::function &f2 = other.func_; + + newval.func_ = [f1, f2](std::string &input) { + std::string s1 = f1(input); + std::string s2 = f2(input); + if(s1.empty() || s2.empty()) + return std::string(); + + return std::string("(") + s1 + ") OR (" + s2 + ")"; + }; + newval.active_ = (active_ & other.active_); + newval.application_index_ = application_index_; + return newval; + } + + /// Create a validator that fails when a given validator succeeds + Validator operator!() const { + Validator newval; + const std::function &dfunc1 = desc_function_; + newval.desc_function_ = [dfunc1]() { + auto str = dfunc1(); + return (!str.empty()) ? std::string("NOT ") + str : std::string{}; + }; + // Give references (will make a copy in lambda function) + const std::function &f1 = func_; + + newval.func_ = [f1, dfunc1](std::string &test) -> std::string { + std::string s1 = f1(test); + if(s1.empty()) { + return std::string("check ") + dfunc1() + " succeeded improperly"; + } + return std::string{}; + }; + newval.active_ = active_; + newval.application_index_ = application_index_; + return newval; + } + + private: + void _merge_description(const Validator &val1, const Validator &val2, const std::string &merger) { + + const std::function &dfunc1 = val1.desc_function_; + const std::function &dfunc2 = val2.desc_function_; + + desc_function_ = [=]() { + std::string f1 = dfunc1(); + std::string f2 = dfunc2(); + if((f1.empty()) || (f2.empty())) { + return f1 + f2; + } + return std::string(1, '(') + f1 + ')' + merger + '(' + f2 + ')'; + }; + } +}; // namespace CLI + +/// Class wrapping some of the accessors of Validator +class CustomValidator : public Validator { + public: +}; +// The implementation of the built in validators is using the Validator class; +// the user is only expected to use the const (static) versions (since there's no setup). +// Therefore, this is in detail. +namespace detail { + +/// CLI enumeration of different file types +enum class path_type { nonexistent, file, directory }; + +#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 +/// get the type of the path from a file name +inline path_type check_path(const char *file) noexcept { + std::error_code ec; + auto stat = std::filesystem::status(file, ec); + if(ec) { + return path_type::nonexistent; + } + switch(stat.type()) { + case std::filesystem::file_type::none: + case std::filesystem::file_type::not_found: + return path_type::nonexistent; + case std::filesystem::file_type::directory: + return path_type::directory; + case std::filesystem::file_type::symlink: + case std::filesystem::file_type::block: + case std::filesystem::file_type::character: + case std::filesystem::file_type::fifo: + case std::filesystem::file_type::socket: + case std::filesystem::file_type::regular: + case std::filesystem::file_type::unknown: + default: + return path_type::file; + } +} +#else +/// get the type of the path from a file name +inline path_type check_path(const char *file) noexcept { +#if defined(_MSC_VER) + struct __stat64 buffer; + if(_stat64(file, &buffer) == 0) { + return ((buffer.st_mode & S_IFDIR) != 0) ? path_type::directory : path_type::file; + } +#else + struct stat buffer; + if(stat(file, &buffer) == 0) { + return ((buffer.st_mode & S_IFDIR) != 0) ? path_type::directory : path_type::file; + } +#endif + return path_type::nonexistent; +} +#endif +/// Check for an existing file (returns error message if check fails) +class ExistingFileValidator : public Validator { + public: + ExistingFileValidator() : Validator("FILE") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result == path_type::nonexistent) { + return "File does not exist: " + filename; + } + if(path_result == path_type::directory) { + return "File is actually a directory: " + filename; + } + return std::string(); + }; + } +}; + +/// Check for an existing directory (returns error message if check fails) +class ExistingDirectoryValidator : public Validator { + public: + ExistingDirectoryValidator() : Validator("DIR") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result == path_type::nonexistent) { + return "Directory does not exist: " + filename; + } + if(path_result == path_type::file) { + return "Directory is actually a file: " + filename; + } + return std::string(); + }; + } +}; + +/// Check for an existing path +class ExistingPathValidator : public Validator { + public: + ExistingPathValidator() : Validator("PATH(existing)") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result == path_type::nonexistent) { + return "Path does not exist: " + filename; + } + return std::string(); + }; + } +}; + +/// Check for an non-existing path +class NonexistentPathValidator : public Validator { + public: + NonexistentPathValidator() : Validator("PATH(non-existing)") { + func_ = [](std::string &filename) { + auto path_result = check_path(filename.c_str()); + if(path_result != path_type::nonexistent) { + return "Path already exists: " + filename; + } + return std::string(); + }; + } +}; + +/// Validate the given string is a legal ipv4 address +class IPV4Validator : public Validator { + public: + IPV4Validator() : Validator("IPV4") { + func_ = [](std::string &ip_addr) { + auto result = CLI::detail::split(ip_addr, '.'); + if(result.size() != 4) { + return std::string("Invalid IPV4 address must have four parts (") + ip_addr + ')'; + } + int num; + for(const auto &var : result) { + bool retval = detail::lexical_cast(var, num); + if(!retval) { + return std::string("Failed parsing number (") + var + ')'; + } + if(num < 0 || num > 255) { + return std::string("Each IP number must be between 0 and 255 ") + var; + } + } + return std::string(); + }; + } +}; + +/// Validate the argument is a number and greater than 0 +class PositiveNumber : public Validator { + public: + PositiveNumber() : Validator("POSITIVE") { + func_ = [](std::string &number_str) { + double number; + if(!detail::lexical_cast(number_str, number)) { + return std::string("Failed parsing number: (") + number_str + ')'; + } + if(number <= 0) { + return std::string("Number less or equal to 0: (") + number_str + ')'; + } + return std::string(); + }; + } +}; +/// Validate the argument is a number and greater than or equal to 0 +class NonNegativeNumber : public Validator { + public: + NonNegativeNumber() : Validator("NONNEGATIVE") { + func_ = [](std::string &number_str) { + double number; + if(!detail::lexical_cast(number_str, number)) { + return std::string("Failed parsing number: (") + number_str + ')'; + } + if(number < 0) { + return std::string("Number less than 0: (") + number_str + ')'; + } + return std::string(); + }; + } +}; + +/// Validate the argument is a number +class Number : public Validator { + public: + Number() : Validator("NUMBER") { + func_ = [](std::string &number_str) { + double number; + if(!detail::lexical_cast(number_str, number)) { + return std::string("Failed parsing as a number (") + number_str + ')'; + } + return std::string(); + }; + } +}; + +} // namespace detail + +// Static is not needed here, because global const implies static. + +/// Check for existing file (returns error message if check fails) +const detail::ExistingFileValidator ExistingFile; + +/// Check for an existing directory (returns error message if check fails) +const detail::ExistingDirectoryValidator ExistingDirectory; + +/// Check for an existing path +const detail::ExistingPathValidator ExistingPath; + +/// Check for an non-existing path +const detail::NonexistentPathValidator NonexistentPath; + +/// Check for an IP4 address +const detail::IPV4Validator ValidIPV4; + +/// Check for a positive number +const detail::PositiveNumber PositiveNumber; + +/// Check for a non-negative number +const detail::NonNegativeNumber NonNegativeNumber; + +/// Check for a number +const detail::Number Number; + +/// Produce a range (factory). Min and max are inclusive. +class Range : public Validator { + public: + /// This produces a range with min and max inclusive. + /// + /// Note that the constructor is templated, but the struct is not, so C++17 is not + /// needed to provide nice syntax for Range(a,b). + template Range(T min, T max) { + std::stringstream out; + out << detail::type_name() << " in [" << min << " - " << max << "]"; + description(out.str()); + + func_ = [min, max](std::string &input) { + T val; + bool converted = detail::lexical_cast(input, val); + if((!converted) || (val < min || val > max)) + return std::string("Value ") + input + " not in range " + std::to_string(min) + " to " + + std::to_string(max); + + return std::string(); + }; + } + + /// Range of one value is 0 to value + template explicit Range(T max) : Range(static_cast(0), max) {} +}; + +/// Produce a bounded range (factory). Min and max are inclusive. +class Bound : public Validator { + public: + /// This bounds a value with min and max inclusive. + /// + /// Note that the constructor is templated, but the struct is not, so C++17 is not + /// needed to provide nice syntax for Range(a,b). + template Bound(T min, T max) { + std::stringstream out; + out << detail::type_name() << " bounded to [" << min << " - " << max << "]"; + description(out.str()); + + func_ = [min, max](std::string &input) { + T val; + bool converted = detail::lexical_cast(input, val); + if(!converted) { + return std::string("Value ") + input + " could not be converted"; + } + if(val < min) + input = detail::to_string(min); + else if(val > max) + input = detail::to_string(max); + + return std::string{}; + }; + } + + /// Range of one value is 0 to value + template explicit Bound(T max) : Bound(static_cast(0), max) {} +}; + +namespace detail { +template ::type>::value, detail::enabler> = detail::dummy> +auto smart_deref(T value) -> decltype(*value) { + return *value; +} + +template < + typename T, + enable_if_t::type>::value, detail::enabler> = detail::dummy> +typename std::remove_reference::type &smart_deref(T &value) { + return value; +} +/// Generate a string representation of a set +template std::string generate_set(const T &set) { + using element_t = typename detail::element_type::type; + using iteration_type_t = typename detail::pair_adaptor::value_type; // the type of the object pair + std::string out(1, '{'); + out.append(detail::join( + detail::smart_deref(set), + [](const iteration_type_t &v) { return detail::pair_adaptor::first(v); }, + ",")); + out.push_back('}'); + return out; +} + +/// Generate a string representation of a map +template std::string generate_map(const T &map, bool key_only = false) { + using element_t = typename detail::element_type::type; + using iteration_type_t = typename detail::pair_adaptor::value_type; // the type of the object pair + std::string out(1, '{'); + out.append(detail::join( + detail::smart_deref(map), + [key_only](const iteration_type_t &v) { + std::string res{detail::to_string(detail::pair_adaptor::first(v))}; + + if(!key_only) { + res.append("->"); + res += detail::to_string(detail::pair_adaptor::second(v)); + } + return res; + }, + ",")); + out.push_back('}'); + return out; +} + +template struct has_find { + template + static auto test(int) -> decltype(std::declval().find(std::declval()), std::true_type()); + template static auto test(...) -> decltype(std::false_type()); + + static const auto value = decltype(test(0))::value; + using type = std::integral_constant; +}; + +/// A search function +template ::value, detail::enabler> = detail::dummy> +auto search(const T &set, const V &val) -> std::pair { + using element_t = typename detail::element_type::type; + auto &setref = detail::smart_deref(set); + auto it = std::find_if(std::begin(setref), std::end(setref), [&val](decltype(*std::begin(setref)) v) { + return (detail::pair_adaptor::first(v) == val); + }); + return {(it != std::end(setref)), it}; +} + +/// A search function that uses the built in find function +template ::value, detail::enabler> = detail::dummy> +auto search(const T &set, const V &val) -> std::pair { + auto &setref = detail::smart_deref(set); + auto it = setref.find(val); + return {(it != std::end(setref)), it}; +} + +/// A search function with a filter function +template +auto search(const T &set, const V &val, const std::function &filter_function) + -> std::pair { + using element_t = typename detail::element_type::type; + // do the potentially faster first search + auto res = search(set, val); + if((res.first) || (!(filter_function))) { + return res; + } + // if we haven't found it do the longer linear search with all the element translations + auto &setref = detail::smart_deref(set); + auto it = std::find_if(std::begin(setref), std::end(setref), [&](decltype(*std::begin(setref)) v) { + V a{detail::pair_adaptor::first(v)}; + a = filter_function(a); + return (a == val); + }); + return {(it != std::end(setref)), it}; +} + +// the following suggestion was made by Nikita Ofitserov(@himikof) +// done in templates to prevent compiler warnings on negation of unsigned numbers + +/// Do a check for overflow on signed numbers +template +inline typename std::enable_if::value, T>::type overflowCheck(const T &a, const T &b) { + if((a > 0) == (b > 0)) { + return ((std::numeric_limits::max)() / (std::abs)(a) < (std::abs)(b)); + } else { + return ((std::numeric_limits::min)() / (std::abs)(a) > -(std::abs)(b)); + } +} +/// Do a check for overflow on unsigned numbers +template +inline typename std::enable_if::value, T>::type overflowCheck(const T &a, const T &b) { + return ((std::numeric_limits::max)() / a < b); +} + +/// Performs a *= b; if it doesn't cause integer overflow. Returns false otherwise. +template typename std::enable_if::value, bool>::type checked_multiply(T &a, T b) { + if(a == 0 || b == 0 || a == 1 || b == 1) { + a *= b; + return true; + } + if(a == (std::numeric_limits::min)() || b == (std::numeric_limits::min)()) { + return false; + } + if(overflowCheck(a, b)) { + return false; + } + a *= b; + return true; +} + +/// Performs a *= b; if it doesn't equal infinity. Returns false otherwise. +template +typename std::enable_if::value, bool>::type checked_multiply(T &a, T b) { + T c = a * b; + if(std::isinf(c) && !std::isinf(a) && !std::isinf(b)) { + return false; + } + a = c; + return true; +} + +} // namespace detail +/// Verify items are in a set +class IsMember : public Validator { + public: + using filter_fn_t = std::function; + + /// This allows in-place construction using an initializer list + template + IsMember(std::initializer_list values, Args &&... args) + : IsMember(std::vector(values), std::forward(args)...) {} + + /// This checks to see if an item is in a set (empty function) + template explicit IsMember(T &&set) : IsMember(std::forward(set), nullptr) {} + + /// This checks to see if an item is in a set: pointer or copy version. You can pass in a function that will filter + /// both sides of the comparison before computing the comparison. + template explicit IsMember(T set, F filter_function) { + + // Get the type of the contained item - requires a container have ::value_type + // if the type does not have first_type and second_type, these are both value_type + using element_t = typename detail::element_type::type; // Removes (smart) pointers if needed + using item_t = typename detail::pair_adaptor::first_type; // Is value_type if not a map + + using local_item_t = typename IsMemberType::type; // This will convert bad types to good ones + // (const char * to std::string) + + // Make a local copy of the filter function, using a std::function if not one already + std::function filter_fn = filter_function; + + // This is the type name for help, it will take the current version of the set contents + desc_function_ = [set]() { return detail::generate_set(detail::smart_deref(set)); }; + + // This is the function that validates + // It stores a copy of the set pointer-like, so shared_ptr will stay alive + func_ = [set, filter_fn](std::string &input) { + local_item_t b; + if(!detail::lexical_cast(input, b)) { + throw ValidationError(input); // name is added later + } + if(filter_fn) { + b = filter_fn(b); + } + auto res = detail::search(set, b, filter_fn); + if(res.first) { + // Make sure the version in the input string is identical to the one in the set + if(filter_fn) { + input = detail::value_string(detail::pair_adaptor::first(*(res.second))); + } + + // Return empty error string (success) + return std::string{}; + } + + // If you reach this point, the result was not found + std::string out(" not in "); + out += detail::generate_set(detail::smart_deref(set)); + return out; + }; + } + + /// You can pass in as many filter functions as you like, they nest (string only currently) + template + IsMember(T &&set, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&... other) + : IsMember( + std::forward(set), + [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); }, + other...) {} +}; + +/// definition of the default transformation object +template using TransformPairs = std::vector>; + +/// Translate named items to other or a value set +class Transformer : public Validator { + public: + using filter_fn_t = std::function; + + /// This allows in-place construction + template + Transformer(std::initializer_list> values, Args &&... args) + : Transformer(TransformPairs(values), std::forward(args)...) {} + + /// direct map of std::string to std::string + template explicit Transformer(T &&mapping) : Transformer(std::forward(mapping), nullptr) {} + + /// This checks to see if an item is in a set: pointer or copy version. You can pass in a function that will filter + /// both sides of the comparison before computing the comparison. + template explicit Transformer(T mapping, F filter_function) { + + static_assert(detail::pair_adaptor::type>::value, + "mapping must produce value pairs"); + // Get the type of the contained item - requires a container have ::value_type + // if the type does not have first_type and second_type, these are both value_type + using element_t = typename detail::element_type::type; // Removes (smart) pointers if needed + using item_t = typename detail::pair_adaptor::first_type; // Is value_type if not a map + using local_item_t = typename IsMemberType::type; // Will convert bad types to good ones + // (const char * to std::string) + + // Make a local copy of the filter function, using a std::function if not one already + std::function filter_fn = filter_function; + + // This is the type name for help, it will take the current version of the set contents + desc_function_ = [mapping]() { return detail::generate_map(detail::smart_deref(mapping)); }; + + func_ = [mapping, filter_fn](std::string &input) { + local_item_t b; + if(!detail::lexical_cast(input, b)) { + return std::string(); + // there is no possible way we can match anything in the mapping if we can't convert so just return + } + if(filter_fn) { + b = filter_fn(b); + } + auto res = detail::search(mapping, b, filter_fn); + if(res.first) { + input = detail::value_string(detail::pair_adaptor::second(*res.second)); + } + return std::string{}; + }; + } + + /// You can pass in as many filter functions as you like, they nest + template + Transformer(T &&mapping, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&... other) + : Transformer( + std::forward(mapping), + [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); }, + other...) {} +}; + +/// translate named items to other or a value set +class CheckedTransformer : public Validator { + public: + using filter_fn_t = std::function; + + /// This allows in-place construction + template + CheckedTransformer(std::initializer_list> values, Args &&... args) + : CheckedTransformer(TransformPairs(values), std::forward(args)...) {} + + /// direct map of std::string to std::string + template explicit CheckedTransformer(T mapping) : CheckedTransformer(std::move(mapping), nullptr) {} + + /// This checks to see if an item is in a set: pointer or copy version. You can pass in a function that will filter + /// both sides of the comparison before computing the comparison. + template explicit CheckedTransformer(T mapping, F filter_function) { + + static_assert(detail::pair_adaptor::type>::value, + "mapping must produce value pairs"); + // Get the type of the contained item - requires a container have ::value_type + // if the type does not have first_type and second_type, these are both value_type + using element_t = typename detail::element_type::type; // Removes (smart) pointers if needed + using item_t = typename detail::pair_adaptor::first_type; // Is value_type if not a map + using local_item_t = typename IsMemberType::type; // Will convert bad types to good ones + // (const char * to std::string) + using iteration_type_t = typename detail::pair_adaptor::value_type; // the type of the object pair + + // Make a local copy of the filter function, using a std::function if not one already + std::function filter_fn = filter_function; + + auto tfunc = [mapping]() { + std::string out("value in "); + out += detail::generate_map(detail::smart_deref(mapping)) + " OR {"; + out += detail::join( + detail::smart_deref(mapping), + [](const iteration_type_t &v) { return detail::to_string(detail::pair_adaptor::second(v)); }, + ","); + out.push_back('}'); + return out; + }; + + desc_function_ = tfunc; + + func_ = [mapping, tfunc, filter_fn](std::string &input) { + local_item_t b; + bool converted = detail::lexical_cast(input, b); + if(converted) { + if(filter_fn) { + b = filter_fn(b); + } + auto res = detail::search(mapping, b, filter_fn); + if(res.first) { + input = detail::value_string(detail::pair_adaptor::second(*res.second)); + return std::string{}; + } + } + for(const auto &v : detail::smart_deref(mapping)) { + auto output_string = detail::value_string(detail::pair_adaptor::second(v)); + if(output_string == input) { + return std::string(); + } + } + + return "Check " + input + " " + tfunc() + " FAILED"; + }; + } + + /// You can pass in as many filter functions as you like, they nest + template + CheckedTransformer(T &&mapping, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&... other) + : CheckedTransformer( + std::forward(mapping), + [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); }, + other...) {} +}; + +/// Helper function to allow ignore_case to be passed to IsMember or Transform +inline std::string ignore_case(std::string item) { return detail::to_lower(item); } + +/// Helper function to allow ignore_underscore to be passed to IsMember or Transform +inline std::string ignore_underscore(std::string item) { return detail::remove_underscore(item); } + +/// Helper function to allow checks to ignore spaces to be passed to IsMember or Transform +inline std::string ignore_space(std::string item) { + item.erase(std::remove(std::begin(item), std::end(item), ' '), std::end(item)); + item.erase(std::remove(std::begin(item), std::end(item), '\t'), std::end(item)); + return item; +} + +/// Multiply a number by a factor using given mapping. +/// Can be used to write transforms for SIZE or DURATION inputs. +/// +/// Example: +/// With mapping = `{"b"->1, "kb"->1024, "mb"->1024*1024}` +/// one can recognize inputs like "100", "12kb", "100 MB", +/// that will be automatically transformed to 100, 14448, 104857600. +/// +/// Output number type matches the type in the provided mapping. +/// Therefore, if it is required to interpret real inputs like "0.42 s", +/// the mapping should be of a type or . +class AsNumberWithUnit : public Validator { + public: + /// Adjust AsNumberWithUnit behavior. + /// CASE_SENSITIVE/CASE_INSENSITIVE controls how units are matched. + /// UNIT_OPTIONAL/UNIT_REQUIRED throws ValidationError + /// if UNIT_REQUIRED is set and unit literal is not found. + enum Options { + CASE_SENSITIVE = 0, + CASE_INSENSITIVE = 1, + UNIT_OPTIONAL = 0, + UNIT_REQUIRED = 2, + DEFAULT = CASE_INSENSITIVE | UNIT_OPTIONAL + }; + + template + explicit AsNumberWithUnit(std::map mapping, + Options opts = DEFAULT, + const std::string &unit_name = "UNIT") { + description(generate_description(unit_name, opts)); + validate_mapping(mapping, opts); + + // transform function + func_ = [mapping, opts](std::string &input) -> std::string { + Number num; + + detail::rtrim(input); + if(input.empty()) { + throw ValidationError("Input is empty"); + } + + // Find split position between number and prefix + auto unit_begin = input.end(); + while(unit_begin > input.begin() && std::isalpha(*(unit_begin - 1), std::locale())) { + --unit_begin; + } + + std::string unit{unit_begin, input.end()}; + input.resize(static_cast(std::distance(input.begin(), unit_begin))); + detail::trim(input); + + if(opts & UNIT_REQUIRED && unit.empty()) { + throw ValidationError("Missing mandatory unit"); + } + if(opts & CASE_INSENSITIVE) { + unit = detail::to_lower(unit); + } + + bool converted = detail::lexical_cast(input, num); + if(!converted) { + throw ValidationError(std::string("Value ") + input + " could not be converted to " + + detail::type_name()); + } + + if(unit.empty()) { + // No need to modify input if no unit passed + return {}; + } + + // find corresponding factor + auto it = mapping.find(unit); + if(it == mapping.end()) { + throw ValidationError(unit + + " unit not recognized. " + "Allowed values: " + + detail::generate_map(mapping, true)); + } + + // perform safe multiplication + bool ok = detail::checked_multiply(num, it->second); + if(!ok) { + throw ValidationError(detail::to_string(num) + " multiplied by " + unit + + " factor would cause number overflow. Use smaller value."); + } + input = detail::to_string(num); + + return {}; + }; + } + + private: + /// Check that mapping contains valid units. + /// Update mapping for CASE_INSENSITIVE mode. + template static void validate_mapping(std::map &mapping, Options opts) { + for(auto &kv : mapping) { + if(kv.first.empty()) { + throw ValidationError("Unit must not be empty."); + } + if(!detail::isalpha(kv.first)) { + throw ValidationError("Unit must contain only letters."); + } + } + + // make all units lowercase if CASE_INSENSITIVE + if(opts & CASE_INSENSITIVE) { + std::map lower_mapping; + for(auto &kv : mapping) { + auto s = detail::to_lower(kv.first); + if(lower_mapping.count(s)) { + throw ValidationError(std::string("Several matching lowercase unit representations are found: ") + + s); + } + lower_mapping[detail::to_lower(kv.first)] = kv.second; + } + mapping = std::move(lower_mapping); + } + } + + /// Generate description like this: NUMBER [UNIT] + template static std::string generate_description(const std::string &name, Options opts) { + std::stringstream out; + out << detail::type_name() << ' '; + if(opts & UNIT_REQUIRED) { + out << name; + } else { + out << '[' << name << ']'; + } + return out.str(); + } +}; + +/// Converts a human-readable size string (with unit literal) to uin64_t size. +/// Example: +/// "100" => 100 +/// "1 b" => 100 +/// "10Kb" => 10240 // you can configure this to be interpreted as kilobyte (*1000) or kibibyte (*1024) +/// "10 KB" => 10240 +/// "10 kb" => 10240 +/// "10 kib" => 10240 // *i, *ib are always interpreted as *bibyte (*1024) +/// "10kb" => 10240 +/// "2 MB" => 2097152 +/// "2 EiB" => 2^61 // Units up to exibyte are supported +class AsSizeValue : public AsNumberWithUnit { + public: + using result_t = std::uint64_t; + + /// If kb_is_1000 is true, + /// interpret 'kb', 'k' as 1000 and 'kib', 'ki' as 1024 + /// (same applies to higher order units as well). + /// Otherwise, interpret all literals as factors of 1024. + /// The first option is formally correct, but + /// the second interpretation is more wide-spread + /// (see https://en.wikipedia.org/wiki/Binary_prefix). + explicit AsSizeValue(bool kb_is_1000) : AsNumberWithUnit(get_mapping(kb_is_1000)) { + if(kb_is_1000) { + description("SIZE [b, kb(=1000b), kib(=1024b), ...]"); + } else { + description("SIZE [b, kb(=1024b), ...]"); + } + } + + private: + /// Get mapping + static std::map init_mapping(bool kb_is_1000) { + std::map m; + result_t k_factor = kb_is_1000 ? 1000 : 1024; + result_t ki_factor = 1024; + result_t k = 1; + result_t ki = 1; + m["b"] = 1; + for(std::string p : {"k", "m", "g", "t", "p", "e"}) { + k *= k_factor; + ki *= ki_factor; + m[p] = k; + m[p + "b"] = k; + m[p + "i"] = ki; + m[p + "ib"] = ki; + } + return m; + } + + /// Cache calculated mapping + static std::map get_mapping(bool kb_is_1000) { + if(kb_is_1000) { + static auto m = init_mapping(true); + return m; + } else { + static auto m = init_mapping(false); + return m; + } + } +}; + +namespace detail { +/// Split a string into a program name and command line arguments +/// the string is assumed to contain a file name followed by other arguments +/// the return value contains is a pair with the first argument containing the program name and the second +/// everything else. +inline std::pair split_program_name(std::string commandline) { + // try to determine the programName + std::pair vals; + trim(commandline); + auto esp = commandline.find_first_of(' ', 1); + while(detail::check_path(commandline.substr(0, esp).c_str()) != path_type::file) { + esp = commandline.find_first_of(' ', esp + 1); + if(esp == std::string::npos) { + // if we have reached the end and haven't found a valid file just assume the first argument is the + // program name + esp = commandline.find_first_of(' ', 1); + break; + } + } + vals.first = commandline.substr(0, esp); + rtrim(vals.first); + // strip the program name + vals.second = (esp != std::string::npos) ? commandline.substr(esp + 1) : std::string{}; + ltrim(vals.second); + return vals; +} + +} // namespace detail +/// @} + +} // namespace CLI + +// From FormatterFwd.hpp: + +namespace CLI { + +class Option; +class App; + +/// This enum signifies the type of help requested +/// +/// This is passed in by App; all user classes must accept this as +/// the second argument. + +enum class AppFormatMode { + Normal, ///< The normal, detailed help + All, ///< A fully expanded help + Sub, ///< Used when printed as part of expanded subcommand +}; + +/// This is the minimum requirements to run a formatter. +/// +/// A user can subclass this is if they do not care at all +/// about the structure in CLI::Formatter. +class FormatterBase { + protected: + /// @name Options + ///@{ + + /// The width of the first column + std::size_t column_width_{30}; + + /// @brief The required help printout labels (user changeable) + /// Values are Needs, Excludes, etc. + std::map labels_{}; + + ///@} + /// @name Basic + ///@{ + + public: + FormatterBase() = default; + FormatterBase(const FormatterBase &) = default; + FormatterBase(FormatterBase &&) = default; + + /// Adding a destructor in this form to work around bug in GCC 4.7 + virtual ~FormatterBase() noexcept {} // NOLINT(modernize-use-equals-default) + + /// This is the key method that puts together help + virtual std::string make_help(const App *, std::string, AppFormatMode) const = 0; + + ///@} + /// @name Setters + ///@{ + + /// Set the "REQUIRED" label + void label(std::string key, std::string val) { labels_[key] = val; } + + /// Set the column width + void column_width(std::size_t val) { column_width_ = val; } + + ///@} + /// @name Getters + ///@{ + + /// Get the current value of a name (REQUIRED, etc.) + std::string get_label(std::string key) const { + if(labels_.find(key) == labels_.end()) + return key; + else + return labels_.at(key); + } + + /// Get the current column width + std::size_t get_column_width() const { return column_width_; } + + ///@} +}; + +/// This is a specialty override for lambda functions +class FormatterLambda final : public FormatterBase { + using funct_t = std::function; + + /// The lambda to hold and run + funct_t lambda_; + + public: + /// Create a FormatterLambda with a lambda function + explicit FormatterLambda(funct_t funct) : lambda_(std::move(funct)) {} + + /// Adding a destructor (mostly to make GCC 4.7 happy) + ~FormatterLambda() noexcept override {} // NOLINT(modernize-use-equals-default) + + /// This will simply call the lambda function + std::string make_help(const App *app, std::string name, AppFormatMode mode) const override { + return lambda_(app, name, mode); + } +}; + +/// This is the default Formatter for CLI11. It pretty prints help output, and is broken into quite a few +/// overridable methods, to be highly customizable with minimal effort. +class Formatter : public FormatterBase { + public: + Formatter() = default; + Formatter(const Formatter &) = default; + Formatter(Formatter &&) = default; + + /// @name Overridables + ///@{ + + /// This prints out a group of options with title + /// + virtual std::string make_group(std::string group, bool is_positional, std::vector opts) const; + + /// This prints out just the positionals "group" + virtual std::string make_positionals(const App *app) const; + + /// This prints out all the groups of options + std::string make_groups(const App *app, AppFormatMode mode) const; + + /// This prints out all the subcommands + virtual std::string make_subcommands(const App *app, AppFormatMode mode) const; + + /// This prints out a subcommand + virtual std::string make_subcommand(const App *sub) const; + + /// This prints out a subcommand in help-all + virtual std::string make_expanded(const App *sub) const; + + /// This prints out all the groups of options + virtual std::string make_footer(const App *app) const; + + /// This displays the description line + virtual std::string make_description(const App *app) const; + + /// This displays the usage line + virtual std::string make_usage(const App *app, std::string name) const; + + /// This puts everything together + std::string make_help(const App * /*app*/, std::string, AppFormatMode) const override; + + ///@} + /// @name Options + ///@{ + + /// This prints out an option help line, either positional or optional form + virtual std::string make_option(const Option *opt, bool is_positional) const { + std::stringstream out; + detail::format_help( + out, make_option_name(opt, is_positional) + make_option_opts(opt), make_option_desc(opt), column_width_); + return out.str(); + } + + /// @brief This is the name part of an option, Default: left column + virtual std::string make_option_name(const Option *, bool) const; + + /// @brief This is the options part of the name, Default: combined into left column + virtual std::string make_option_opts(const Option *) const; + + /// @brief This is the description. Default: Right column, on new line if left column too large + virtual std::string make_option_desc(const Option *) const; + + /// @brief This is used to print the name on the USAGE line + virtual std::string make_option_usage(const Option *opt) const; + + ///@} +}; + +} // namespace CLI + +// From Option.hpp: + +namespace CLI { + +using results_t = std::vector; +/// callback function definition +using callback_t = std::function; + +class Option; +class App; + +using Option_p = std::unique_ptr - - diff --git a/src/Simulation/Simulators.Type3.Tests/Tests.Microsoft.Quantum.Simulators.Type3.csproj b/src/Simulation/Simulators.Type3.Tests/Tests.Microsoft.Quantum.Simulators.Type3.csproj index d66eb0ee909..8d8fbba1a19 100644 --- a/src/Simulation/Simulators.Type3.Tests/Tests.Microsoft.Quantum.Simulators.Type3.csproj +++ b/src/Simulation/Simulators.Type3.Tests/Tests.Microsoft.Quantum.Simulators.Type3.csproj @@ -1,4 +1,4 @@ - + @@ -19,5 +19,3 @@ - - diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj index 2b2cf28cb92..433eecac3ac 100644 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,5 @@ - + + diff --git a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Primitive.Measure.cs b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Primitive.Measure.cs index b13a03116da..907e6378d4e 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Primitive.Measure.cs +++ b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Primitive.Measure.cs @@ -5,10 +5,11 @@ namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Implementati { using System; using Microsoft.Quantum.Simulation.Core; + using Microsoft.Quantum.Intrinsic.Interfaces; public partial class QCTraceSimulatorImpl { - public virtual Result Measure__Body(IQArray paulis, IQArray targets) + Result IIntrinsicMeasure.Body(IQArray paulis, IQArray targets) { return this.Measure(paulis, targets); } diff --git a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs index 4e614f5a524..5d37224316e 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs +++ b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs @@ -16,7 +16,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Implementati /// /// Internals of . For internal use only. /// - public partial class QCTraceSimulatorImpl : SimulatorBase, IGate_Measure + public partial class QCTraceSimulatorImpl : SimulatorBase, IIntrinsicMeasure { protected readonly QCTraceSimulatorConfiguration configuration; private readonly QCTraceSimulatorCore tracingCore; diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs index 8e179f2d8a7..f8c3a68e3ef 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyControlledX__Body(Qubit control, Qubit target) + void IIntrinsicApplyControlledX.Body(Qubit control, Qubit target) { this.CheckQubits(new QArray(new Qubit[]{ control, target })); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs index 1cfbeed2a0e..1f0ae75acdc 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyControlledZ__Body(Qubit control, Qubit target) + void IIntrinsicApplyControlledZ.Body(Qubit control, Qubit target) { this.CheckQubits(new QArray(new Qubit[]{ control, target })); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs index 453fbe28339..242d2bfa069 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledH__Body(Qubit target) + void IIntrinsicApplyUncontrolledH.Body(Qubit target) { this.CheckQubit(target); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs index 56e7358db96..7bce94d0644 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs @@ -1,24 +1,23 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledRx__Body(double angle, Qubit target) + void IIntrinsicApplyUncontrolledRx.Body(double angle, Qubit target) { this.CheckQubit(target, nameof(target)); CheckAngle(angle); R(this.Id, Pauli.PauliX, angle, (uint)target.Id); } - public virtual void ApplyUncontrolledRx__AdjointBody(double angle, Qubit target) + void IIntrinsicApplyUncontrolledRx.AdjointBody(double angle, Qubit target) { - ApplyUncontrolledRx__Body(-angle, target); + ((IIntrinsicApplyUncontrolledRx)this).Body(-angle, target); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs index 05c811dc667..4dad6b04f55 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs @@ -1,24 +1,23 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledRy__Body(double angle, Qubit target) + void IIntrinsicApplyUncontrolledRy.Body(double angle, Qubit target) { this.CheckQubit(target, nameof(target)); CheckAngle(angle); R(this.Id, Pauli.PauliY, angle, (uint)target.Id); } - public virtual void ApplyUncontrolledRy__AdjointBody(double angle, Qubit target) + void IIntrinsicApplyUncontrolledRy.AdjointBody(double angle, Qubit target) { - ApplyUncontrolledRy__Body(-angle, target); + ((IIntrinsicApplyUncontrolledRy)this).Body(-angle, target); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs index d6343548bca..0c28ea37075 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs @@ -1,24 +1,23 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledRz__Body(double angle, Qubit target) + void IIntrinsicApplyUncontrolledRz.Body(double angle, Qubit target) { this.CheckQubit(target, nameof(target)); CheckAngle(angle); R(this.Id, Pauli.PauliZ, angle, (uint)target.Id); } - public virtual void ApplyUncontrolledRz__AdjointBody(double angle, Qubit target) + void IIntrinsicApplyUncontrolledRz.AdjointBody(double angle, Qubit target) { - ApplyUncontrolledRz__Body(-angle, target); + ((IIntrinsicApplyUncontrolledRz)this).Body(-angle, target); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs index e9e08bdb6f3..680617dfbed 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs @@ -1,22 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledS__Body(Qubit target) + void IIntrinsicApplyUncontrolledS.Body(Qubit target) { this.CheckQubit(target); S(this.Id, (uint)target.Id); } - public virtual void ApplyUncontrolledS__AdjointBody(Qubit target) + void IIntrinsicApplyUncontrolledS.AdjointBody(Qubit target) { this.CheckQubit(target); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledSWAP.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledSWAP.cs index e6d8e72382a..733db0889a2 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledSWAP.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledSWAP.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledSWAP__Body(Qubit qubit1, Qubit qubit2) + void IIntrinsicApplyUncontrolledSWAP.Body(Qubit qubit1, Qubit qubit2) { // Issue #44 (https://github.com/microsoft/qsharp-runtime/issues/44) // If/when the simulator provides access to the accelerated SWAP functionality, diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs index 3f3e4902be5..ce00cb8bc1e 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs @@ -1,22 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledT__Body(Qubit target) + void IIntrinsicApplyUncontrolledT.Body(Qubit target) { this.CheckQubit(target); T(this.Id, (uint)target.Id); } - public virtual void ApplyUncontrolledT__AdjointBody(Qubit target) + void IIntrinsicApplyUncontrolledT.AdjointBody(Qubit target) { this.CheckQubit(target); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs index 13aaf95b503..673ca0742da 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledX__Body(Qubit target) + void IIntrinsicApplyUncontrolledX.Body(Qubit target) { this.CheckQubit(target); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs index 5e409019a40..3f1d13c6a53 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledY__Body(Qubit target) + void IIntrinsicApplyUncontrolledY.Body(Qubit target) { this.CheckQubit(target); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs index 09eb9f70e9e..10d6d31aca8 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void ApplyUncontrolledZ__Body(Qubit target) + void IIntrinsicApplyUncontrolledZ.Body(Qubit target) { this.CheckQubit(target); diff --git a/src/Simulation/Simulators/QuantumSimulator/Assert.cs b/src/Simulation/Simulators/QuantumSimulator/Assert.cs index fb7d2ec5952..fc54ba1fcc1 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Assert.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Assert.cs @@ -2,9 +2,6 @@ // Licensed under the MIT License. using System; -using System.Diagnostics; -using System.Linq; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; using static System.Math; diff --git a/src/Simulation/Simulators/QuantumSimulator/AssertProb.cs b/src/Simulation/Simulators/QuantumSimulator/AssertProb.cs index 8cc32bb0f9e..955ba22929b 100644 --- a/src/Simulation/Simulators/QuantumSimulator/AssertProb.cs +++ b/src/Simulation/Simulators/QuantumSimulator/AssertProb.cs @@ -2,9 +2,6 @@ // Licensed under the MIT License. using System; -using System.Diagnostics; -using System.Linq; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; using static System.Math; diff --git a/src/Simulation/Simulators/QuantumSimulator/Exp.cs b/src/Simulation/Simulators/QuantumSimulator/Exp.cs index fcab47bc9e8..9d1b11511f4 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Exp.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Exp.cs @@ -2,15 +2,14 @@ // Licensed under the MIT License. using System; -using System.Linq; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void Exp__Body(IQArray paulis, double angle, IQArray targets) + void IIntrinsicExp.Body(IQArray paulis, double angle, IQArray targets) { this.CheckQubits(targets); CheckAngle(angle); @@ -23,12 +22,12 @@ public virtual void Exp__Body(IQArray paulis, double angle, IQArray paulis, double angle, IQArray targets) + void IIntrinsicExp.AdjointBody(IQArray paulis, double angle, IQArray targets) { - Exp__Body(paulis, -angle, targets); + ((IIntrinsicExp)this).Body(paulis, -angle, targets); } - public virtual void Exp__ControlledBody(IQArray controls, IQArray paulis, double angle, IQArray targets) + void IIntrinsicExp.ControlledBody(IQArray controls, IQArray paulis, double angle, IQArray targets) { this.CheckQubits(controls, targets); CheckAngle(angle); @@ -39,13 +38,13 @@ public virtual void Exp__ControlledBody(IQArray controls, IQArray } SafeControlled(controls, - () => Exp__Body(paulis, angle, targets), + () => ((IIntrinsicExp)this).Body(paulis, angle, targets), (count, ids) => MCExp(this.Id, (uint)paulis.Length, paulis.ToArray(), angle, count, ids, targets.GetIds())); } - public virtual void Exp__ControlledAdjointBody(IQArray controls, IQArray paulis, double angle, IQArray targets) + void IIntrinsicExp.ControlledAdjointBody(IQArray controls, IQArray paulis, double angle, IQArray targets) { - Exp__ControlledBody(controls, paulis, -angle, targets); + ((IIntrinsicExp)this).ControlledBody(controls, paulis, -angle, targets); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/Extensions.cs b/src/Simulation/Simulators/QuantumSimulator/Extensions.cs index 9f073e6c6bd..2e38358e372 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Extensions.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Extensions.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System; -using System.Reflection; using System.Diagnostics; using System.Linq; diff --git a/src/Simulation/Simulators/QuantumSimulator/H.cs b/src/Simulation/Simulators/QuantumSimulator/H.cs index 57b9aed9169..3df34308f06 100644 --- a/src/Simulation/Simulators/QuantumSimulator/H.cs +++ b/src/Simulation/Simulators/QuantumSimulator/H.cs @@ -1,27 +1,26 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void H__Body(Qubit target) + void IIntrinsicH.Body(Qubit target) { this.CheckQubit(target); H(this.Id, (uint)target.Id); } - public virtual void H__ControlledBody(IQArray controls, Qubit target) + void IIntrinsicH.ControlledBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => H__Body(target), + () => ((IIntrinsicH)this).Body(target), (count, ids) => MCH(this.Id, count, ids, (uint)target.Id)); } } diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs index e36cdf6c602..f372f9a02de 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void IsingXX__Body(double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingXX.Body(double angle, Qubit target1, Qubit target2) { var paulis = new Pauli[]{ Pauli.PauliX, Pauli.PauliX }; var targets = new QArray(new Qubit[]{ target1, target2 }); @@ -19,16 +18,16 @@ public virtual void IsingXX__Body(double angle, Qubit target1, Qubit target2) Exp(this.Id, (uint)targets.Length, paulis, angle * 2.0, targets.GetIds()); } - public virtual void IsingXX__AdjointBody(double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingXX.AdjointBody(double angle, Qubit target1, Qubit target2) { - IsingXX__Body(-angle, target1, target2); + ((IIntrinsicIsingXX)this).Body(-angle, target1, target2); } - public virtual void IsingXX__ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingXX.ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2) { if (controls == null || controls.Length == 0) { - IsingXX__Body(angle, target1, target2); + ((IIntrinsicIsingXX)this).Body(angle, target1, target2); } else { @@ -41,9 +40,9 @@ public virtual void IsingXX__ControlledBody(IQArray controls, double angl } } - public virtual void IsingXX__ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingXX.ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2) { - IsingXX__ControlledBody(controls, -angle, target1, target2); + ((IIntrinsicIsingXX)this).ControlledBody(controls, -angle, target1, target2); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs index 924a7903981..c733988a2cd 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void IsingYY__Body(double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingYY.Body(double angle, Qubit target1, Qubit target2) { var paulis = new Pauli[]{ Pauli.PauliY, Pauli.PauliY }; var targets = new QArray(new Qubit[]{ target1, target2 }); @@ -19,16 +18,16 @@ public virtual void IsingYY__Body(double angle, Qubit target1, Qubit target2) Exp(this.Id, (uint)targets.Length, paulis, angle * 2.0, targets.GetIds()); } - public virtual void IsingYY__AdjointBody(double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingYY.AdjointBody(double angle, Qubit target1, Qubit target2) { - IsingYY__Body(-angle, target1, target2); + ((IIntrinsicIsingYY)this).Body(-angle, target1, target2); } - public virtual void IsingYY__ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingYY.ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2) { if (controls == null || controls.Length == 0) { - IsingYY__Body(angle, target1, target2); + ((IIntrinsicIsingYY)this).Body(angle, target1, target2); } else { @@ -41,9 +40,9 @@ public virtual void IsingYY__ControlledBody(IQArray controls, double angl } } - public virtual void IsingYY__ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingYY.ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2) { - IsingYY__ControlledBody(controls, -angle, target1, target2); + ((IIntrinsicIsingYY)this).ControlledBody(controls, -angle, target1, target2); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs index 6265db3967d..e19c69347d3 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void IsingZZ__Body(double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingZZ.Body(double angle, Qubit target1, Qubit target2) { var paulis = new Pauli[]{ Pauli.PauliZ, Pauli.PauliZ }; var targets = new QArray(new Qubit[]{ target1, target2 }); @@ -19,16 +18,16 @@ public virtual void IsingZZ__Body(double angle, Qubit target1, Qubit target2) Exp(this.Id, (uint)targets.Length, paulis, angle * 2.0, targets.GetIds()); } - public virtual void IsingZZ__AdjointBody(double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingZZ.AdjointBody(double angle, Qubit target1, Qubit target2) { - IsingZZ__Body(-angle, target1, target2); + ((IIntrinsicIsingZZ)this).Body(-angle, target1, target2); } - public virtual void IsingZZ__ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingZZ.ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2) { if (controls == null || controls.Length == 0) { - IsingZZ__Body(angle, target1, target2); + ((IIntrinsicIsingZZ)this).Body(angle, target1, target2); } else { @@ -41,9 +40,9 @@ public virtual void IsingZZ__ControlledBody(IQArray controls, double angl } } - public virtual void IsingZZ__ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2) + void IIntrinsicIsingZZ.ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2) { - IsingZZ__ControlledBody(controls, -angle, target1, target2); + ((IIntrinsicIsingZZ)this).ControlledBody(controls, -angle, target1, target2); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/M.cs b/src/Simulation/Simulators/QuantumSimulator/M.cs index 860daa5643e..0777dd05c54 100644 --- a/src/Simulation/Simulators/QuantumSimulator/M.cs +++ b/src/Simulation/Simulators/QuantumSimulator/M.cs @@ -1,17 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Diagnostics; -using System.Linq; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual Result M__Body(Qubit target) + Result IIntrinsicM.Body(Qubit target) { this.CheckQubit(target); //setting qubit as measured to allow for release diff --git a/src/Simulation/Simulators/QuantumSimulator/Measure.cs b/src/Simulation/Simulators/QuantumSimulator/Measure.cs index 56b0dfaf6fb..4ed4696dad0 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Measure.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Measure.cs @@ -2,14 +2,14 @@ // Licensed under the MIT License. using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual Result Measure__Body(IQArray paulis, IQArray targets) + Result IIntrinsicMeasure.Body(IQArray paulis, IQArray targets) { this.CheckQubits(targets); if (paulis.Length != targets.Length) diff --git a/src/Simulation/Simulators/QuantumSimulator/QuantumSimulator.cs b/src/Simulation/Simulators/QuantumSimulator/QuantumSimulator.cs index c99bced0ba2..8b8059f22be 100644 --- a/src/Simulation/Simulators/QuantumSimulator/QuantumSimulator.cs +++ b/src/Simulation/Simulators/QuantumSimulator/QuantumSimulator.cs @@ -2,11 +2,9 @@ // Licensed under the MIT License. using System; -using System.Linq; using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Common; using System.Runtime.InteropServices; -using System.Threading; using Microsoft.Quantum.Simulation.Simulators.Exceptions; using Microsoft.Quantum.Intrinsic.Interfaces; using System.Collections.Generic; diff --git a/src/Simulation/Simulators/QuantumSimulator/Qubit.cs b/src/Simulation/Simulators/QuantumSimulator/Qubit.cs index 010ccab7bf7..02424dfbc3e 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Qubit.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Qubit.cs @@ -5,7 +5,6 @@ using Microsoft.Quantum.Simulation.Core; using System; using System.Diagnostics; -using System.Runtime.InteropServices; namespace Microsoft.Quantum.Simulation.Simulators { diff --git a/src/Simulation/Simulators/QuantumSimulator/QubitManager.cs b/src/Simulation/Simulators/QuantumSimulator/QubitManager.cs index da2ac62b7cb..b1bcc7b09fa 100644 --- a/src/Simulation/Simulators/QuantumSimulator/QubitManager.cs +++ b/src/Simulation/Simulators/QuantumSimulator/QubitManager.cs @@ -5,7 +5,6 @@ using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators.Exceptions; using System.Diagnostics; -using System.Runtime.InteropServices; namespace Microsoft.Quantum.Simulation.Simulators { diff --git a/src/Simulation/Simulators/QuantumSimulator/R.cs b/src/Simulation/Simulators/QuantumSimulator/R.cs index fb3d85ab9ea..e0597eb2783 100644 --- a/src/Simulation/Simulators/QuantumSimulator/R.cs +++ b/src/Simulation/Simulators/QuantumSimulator/R.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void R__Body(Pauli pauli, double angle, Qubit target) + void IIntrinsicR.Body(Pauli pauli, double angle, Qubit target) { this.CheckQubit(target); CheckAngle(angle); @@ -17,25 +16,25 @@ public virtual void R__Body(Pauli pauli, double angle, Qubit target) R(this.Id, pauli, angle, (uint)target.Id); } - public virtual void R__AdjointBody(Pauli pauli, double angle, Qubit target) + void IIntrinsicR.AdjointBody(Pauli pauli, double angle, Qubit target) { - R__Body(pauli, -angle, target); + ((IIntrinsicR)this).Body(pauli, -angle, target); } - public virtual void R__ControlledBody(IQArray controls, Pauli pauli, double angle, Qubit target) + void IIntrinsicR.ControlledBody(IQArray controls, Pauli pauli, double angle, Qubit target) { this.CheckQubits(controls, target); CheckAngle(angle); SafeControlled(controls, - () => R__Body(pauli, angle, target), + () => ((IIntrinsicR)this).Body(pauli, angle, target), (count, ids) => MCR(this.Id, pauli, angle, count, ids, (uint)target.Id)); } - public virtual void R__ControlledAdjointBody(IQArray controls, Pauli pauli, double angle, Qubit target) + void IIntrinsicR.ControlledAdjointBody(IQArray controls, Pauli pauli, double angle, Qubit target) { - R__ControlledBody(controls, pauli, -angle, target); + ((IIntrinsicR)this).ControlledBody(controls, pauli, -angle, target); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/Random.cs b/src/Simulation/Simulators/QuantumSimulator/Random.cs deleted file mode 100644 index 419bf425112..00000000000 --- a/src/Simulation/Simulators/QuantumSimulator/Random.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 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 QSimrandom : Quantum.Intrinsic.Random - { - private uint SimulatorId { get; } - - public QSimrandom(QuantumSimulator m) : base(m) - { - this.SimulatorId = m.Id; - } - - public override Func, Int64> __Body__ => (p) => - { - return random_choice(this.SimulatorId, p.Length, p.ToArray()); - }; - } - } -} diff --git a/src/Simulation/Simulators/QuantumSimulator/Reset.cs b/src/Simulation/Simulators/QuantumSimulator/Reset.cs index 16f0ff3e39c..a8bce353976 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Reset.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Reset.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public void Reset__Body(Qubit target) + void IIntrinsicReset.Body(Qubit target) { // The native simulator doesn't have a reset operation, so simulate // it via an M follow by a conditional X. diff --git a/src/Simulation/Simulators/QuantumSimulator/Rx.cs b/src/Simulation/Simulators/QuantumSimulator/Rx.cs index ec092af18d9..32f65bd2d82 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Rx.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Rx.cs @@ -1,36 +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; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void Rx__Body(double angle, Qubit target) + void IIntrinsicRx.Body(double angle, Qubit target) { this.CheckQubit(target, nameof(target)); CheckAngle(angle); R(this.Id, Pauli.PauliX, angle, (uint)target.Id); } - public virtual void Rx__AdjointBody(double angle, Qubit target) + void IIntrinsicRx.AdjointBody(double angle, Qubit target) { - Rx__Body(-angle, target); + ((IIntrinsicRx)this).Body(-angle, target); } - public virtual void Rx__ControlledBody(IQArray controls, double angle, Qubit target) + void IIntrinsicRx.ControlledBody(IQArray controls, double angle, Qubit target) { this.CheckQubits(controls, target); CheckAngle(angle); MCR(this.Id, Pauli.PauliX, angle, (uint)controls.Length, controls.GetIds(), (uint)target.Id); } - public virtual void Rx__ControlledAdjointBody(IQArray controls, double angle, Qubit target) + void IIntrinsicRx.ControlledAdjointBody(IQArray controls, double angle, Qubit target) { - Rx__ControlledBody(controls, -angle, target); + ((IIntrinsicRx)this).ControlledBody(controls, -angle, target); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/Ry.cs b/src/Simulation/Simulators/QuantumSimulator/Ry.cs index 81962a986de..b76cca3ec86 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Ry.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Ry.cs @@ -1,36 +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; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void Ry__Body(double angle, Qubit target) + void IIntrinsicRy.Body(double angle, Qubit target) { this.CheckQubit(target, nameof(target)); CheckAngle(angle); R(this.Id, Pauli.PauliY, angle, (uint)target.Id); } - public virtual void Ry__AdjointBody(double angle, Qubit target) + void IIntrinsicRy.AdjointBody(double angle, Qubit target) { - Ry__Body(-angle, target); + ((IIntrinsicRy)this).Body(-angle, target); } - public virtual void Ry__ControlledBody(IQArray controls, double angle, Qubit target) + void IIntrinsicRy.ControlledBody(IQArray controls, double angle, Qubit target) { this.CheckQubits(controls, target); CheckAngle(angle); MCR(this.Id, Pauli.PauliY, angle, (uint)controls.Length, controls.GetIds(), (uint)target.Id); } - public virtual void Ry__ControlledAdjointBody(IQArray controls, double angle, Qubit target) + void IIntrinsicRy.ControlledAdjointBody(IQArray controls, double angle, Qubit target) { - Ry__ControlledBody(controls, -angle, target); + ((IIntrinsicRy)this).ControlledBody(controls, -angle, target); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/Rz.cs b/src/Simulation/Simulators/QuantumSimulator/Rz.cs index 6784d7eb149..8f0b259ca95 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Rz.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Rz.cs @@ -1,36 +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; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void Rz__Body(double angle, Qubit target) + void IIntrinsicRz.Body(double angle, Qubit target) { this.CheckQubit(target, nameof(target)); CheckAngle(angle); R(this.Id, Pauli.PauliZ, angle, (uint)target.Id); } - public virtual void Rz__AdjointBody(double angle, Qubit target) + void IIntrinsicRz.AdjointBody(double angle, Qubit target) { - Rz__Body(-angle, target); + ((IIntrinsicRz)this).Body(-angle, target); } - public virtual void Rz__ControlledBody(IQArray controls, double angle, Qubit target) + void IIntrinsicRz.ControlledBody(IQArray controls, double angle, Qubit target) { this.CheckQubits(controls, target); CheckAngle(angle); MCR(this.Id, Pauli.PauliZ, angle, (uint)controls.Length, controls.GetIds(), (uint)target.Id); } - public virtual void Rz__ControlledAdjointBody(IQArray controls, double angle, Qubit target) + void IIntrinsicRz.ControlledAdjointBody(IQArray controls, double angle, Qubit target) { - Rz__ControlledBody(controls, -angle, target); + ((IIntrinsicRz)this).ControlledBody(controls, -angle, target); } } } diff --git a/src/Simulation/Simulators/QuantumSimulator/S.cs b/src/Simulation/Simulators/QuantumSimulator/S.cs index c1e265bba3d..f3a06adab56 100644 --- a/src/Simulation/Simulators/QuantumSimulator/S.cs +++ b/src/Simulation/Simulators/QuantumSimulator/S.cs @@ -1,43 +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; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void S__Body(Qubit target) + void IIntrinsicS.Body(Qubit target) { this.CheckQubit(target); S(this.Id, (uint)target.Id); } - public virtual void S__ControlledBody(IQArray controls, Qubit target) + void IIntrinsicS.ControlledBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => S__Body(target), + () => ((IIntrinsicS)this).Body(target), (count, ids) => MCS(this.Id, count, ids, (uint)target.Id)); } - public virtual void S__AdjointBody(Qubit target) + void IIntrinsicS.AdjointBody(Qubit target) { this.CheckQubit(target); AdjS(this.Id, (uint)target.Id); } - public virtual void S__ControlledAdjointBody(IQArray controls, Qubit target) + void IIntrinsicS.ControlledAdjointBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => S__AdjointBody(target), + () => ((IIntrinsicS)this).AdjointBody(target), (count, ids) => MCAdjS(this.Id, count, ids, (uint)target.Id)); } } diff --git a/src/Simulation/Simulators/QuantumSimulator/SWAP.cs b/src/Simulation/Simulators/QuantumSimulator/SWAP.cs index 88f967a5bc3..b0be124a3b7 100644 --- a/src/Simulation/Simulators/QuantumSimulator/SWAP.cs +++ b/src/Simulation/Simulators/QuantumSimulator/SWAP.cs @@ -1,16 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void SWAP__Body(Qubit target1, Qubit target2) + void IIntrinsicSWAP.Body(Qubit target1, Qubit target2) { var ctrls1 = new QArray(target1); var ctrls2 = new QArray(target2); @@ -21,11 +20,11 @@ public virtual void SWAP__Body(Qubit target1, Qubit target2) MCX(this.Id, (uint)ctrls1.Length, ctrls1.GetIds(), (uint)target2.Id); } - public virtual void SWAP__ControlledBody(IQArray controls, Qubit target1, Qubit target2) + void IIntrinsicSWAP.ControlledBody(IQArray controls, Qubit target1, Qubit target2) { if ((controls == null) || (controls.Count == 0)) { - SWAP__Body(target1, target2); + ((IIntrinsicSWAP)this).Body(target1, target2); } else { diff --git a/src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs b/src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs index 0d5d5b53824..eb8b27f1ee6 100644 --- a/src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs +++ b/src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs @@ -505,86 +505,6 @@ public ApplyIfElse(SimulatorBase m) : base(m) => }; } - public class ApplyIfElseA : ApplyIfElseIntrinsicA - { - protected readonly SimulatorBase sim; - public ApplyIfElseA(SimulatorBase m) : base(m) => - sim = m; - - public override Func<(Result, IAdjointable, IAdjointable), QVoid> __Body__ => (q) => - { - (Result measurementResult, ICallable onZero, ICallable onOne) = q; - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, OperationFunctor.Body, null); - return QVoid.Instance; - }; - - public override Func<(Result, IAdjointable, IAdjointable), QVoid> __AdjointBody__ => (q) => - { - (Result measurementResult, ICallable onZero, ICallable onOne) = q; - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, OperationFunctor.Adjoint, null); - return QVoid.Instance; - }; - } - - public class ApplyIfElseC : ApplyIfElseIntrinsicC - { - protected readonly SimulatorBase sim; - public ApplyIfElseC(SimulatorBase m) : base(m) => - sim = m; - - public override Func<(Result, IControllable, IControllable), QVoid> __Body__ => (q) => - { - (Result measurementResult, ICallable onZero, ICallable onOne) = q; - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, OperationFunctor.Body, null); - return QVoid.Instance; - }; - - public override Func<(IQArray, (Result, IControllable, IControllable)), QVoid> __ControlledBody__ => (q) => - { - (IQArray ctrls, (Result measurementResult, ICallable onZero, ICallable onOne)) = q; - (var specKind, IQArray? controls) = ctrls?.Count == 0 ? (OperationFunctor.Body, null) : (OperationFunctor.Controlled, ctrls); - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, specKind, controls); - return QVoid.Instance; - }; - } - - public class ApplyIfElseCA : ApplyIfElseIntrinsicCA - { - protected readonly SimulatorBase sim; - public ApplyIfElseCA(SimulatorBase m) : base(m) => - sim = m; - - public override Func<(Result, IUnitary, IUnitary), QVoid> __Body__ => (q) => - { - (Result measurementResult, ICallable onZero, ICallable onOne) = q; - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, OperationFunctor.Body, null); - return QVoid.Instance; - }; - - public override Func<(Result, IUnitary, IUnitary), QVoid> __AdjointBody__ => (q) => - { - (Result measurementResult, ICallable onZero, ICallable onOne) = q; - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, OperationFunctor.Adjoint, null); - return QVoid.Instance; - }; - - public override Func<(IQArray, (Result, IUnitary, IUnitary)), QVoid> __ControlledBody__ => (q) => - { - (IQArray ctrls, (Result measurementResult, ICallable onZero, ICallable onOne)) = q; - (var specKind, IQArray? controls) = ctrls?.Count == 0 ? (OperationFunctor.Body, null) : (OperationFunctor.Controlled, ctrls); - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, specKind, controls); - return QVoid.Instance; - }; - - public override Func<(IQArray, (Result, IUnitary, IUnitary)), QVoid> __ControlledAdjointBody__ => (q) => - { - (IQArray ctrls, (Result measurementResult, ICallable onZero, ICallable onOne)) = q; - (var specKind, IQArray? controls) = ctrls?.Count == 0 ? (OperationFunctor.Adjoint, null) : (OperationFunctor.ControlledAdjoint, ctrls); - this.sim.BranchingBasedOnMeasurement(measurementResult, Result.Zero, onZero, onOne, specKind, controls); - return QVoid.Instance; - }; - } - public class ApplyConditionally : ApplyConditionallyIntrinsic { protected readonly SimulatorBase sim; @@ -599,86 +519,6 @@ public ApplyConditionally(SimulatorBase m) : base(m) => }; } - public class ApplyConditionallyA : ApplyConditionallyIntrinsicA - { - protected readonly SimulatorBase sim; - public ApplyConditionallyA(SimulatorBase m) : base(m) => - sim = m; - - public override Func<(IQArray, IQArray, IAdjointable, IAdjointable), QVoid> __Body__ => (q) => - { - (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp) = q; - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, OperationFunctor.Body, null); - return QVoid.Instance; - }; - - public override Func<(IQArray, IQArray, IAdjointable, IAdjointable), QVoid> __AdjointBody__ => (q) => - { - (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp) = q; - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, OperationFunctor.Adjoint, null); - return QVoid.Instance; - }; - } - - public class ApplyConditionallyC : ApplyConditionallyIntrinsicC - { - protected readonly SimulatorBase sim; - public ApplyConditionallyC(SimulatorBase m) : base(m) => - sim = m; - - public override Func<(IQArray, IQArray, IControllable, IControllable), QVoid> __Body__ => (q) => - { - (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp) = q; - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, OperationFunctor.Body, null); - return QVoid.Instance; - }; - - public override Func<(IQArray, (IQArray, IQArray, IControllable, IControllable)), QVoid> __ControlledBody__ => (q) => - { - (IQArray ctrls, (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp)) = q; - (var specKind, IQArray? controls) = ctrls?.Count == 0 ? (OperationFunctor.Body, null) : (OperationFunctor.Controlled, ctrls); - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, specKind, controls); - return QVoid.Instance; - }; - } - - public class ApplyConditionallyCA : ApplyConditionallyIntrinsicCA - { - protected readonly SimulatorBase sim; - public ApplyConditionallyCA(SimulatorBase m) : base(m) => - sim = m; - - public override Func<(IQArray, IQArray, IUnitary, IUnitary), QVoid> __Body__ => (q) => - { - (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp) = q; - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, OperationFunctor.Body, null); - return QVoid.Instance; - }; - - public override Func<(IQArray, IQArray, IUnitary, IUnitary), QVoid> __AdjointBody__ => (q) => - { - (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp) = q; - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, OperationFunctor.Adjoint, null); - return QVoid.Instance; - }; - - public override Func<(IQArray, (IQArray, IQArray, IUnitary, IUnitary)), QVoid> __ControlledBody__ => (q) => - { - (IQArray ctrls, (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp)) = q; - (var specKind, IQArray? controls) = ctrls?.Count == 0 ? (OperationFunctor.Body, null) : (OperationFunctor.Controlled, ctrls); - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, specKind, controls); - return QVoid.Instance; - }; - - public override Func<(IQArray, (IQArray, IQArray, IUnitary, IUnitary)), QVoid> __ControlledAdjointBody__ => (q) => - { - (IQArray ctrls, (IQArray measurementResults, IQArray resultsValues, ICallable onEqualOp, ICallable onNonEqualOp)) = q; - (var specKind, IQArray? controls) = ctrls?.Count == 0 ? (OperationFunctor.Adjoint, null) : (OperationFunctor.ControlledAdjoint, ctrls); - this.sim.BranchingBasedOnMeasurement(measurementResults, resultsValues, onEqualOp, onNonEqualOp, specKind, controls); - return QVoid.Instance; - }; - } - private Action BuildClause(ICallable op, OperationFunctor type, IQArray? ctrls) => type switch { diff --git a/src/Simulation/Simulators/QuantumSimulator/StackTrace.cs b/src/Simulation/Simulators/QuantumSimulator/StackTrace.cs index c0840d02100..63ede1e4457 100644 --- a/src/Simulation/Simulators/QuantumSimulator/StackTrace.cs +++ b/src/Simulation/Simulators/QuantumSimulator/StackTrace.cs @@ -1,13 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Text; using Microsoft.Quantum.Simulation.Core; using System.Diagnostics; -using System.Linq; namespace Microsoft.Quantum.Simulation.Common { diff --git a/src/Simulation/Simulators/QuantumSimulator/StateDumper.cs b/src/Simulation/Simulators/QuantumSimulator/StateDumper.cs index 9198616d9cd..1faa7bda1a5 100644 --- a/src/Simulation/Simulators/QuantumSimulator/StateDumper.cs +++ b/src/Simulation/Simulators/QuantumSimulator/StateDumper.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Simulation.Simulators diff --git a/src/Simulation/Simulators/QuantumSimulator/T.cs b/src/Simulation/Simulators/QuantumSimulator/T.cs index c95dde4528d..25ca2f61d48 100644 --- a/src/Simulation/Simulators/QuantumSimulator/T.cs +++ b/src/Simulation/Simulators/QuantumSimulator/T.cs @@ -1,43 +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; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void T__Body(Qubit target) + void IIntrinsicT.Body(Qubit target) { this.CheckQubit(target); T(this.Id, (uint)target.Id); } - public virtual void T__ControlledBody(IQArray controls, Qubit target) + void IIntrinsicT.ControlledBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => T__Body(target), + () => ((IIntrinsicT)this).Body(target), (count, ids) => MCT(this.Id, count, ids, (uint)target.Id)); } - public virtual void T__AdjointBody(Qubit target) + void IIntrinsicT.AdjointBody(Qubit target) { this.CheckQubit(target); AdjT(this.Id, (uint)target.Id); } - public virtual void T__ControlledAdjointBody(IQArray controls, Qubit target) + void IIntrinsicT.ControlledAdjointBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => T__AdjointBody(target), + () => ((IIntrinsicT)this).AdjointBody(target), (count, ids) => MCAdjT(this.Id, count, ids, (uint)target.Id)); } } diff --git a/src/Simulation/Simulators/QuantumSimulator/X.cs b/src/Simulation/Simulators/QuantumSimulator/X.cs index c01f5b65535..7af68a2b261 100644 --- a/src/Simulation/Simulators/QuantumSimulator/X.cs +++ b/src/Simulation/Simulators/QuantumSimulator/X.cs @@ -1,27 +1,26 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void X__Body(Qubit target) + void IIntrinsicX.Body(Qubit target) { this.CheckQubit(target); X(this.Id, (uint)target.Id); } - public virtual void X__ControlledBody(IQArray controls, Qubit target) + void IIntrinsicX.ControlledBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => X__Body(target), + () => ((IIntrinsicX)this).Body(target), (count, ids) => MCX(this.Id, count, ids, (uint)target.Id)); } } diff --git a/src/Simulation/Simulators/QuantumSimulator/Y.cs b/src/Simulation/Simulators/QuantumSimulator/Y.cs index 42fda7e38e7..8858b2202dd 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Y.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Y.cs @@ -1,27 +1,26 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void Y__Body(Qubit target) + void IIntrinsicY.Body(Qubit target) { this.CheckQubit(target); Y(this.Id, (uint)target.Id); } - public virtual void Y__ControlledBody(IQArray controls, Qubit target) + void IIntrinsicY.ControlledBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => Y__Body(target), + () => ((IIntrinsicY)this).Body(target), (count, ids) => MCY(this.Id, count, ids, (uint)target.Id)); } } diff --git a/src/Simulation/Simulators/QuantumSimulator/Z.cs b/src/Simulation/Simulators/QuantumSimulator/Z.cs index ef8a174c2a6..026f4f5c6d2 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Z.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Z.cs @@ -1,27 +1,26 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Runtime.InteropServices; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public virtual void Z__Body(Qubit target) + void IIntrinsicZ.Body(Qubit target) { this.CheckQubit(target); Z(this.Id, (uint)target.Id); } - public virtual void Z__ControlledBody(IQArray controls, Qubit target) + void IIntrinsicZ.ControlledBody(IQArray controls, Qubit target) { this.CheckQubits(controls, target); SafeControlled(controls, - () => Z__Body(target), + () => ((IIntrinsicZ)this).Body(target), (count, ids) => MCZ(this.Id, count, ids, (uint)target.Id)); } } diff --git a/src/Simulation/Simulators/ToffoliSimulator/Exp.cs b/src/Simulation/Simulators/ToffoliSimulator/Exp.cs index 5bd117c287e..6bead008ceb 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/Exp.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/Exp.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -13,7 +14,7 @@ public partial class ToffoliSimulator /// For the Toffoli simulator, the implementation flips a target qubit /// if the respective rotation is effectively an X gate. /// - public void Exp__Body(IQArray paulis, double angle, IQArray targets) + void IIntrinsicExp.Body(IQArray paulis, double angle, IQArray targets) { if (targets == null) return; @@ -38,7 +39,7 @@ public void Exp__Body(IQArray paulis, double angle, IQArray target /// The implementation of the adjoint specialization of the operation. /// For the Toffoli simulator *only*, this operation is self-adjoint. /// - public void Exp__AdjointBody(IQArray paulis, double angle, IQArray targets) => Exp__Body(paulis, angle, targets); + void IIntrinsicExp.AdjointBody(IQArray paulis, double angle, IQArray targets) => ((IIntrinsicExp)this).Body(paulis, angle, targets); /// /// The implementation of the controlled specialization of the operation. @@ -46,7 +47,7 @@ public void Exp__Body(IQArray paulis, double angle, IQArray target /// if the rotation is effectively an X gate and all of the control qubits /// are in the One state. /// - public void Exp__ControlledBody(IQArray controls, IQArray paulis, double angle, IQArray targets) + void IIntrinsicExp.ControlledBody(IQArray controls, IQArray paulis, double angle, IQArray targets) { if (targets == null) return; @@ -72,6 +73,6 @@ public void Exp__ControlledBody(IQArray controls, IQArray paulis, /// The implementation of the controlled adjoint specialization of the operation. /// For the Toffoli simulator *only*, the controlled specialization is self-adjoint. /// - public void Exp__ControlledAdjointBody(IQArray controls, IQArray paulis, double angle, IQArray targets) => Exp__ControlledBody(controls, paulis, angle, targets); + void IIntrinsicExp.ControlledAdjointBody(IQArray controls, IQArray paulis, double angle, IQArray targets) => ((IIntrinsicExp)this).ControlledBody(controls, paulis, angle, targets); } } diff --git a/src/Simulation/Simulators/ToffoliSimulator/H.cs b/src/Simulation/Simulators/ToffoliSimulator/H.cs index 9b9b3c45be3..184669a41bd 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/H.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/H.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -12,8 +13,8 @@ public partial class ToffoliSimulator /// The implementation of the operation. /// For the Toffoli simulator, the implementation throws a run-time error. /// - public void H__Body(Qubit target) => throw new NotImplementedException(); + void IIntrinsicH.Body(Qubit target) => throw new NotImplementedException(); - public void H__ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); + void IIntrinsicH.ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); } } diff --git a/src/Simulation/Simulators/ToffoliSimulator/Measure.cs b/src/Simulation/Simulators/ToffoliSimulator/Measure.cs index 5ed771006ff..886626d3213 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/Measure.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/Measure.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -16,7 +17,7 @@ public partial class ToffoliSimulator /// That is, Result.One is returned if an odd number of the measured qubits are /// in the One state. /// - public Result Measure__Body(IQArray paulis, IQArray targets) + Result IIntrinsicMeasure.Body(IQArray paulis, IQArray targets) { Qubit? f(Pauli p, Qubit q) => p switch { diff --git a/src/Simulation/Simulators/ToffoliSimulator/R.cs b/src/Simulation/Simulators/ToffoliSimulator/R.cs index 7c1fdd33d4e..b3960bb89c5 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/R.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/R.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -13,7 +14,7 @@ public partial class ToffoliSimulator /// For the Toffoli simulator, the implementation flips the target qubit /// if the rotation is effectively an X gate. /// - public void R__Body(Pauli pauli, double angle, Qubit target) + void IIntrinsicR.Body(Pauli pauli, double angle, Qubit target) { if (target == null) return; @@ -30,7 +31,7 @@ public void R__Body(Pauli pauli, double angle, Qubit target) /// The implementation of the adjoint specialization of the operation. /// For the Toffoli simulator *only*, this operation is self-adjoint. /// - public void R__AdjointBody(Pauli pauli, double angle, Qubit target) => R__Body(pauli, angle, target); + void IIntrinsicR.AdjointBody(Pauli pauli, double angle, Qubit target) => ((IIntrinsicR)this).Body(pauli, angle, target); /// /// The implementation of the controlled specialization of the operation. @@ -38,7 +39,7 @@ public void R__Body(Pauli pauli, double angle, Qubit target) /// if the rotation is effectively an X gate and all of the control qubits /// are in the One state. /// - public void R__ControlledBody(IQArray controls, Pauli pauli, double angle, Qubit target) + void IIntrinsicR.ControlledBody(IQArray controls, Pauli pauli, double angle, Qubit target) { if (target == null) return; @@ -56,6 +57,6 @@ public void R__ControlledBody(IQArray controls, Pauli pauli, double angle /// The implementation of the controlled adjoint specialization of the operation. /// For the Toffoli simulator *only*, the controlled specialization is self-adjoint. /// - public void R__ControlledAdjointBody(IQArray controls, Pauli pauli, double angle, Qubit target) => R__ControlledBody(controls, pauli, angle, target); + void IIntrinsicR.ControlledAdjointBody(IQArray controls, Pauli pauli, double angle, Qubit target) => ((IIntrinsicR)this).ControlledBody(controls, pauli, angle, target); } } diff --git a/src/Simulation/Simulators/ToffoliSimulator/Random.cs b/src/Simulation/Simulators/ToffoliSimulator/Random.cs deleted file mode 100644 index f1de531f998..00000000000 --- a/src/Simulation/Simulators/ToffoliSimulator/Random.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Linq; -using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Simulation.Simulators -{ - public partial class ToffoliSimulator - { - /// - /// Implementation of the Random operation for the Toffoli simulator. - /// - public class ToffSimRandom : Microsoft.Quantum.Intrinsic.Random - { - private ToffoliSimulator Simulator; - - /// - /// Constructs a new operation instance. - /// - /// The simulator that this operation affects. - public ToffSimRandom(ToffoliSimulator m) : base(m) - { - Simulator = m; - } - - /// - /// The implementation of the operation. - /// - public override Func, Int64> __Body__ => (probs) => - CommonUtils.SampleDistribution(probs, Simulator.RandomGenerator.NextDouble()); - } - } -} diff --git a/src/Simulation/Simulators/ToffoliSimulator/S.cs b/src/Simulation/Simulators/ToffoliSimulator/S.cs index 77c6b2544bb..944ef6d3e5c 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/S.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/S.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -12,12 +13,12 @@ public partial class ToffoliSimulator /// The implementation of the operation. /// For the Toffoli simulator, the implementation throws a run-time error. /// - public void S__Body(Qubit target) => throw new NotImplementedException(); + void IIntrinsicS.Body(Qubit target) => throw new NotImplementedException(); - public void S__ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); + void IIntrinsicS.ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); - public void S__AdjointBody(Qubit target) => throw new NotImplementedException(); + void IIntrinsicS.AdjointBody(Qubit target) => throw new NotImplementedException(); - public void S__ControlledAdjointBody(IQArray controls, Qubit target) => throw new NotImplementedException(); + void IIntrinsicS.ControlledAdjointBody(IQArray controls, Qubit target) => throw new NotImplementedException(); } } diff --git a/src/Simulation/Simulators/ToffoliSimulator/T.cs b/src/Simulation/Simulators/ToffoliSimulator/T.cs index 208009be8b4..509f7dbc01e 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/T.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/T.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -12,12 +13,12 @@ public partial class ToffoliSimulator /// The implementation of the operation. /// For the Toffoli simulator, the implementation throws a run-time error. /// - public void T__Body(Qubit target) => throw new NotImplementedException(); + void IIntrinsicT.Body(Qubit target) => throw new NotImplementedException(); - public void T__ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); + void IIntrinsicT.ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); - public void T__AdjointBody(Qubit target) => throw new NotImplementedException(); + void IIntrinsicT.AdjointBody(Qubit target) => throw new NotImplementedException(); - public void T__ControlledAdjointBody(IQArray controls, Qubit target) => throw new NotImplementedException(); + void IIntrinsicT.ControlledAdjointBody(IQArray controls, Qubit target) => throw new NotImplementedException(); } } diff --git a/src/Simulation/Simulators/ToffoliSimulator/X.cs b/src/Simulation/Simulators/ToffoliSimulator/X.cs index cf42191160e..a4ca14c003e 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/X.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/X.cs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -12,7 +12,7 @@ public partial class ToffoliSimulator /// The implementation of the operation. /// For the Toffoli simulator, the implementation flips the target qubit. /// - public void X__Body(Qubit target) + void IIntrinsicX.Body(Qubit target) { if (target == null) return; @@ -26,7 +26,7 @@ public void X__Body(Qubit target) /// For the Toffoli simulator, the implementation flips the target qubit /// if all of the control qubits are 1. /// - public void X__ControlledBody(IQArray controls, Qubit target) + void IIntrinsicX.ControlledBody(IQArray controls, Qubit target) { if (target == null) return; diff --git a/src/Simulation/Simulators/ToffoliSimulator/Y.cs b/src/Simulation/Simulators/ToffoliSimulator/Y.cs index aee499ba6de..c548d089154 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/Y.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/Y.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -12,8 +13,8 @@ public partial class ToffoliSimulator /// The implementation of the operation. /// For the Toffoli simulator, the implementation throws a run-time error. /// - public void Y__Body(Qubit target) => throw new NotImplementedException(); + void IIntrinsicY.Body(Qubit target) => throw new NotImplementedException(); - public void Y__ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); + void IIntrinsicY.ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); } } diff --git a/src/Simulation/Simulators/ToffoliSimulator/Z.cs b/src/Simulation/Simulators/ToffoliSimulator/Z.cs index 7044156fe0a..9afa0ab14a3 100644 --- a/src/Simulation/Simulators/ToffoliSimulator/Z.cs +++ b/src/Simulation/Simulators/ToffoliSimulator/Z.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Intrinsic.Interfaces; namespace Microsoft.Quantum.Simulation.Simulators { @@ -12,8 +13,8 @@ public partial class ToffoliSimulator /// The implementation of the operation. /// For the Toffoli simulator, the implementation throws a run-time error. /// - public void Z__Body(Qubit target) => throw new NotImplementedException(); + void IIntrinsicZ.Body(Qubit target) => throw new NotImplementedException(); - public void Z__ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); + void IIntrinsicZ.ControlledBody(IQArray controls, Qubit target) => throw new NotImplementedException(); } } diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs deleted file mode 100644 index 4bf60fd83dd..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs +++ /dev/null @@ -1,39 +0,0 @@ -// 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 deleted file mode 100644 index 70cb2a6d068..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs +++ /dev/null @@ -1,36 +0,0 @@ -// 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 deleted file mode 100644 index 74a4e5f61fa..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs +++ /dev/null @@ -1,28 +0,0 @@ -// 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 deleted file mode 100644 index 8db8b3733a1..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs +++ /dev/null @@ -1,36 +0,0 @@ -// 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 deleted file mode 100644 index bd72cde1e7e..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs +++ /dev/null @@ -1,36 +0,0 @@ -// 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 deleted file mode 100644 index 5c864aae74f..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs +++ /dev/null @@ -1,36 +0,0 @@ -// 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 deleted file mode 100644 index 1b64c5e7839..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs +++ /dev/null @@ -1,27 +0,0 @@ -// 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 deleted file mode 100644 index 60cf1ecd7b8..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs +++ /dev/null @@ -1,27 +0,0 @@ -// 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 deleted file mode 100644 index 08a566bc840..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs +++ /dev/null @@ -1,26 +0,0 @@ -// 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 deleted file mode 100644 index bee6d1fb7b3..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs +++ /dev/null @@ -1,26 +0,0 @@ -// 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 deleted file mode 100644 index ffb10e7e364..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs +++ /dev/null @@ -1,26 +0,0 @@ -// 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/AssertOperationsEqualInPlace.qs b/src/Simulation/TargetDefinitions/Decompositions/AssertOperationsEqualInPlace.qs index 427e3c50451..b6db789bc43 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/AssertOperationsEqualInPlace.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/AssertOperationsEqualInPlace.qs @@ -12,7 +12,7 @@ namespace Microsoft.Quantum.Diagnostics { internal operation IterateThroughCartesianPower (length : Int, value : Int, op : (Int[] => Unit)) : Unit { mutable bounds = new Int[length]; - for (i in 0 .. length - 1) + for i in 0 .. length - 1 { set bounds = bounds w/ i <- value; } @@ -33,7 +33,7 @@ namespace Microsoft.Quantum.Diagnostics { //computes the next element in the Cartesian product set arr = arr w/ 0 <- arr[0] + 1; - for (i in 0 .. Length(arr) - 2) + for i in 0 .. Length(arr) - 2 { if (arr[i] == bounds[i]) { @@ -73,7 +73,7 @@ namespace Microsoft.Quantum.Diagnostics { fail "qubits and stateIds must have the same length"; } - for (i in 0 .. Length(qubits) - 1) + for i in 0 .. Length(qubits) - 1 { let id = basis[i]; let qubit = qubits[i]; @@ -120,7 +120,7 @@ namespace Microsoft.Quantum.Diagnostics { internal operation AssertEqualOnBasisVector (basis : Int[], givenU : (Qubit[] => Unit), expectedU : (Qubit[] => Unit is Adj)) : Unit { let tolerance = 1e-5; - using (qubits = Qubit[Length(basis)]) { + use qubits = Qubit[Length(basis)] { AssertAllZeroWithinTolerance(qubits, tolerance); FlipToBasis(basis, qubits); givenU(qubits); diff --git a/src/Simulation/TargetDefinitions/Decompositions/AssertOperationsEqualReferenced.qs b/src/Simulation/TargetDefinitions/Decompositions/AssertOperationsEqualReferenced.qs index eed629789a1..8766380257a 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/AssertOperationsEqualReferenced.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/AssertOperationsEqualReferenced.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Diagnostics { internal operation PrepareEntangledState (left : Qubit[], right : Qubit[]) : Unit is Adj + Ctl { - for (idxQubit in 0 .. Length(left) - 1) + for idxQubit in 0 .. Length(left) - 1 { H(left[idxQubit]); Controlled X([left[idxQubit]], right[idxQubit]); @@ -55,7 +55,7 @@ namespace Microsoft.Quantum.Diagnostics { /// Operation defining the expected behavior for the operation under test. operation AssertOperationsEqualReferenced (nQubits : Int, actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj)) : Unit { // Prepare a reference register entangled with the target register. - using ((reference, target) = (Qubit[nQubits], Qubit[nQubits])) { + use (reference, target) = (Qubit[nQubits], Qubit[nQubits]) { PrepareEntangledState(reference, target); actual(target); Adjoint expected(target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs b/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs index 99772e845a0..e845e6cc422 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the doubly controlled–NOT (CCNOT) gate to three qubits. @@ -20,7 +19,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Controlled X([control1, control2], target); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.CCNOT") operation CCNOT (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj + Ctl { body (...) { Controlled X([control1, control2], target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs b/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs index 5b1601c799b..fcc55c6aaa6 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the doubly controlled–NOT (CCNOT) gate to three qubits. @@ -20,7 +19,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```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) diff --git a/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs b/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs index 7817f4fd480..ead30a51ac0 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the controlled-NOT (CNOT) gate to a pair of qubits. @@ -31,7 +30,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Controlled X([control], target); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.CNOT") operation CNOT (control : Qubit, target : Qubit) : Unit is Adj + Ctl { body (...) { Controlled X([control], target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs index 5a0bdeeb3f1..e891e67c7f3 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs @@ -4,7 +4,6 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Math; open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the exponential of a multi-qubit Pauli operator @@ -29,7 +28,6 @@ namespace Microsoft.Quantum.Intrinsic { /// the qubit register is to be rotated. /// ## qubits /// 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 { // Note that power must be converted to a double and used with 2.0 instead of 2 to allow for // negative exponents that result in a fractional denominator. diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs index 226630ffb79..10f986aac12 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs @@ -4,7 +4,6 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Math; open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the exponential of a multi-qubit Pauli operator @@ -29,7 +28,6 @@ namespace Microsoft.Quantum.Intrinsic { /// the qubit register is to be rotated. /// ## qubits /// 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 (...) { if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'target' must have the same length"; } diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs index 6bd54f9a036..74118c24c5d 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the exponential of a multi-qubit Pauli operator. @@ -23,7 +22,6 @@ namespace Microsoft.Quantum.Intrinsic { /// target register is to be rotated. /// ## qubits /// Register to apply the given rotation to. - @EnableTestingViaName("Test.TargetDefinitions.Exp") operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit is Adj + Ctl { body (...) { if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'qubits' must have the same length"; } diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs index 5131ac27048..2b25fdb2ea4 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs @@ -2,9 +2,7 @@ // 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) { @@ -12,7 +10,7 @@ namespace Microsoft.Quantum.Intrinsic { } else { // Length(paulis) > 1 within { - for (i in 0 .. Length(paulis) - 1) { + for i in 0 .. Length(paulis) - 1 { MapPauli(qubits[i], PauliZ, paulis[i]); } } diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs index b1bbc9d0dc4..ebc50d9aca4 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs @@ -2,9 +2,7 @@ // 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) { @@ -28,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { } else { // Length(paulis) > 2 within { - for (i in 0 .. Length(paulis) - 1) { + for i in 0 .. Length(paulis) - 1 { MapPauli(qubits[i], PauliZ, paulis[i]); } } diff --git a/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs index ff638cc18d9..f1c18932cc9 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Hadamard transformation to a single qubit. @@ -20,7 +19,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/I.qs b/src/Simulation/TargetDefinitions/Decompositions/I.qs index 39ddebc3797..debdfc92c68 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/I.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/I.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Performs the identity operation (no-op) on a single qubit. @@ -10,7 +9,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Remarks /// This is a no-op. It is provided for completeness and because /// sometimes it is useful to call the identity in an algorithm or to pass it as a parameter. - @EnableTestingViaName("Test.TargetDefinitions.I") operation I (target : Qubit) : Unit is Adj + Ctl { body (...) { } adjoint self; diff --git a/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs b/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs deleted file mode 100644 index 2c4b93c4ad1..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; - - /// # Summary - /// Applies the two qubit Ising $XX$ rotation gate. - /// - /// # Description - /// \begin{align} - /// XX(\theta) \mathrel{:=} - /// \begin{bmatrix} - /// \cos \theta & 0 & 0 & -i\sin \theta \\\\ - /// 0 & \cos \theta & -i\sin \theta & 0 \\\\ - /// 0 & -i\sin \theta & \cos \theta & 0 \\\\ - /// -i\sin \theta & 0 & 0 & \cos \theta - /// \end{bmatrix}. - /// \end{align} - /// - /// # Input - /// ## theta - /// The angle about which the qubits are rotated. - /// ## qubit0 - /// The first qubit input to the gate. - /// ## qubit1 - /// The second qubit input to the gate. - @EnableTestingViaName("Test.TargetDefinitions.IsingXX") - 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 deleted file mode 100644 index 51d3a76c929..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; - - /// # Summary - /// Applies the two qubit Ising $YY$ rotation gate. - /// - /// # Description - /// \begin{align} - /// YY(\theta) \mathrel{:=} - /// \begin{bmatrix} - /// \cos \theta & 0 & 0 & i\sin \theta \\\\ - /// 0 & \cos \theta & -i\sin \theta & 0 \\\\ - /// 0 & -i\sin \theta & \cos \theta & 0 \\\\ - /// i\sin \theta & 0 & 0 & \cos \theta - /// \end{bmatrix}. - /// \end{align} - /// - /// # Input - /// ## theta - /// The angle about which the qubits are rotated. - /// ## qubit0 - /// The first qubit input to the gate. - /// ## qubit1 - /// The second qubit input to the gate. - @EnableTestingViaName("Test.TargetDefinitions.IsingYY") - 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 deleted file mode 100644 index 16649bcffd6..00000000000 --- a/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; - - /// # Summary - /// Applies the two qubit Ising $ZZ$ rotation gate. - /// - /// # Description - /// \begin{align} - /// ZZ(\theta) \mathrel{:=} - /// \begin{bmatrix} - /// e^{-i \theta / 2} & 0 & 0 & 0 \\\\ - /// 0 & e^{-i \theta / 2} & 0 & 0 \\\\ - /// 0 & 0 & e^{-i \theta / 2} & 0 \\\\ - /// 0 & 0 & 0 & e^{i \theta / 2} - /// \end{bmatrix}. - /// \end{align} - /// - /// # Input - /// ## theta - /// The angle about which the qubits are rotated. - /// ## qubit0 - /// The first qubit input to the gate. - /// ## qubit1 - /// The second qubit input to the gate. - @EnableTestingViaName("Test.TargetDefinitions.IsingZZ") - 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/M.qs b/src/Simulation/TargetDefinitions/Decompositions/M.qs index a8fb33939a2..77f43700d34 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/M.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/M.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Performs a measurement of a single qubit in the @@ -29,7 +28,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Measure([PauliZ], [qubit]); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.M") operation M (qubit : Qubit) : Result { return Measure([PauliZ], [qubit]); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs index 183fbbfd0e3..13a09519900 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Targeting; /// # Summary @@ -26,7 +25,6 @@ namespace Microsoft.Quantum.Measurement { "BasicQuantumFunctionality", "MResetX is replaced by a supported implementation on all execution targets." ) - @EnableTestingViaName("Test.TargetDefinitions.MResetX") operation MResetX (target : Qubit) : Result { let result = Measure([PauliX], [target]); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs index d853dc9e8e5..0254cd0fc6e 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the X basis, @@ -21,7 +20,6 @@ namespace Microsoft.Quantum.Measurement { /// /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs index 0db2613018d..b83ed66273b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the X basis, @@ -21,7 +20,6 @@ namespace Microsoft.Quantum.Measurement { /// /// # Output /// The result of measuring `target` in the Pauli $X$ basis. - @EnableTestingViaName("Test.TargetDefinitions.MResetX") operation MResetX (target : Qubit) : Result { // Because the qubit cannot be reused after measurement, no actual // reset is required. diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs index 290b1fb8352..80beea433fb 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Targeting; /// # Summary @@ -26,7 +25,6 @@ namespace Microsoft.Quantum.Measurement { "BasicQuantumFunctionality", "MResetY is replaced by a supported implementation on all execution targets." ) - @EnableTestingViaName("Test.TargetDefinitions.MResetY") operation MResetY (target : Qubit) : Result { let result = Measure([PauliY], [target]); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs index 1bb586cfb8e..940b959b726 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the Y basis, @@ -21,7 +20,6 @@ namespace Microsoft.Quantum.Measurement { /// /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs index a2337edb403..20a68832277 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the Y basis, @@ -21,7 +20,6 @@ namespace Microsoft.Quantum.Measurement { /// /// # Output /// The result of measuring `target` in the Pauli $Y$ basis. - @EnableTestingViaName("Test.TargetDefinitions.MResetY") operation MResetY (target : Qubit) : Result { // Because the qubit cannot be reused after measurement, no actual // reset is required. diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs index 8bb4a8849ec..34db679ded6 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Targeting; /// # Summary @@ -26,7 +25,6 @@ namespace Microsoft.Quantum.Measurement { "BasicQuantumFunctionality", "MResetZ is replaced by a supported implementation on all execution targets." ) - @EnableTestingViaName("Test.TargetDefinitions.MResetZ") operation MResetZ (target : Qubit) : Result { let result = M(target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs index 53dac30786f..00fafd690db 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the Z basis, @@ -21,7 +20,6 @@ namespace Microsoft.Quantum.Measurement { /// /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs index a18daeb426b..2f0b3a56e24 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the Z basis, @@ -21,7 +20,6 @@ namespace Microsoft.Quantum.Measurement { /// /// # Output /// The result of measuring `target` in the Pauli $Z$ basis. - @EnableTestingViaName("Test.TargetDefinitions.MResetZ") operation MResetZ (target : Qubit) : Result { // Because the qubit cannot be reused after measurement, no actual // reset is required. diff --git a/src/Simulation/TargetDefinitions/Decompositions/Measure.qs b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs index 06f83119c47..bee6db6510b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Measure.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs @@ -2,7 +2,6 @@ // 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 @@ -39,7 +38,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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 { if (Length(bases) != Length(qubits)) { fail "Arrays 'bases' and 'qubits' must be of the same length."; } mutable res = One; @@ -53,9 +51,9 @@ namespace Microsoft.Quantum.Intrinsic { } } else { - using( q = Qubit() ) { + use q = Qubit() { H(q); - for( k in 0 .. Length(bases) - 1 ) { + 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); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs index 1bac07a8550..19d2f6c1c53 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs @@ -2,7 +2,6 @@ // 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 @@ -39,7 +38,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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 { if (Length(bases) != Length(qubits)) { fail "Arrays 'bases' and 'qubits' must be of the same length."; } if (Length(bases) == 1) { @@ -49,12 +47,12 @@ namespace Microsoft.Quantum.Intrinsic { return M(qubits[0]); } else { - using (q = Qubit()) { + use q = Qubit() { within { H(q); } apply { - for (k in 0 .. Length(bases) - 1) { + 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); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs b/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs index 680d9d74faf..bfdd2c314b1 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs @@ -2,9 +2,7 @@ // 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. diff --git a/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs b/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs index fb5dc304282..dfd4afd5cc1 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs @@ -2,9 +2,7 @@ // 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. diff --git a/src/Simulation/TargetDefinitions/Decompositions/R.qs b/src/Simulation/TargetDefinitions/Decompositions/R.qs index bd3f376d6d4..6a8572b92d2 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/R.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/R.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies a rotation about the given Pauli axis. @@ -26,7 +25,6 @@ namespace Microsoft.Quantum.Intrinsic { /// When called with `pauli = PauliI`, this operation applies /// a *global phase*. This phase can be significant /// when used with the `Controlled` functor. - @EnableTestingViaName("Test.TargetDefinitions.R") operation R (pauli : Pauli, theta : Double, qubit : Qubit) : Unit is Adj + Ctl { if (pauli == PauliX) { Rx(theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/R1.qs b/src/Simulation/TargetDefinitions/Decompositions/R1.qs index 02ed51439bd..87c88d9f4dc 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/R1.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/R1.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies a rotation about the $\ket{1}$ state by a given angle. @@ -25,7 +24,6 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliZ, theta, qubit); /// R(PauliI, -theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.R1") operation R1 (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { R(PauliZ, theta, qubit); R(PauliI, -theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs b/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs index 056e0ba9e54..8cd29fb0fba 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies a rotation about the $\ket{1}$ state by an angle specified @@ -35,7 +34,6 @@ namespace Microsoft.Quantum.Intrinsic { /// RFrac(PauliZ, -numerator, denominator + 1, qubit); /// RFrac(PauliI, numerator, denominator + 1, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.R1Frac") operation R1Frac (numerator : Int, power : Int, qubit : Qubit) : Unit is Adj + Ctl { RFrac(PauliZ, -numerator, power + 1, qubit); RFrac(PauliI, numerator, power + 1, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs b/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs index 2c1e1b7be37..e99a14bf512 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs @@ -4,7 +4,6 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Math; open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies a rotation about the given Pauli axis by an angle specified @@ -39,7 +38,6 @@ namespace Microsoft.Quantum.Intrinsic { /// // PI() is a Q# function that returns an approximation of π. /// R(pauli, -PI() * IntAsDouble(numerator) / IntAsDouble(2 ^ (power - 1)), qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.RFrac") operation RFrac (pauli : Pauli, numerator : Int, power : Int, qubit : Qubit) : Unit is Adj + Ctl { // Note that power must be converted to a double and used with 2.0 instead of 2 to allow for // negative exponents that result in a fractional denominator. diff --git a/src/Simulation/TargetDefinitions/Decompositions/Reset.qs b/src/Simulation/TargetDefinitions/Decompositions/Reset.qs index 651ba46e2fa..b6a06a5761b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Reset.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Reset.qs @@ -16,7 +16,6 @@ namespace Microsoft.Quantum.Intrinsic { "BasicQuantumFunctionality", "Reset is replaced by a supported implementation on all execution targets." ) - @EnableTestingViaName("Test.TargetDefinitions.Reset") operation Reset (qubit : Qubit) : Unit { if (M(qubit) == One) { X(qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs b/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs index 6a520c85bb7..9daa8d3c1d5 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Given an array of qubits, measure them and ensure they are in the |0⟩ state @@ -11,9 +10,8 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubits /// An array of qubits whose states are to be reset to $\ket{0}$. - @EnableTestingViaName("Test.TargetDefinitions.ResetAll") operation ResetAll (qubits : Qubit[]) : Unit { - for (qubit in qubits) { + for qubit in qubits { Reset(qubit); } } diff --git a/src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs index ef28b037cf2..f301194b99b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs @@ -2,7 +2,6 @@ // 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 @@ -11,7 +10,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// The qubit whose state is to be reset to $\ket{0}$. - @EnableTestingViaName("Test.TargetDefinitions.Reset") operation Reset (qubit : Qubit) : Unit { // This platform doesn't support use of a qubit after measurement, so // `Reset` is really just marking the qubit as measured. diff --git a/src/Simulation/TargetDefinitions/Decompositions/Rx.qs b/src/Simulation/TargetDefinitions/Decompositions/Rx.qs index e7cf9c8be1c..7c13b9d3715 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Rx.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Rx.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliX, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Rx") operation Rx (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { R(PauliX, theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs index e964eb00297..bcf07a180dd 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliX, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Rx") operation Rx (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { ApplyUncontrolledRx(theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/Ry.qs b/src/Simulation/TargetDefinitions/Decompositions/Ry.qs index ac1cb18dcfa..06c3c0bfa92 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Ry.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Ry.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliY, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Ry") operation Ry (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { R(PauliY, theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs index 5b6d46032b0..93b0f404e12 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliY, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Ry") operation Ry (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { ApplyUncontrolledRy(theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/Rz.qs b/src/Simulation/TargetDefinitions/Decompositions/Rz.qs index 08d0e2b239b..8aadfb3859b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Rz.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Rz.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliZ, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Rz") operation Rz (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { R(PauliZ, theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs index 09bfa6aec51..f8901ea1d6b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliZ, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Rz") operation Rz (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { ApplyUncontrolledRz(theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs index 09655566e04..a3522892acf 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the π/4 phase gate to a single qubit. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs b/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs index 5b987ea6b74..ee2c95aae1b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the SWAP gate to a pair of qubits. @@ -33,7 +32,6 @@ namespace Microsoft.Quantum.Intrinsic { /// CNOT(qubit2, qubit1); /// CNOT(qubit1, qubit2); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.SWAP") operation SWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit is Adj + Ctl { body (...) { within { diff --git a/src/Simulation/TargetDefinitions/Decompositions/SWAPFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/SWAPFromSinglyControlled.qs index 90eaf3fba0a..3beb32ccbd7 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/SWAPFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/SWAPFromSinglyControlled.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the SWAP gate to a pair of qubits. @@ -33,7 +32,6 @@ namespace Microsoft.Quantum.Intrinsic { /// CNOT(qubit2, qubit1); /// CNOT(qubit1, qubit2); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.SWAP") operation SWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit is Adj + Ctl { body (...) { ApplyUncontrolledSWAP(qubit1, qubit2); diff --git a/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs b/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs index 740925d833c..ff7ec846edf 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs @@ -3,7 +3,6 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; /// # Summary /// Sets a qubit to a given computational basis state by measuring the @@ -18,7 +17,6 @@ namespace Microsoft.Quantum.Measurement { /// # Remarks /// As an invariant of this operation, calling `M(q)` immediately /// after `SetToBasisState(result, q)` will return `result`. - @EnableTestingViaName("Test.TargetDefinitions.SetToBasisState") operation SetToBasisState(desired : Result, target : Qubit) : Unit { if (desired != M(target)) { X(target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs index 222ef97d9e1..e327305d5ae 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the π/8 gate to a single qubit. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs index d2808323a0d..32c31472a42 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs @@ -2,9 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; - @EnableTestingViaName("Test.TargetDefinitions.SpreadZ") internal operation SpreadZ (from : Qubit, to : Qubit[]) : Unit is Adj { if (Length(to) > 0) { CNOT(to[0], from); @@ -16,7 +14,6 @@ namespace Microsoft.Quantum.Intrinsic { } } - @EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhase") internal operation ApplyGlobalPhase (theta : Double) : Unit is Ctl + Adj { body (...) {} controlled (controls, (...)) { @@ -30,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { } } - @EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhaseFracWithR1Frac") internal operation ApplyGlobalPhaseFracWithR1Frac (numerator : Int, power : Int) : Unit is Adj + Ctl { body (...) {} controlled (ctrls, ...) { @@ -43,7 +39,6 @@ namespace Microsoft.Quantum.Intrinsic { } } - @EnableTestingViaName("Test.TargetDefinitions.MapPauli") internal operation MapPauli (qubit : Qubit, from : Pauli, to : Pauli) : Unit is Adj { if (from == to) { } @@ -73,13 +68,12 @@ 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]) { + use temps = Qubit[numControlPairs] { within { - for (numPair in 0 .. numControlPairs - 1) { // constant depth + for numPair in 0 .. numControlPairs - 1 { // constant depth PhaseCCX(controls[2*numPair], controls[2*numPair + 1], temps[numPair]); } } @@ -90,7 +84,6 @@ namespace Microsoft.Quantum.Intrinsic { } } - @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); @@ -106,7 +99,6 @@ namespace Microsoft.Quantum.Intrinsic { H(target); } - @EnableTestingViaName("Test.TargetDefinitions.ReducedDyadicFraction") internal function ReducedDyadicFraction (numerator : Int, denominatorPowerOfTwo : Int) : (Int, Int) { if (numerator == 0) { return (0,0); } mutable num = numerator; @@ -118,7 +110,6 @@ namespace Microsoft.Quantum.Intrinsic { return (num,denPow); } - @EnableTestingViaName("Test.TargetDefinitions.ReducedDyadicFractionPeriodic") internal function ReducedDyadicFractionPeriodic (numerator : Int, denominatorPowerOfTwo : Int) : (Int, Int) { let (k,n) = ReducedDyadicFraction(numerator,denominatorPowerOfTwo); // k is odd, or (k,n) are both 0 let period = 2*2^n; // \pi k / 2^n is 2\pi periodic, therefore k is 2 * 2^n periodic @@ -129,30 +120,28 @@ namespace Microsoft.Quantum.Intrinsic { // TODO(swernli): Consider removing this in favor of pulling Microsoft.Quantum.Arrays.Subarray // into the runtime. - @EnableTestingViaName("Test.TargetDefinitions.Subarray") internal function Subarray<'T> (indices : Int[], array : 'T[]) : 'T[] { let nSliced = Length(indices); mutable sliced = new 'T[nSliced]; - for (idx in 0 .. nSliced - 1) { + for idx in 0 .. nSliced - 1 { set sliced w/= idx <- array[indices[idx]]; } return sliced; } - @EnableTestingViaName("Test.TargetDefinitions.IndicesOfNonIdentity") internal function IndicesOfNonIdentity (paulies : Pauli[]) : Int[] { mutable nonIdPauliCount = 0; - for (i in 0 .. Length(paulies) - 1) { + for i in 0 .. Length(paulies) - 1 { if (paulies[i] != PauliI) { set nonIdPauliCount += 1; } } mutable indices = new Int[nonIdPauliCount]; mutable index = 0; - for (i in 0 .. Length(paulies) - 1) { + for i in 0 .. Length(paulies) - 1 { if (paulies[i] != PauliI) { set indices w/= index <- i; set index = index + 1; @@ -162,7 +151,6 @@ namespace Microsoft.Quantum.Intrinsic { return indices; } - @EnableTestingViaName("Test.TargetDefinitions.RemovePauliI") internal function RemovePauliI (paulis : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) { let indices = IndicesOfNonIdentity(paulis); let newPaulis = Subarray(indices, paulis); diff --git a/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs index e33e1c88263..1441748ff54 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Pauli $X$ gate. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs index 7636e127f22..71499ff03ac 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Pauli $Y$ gate. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs index 146bfc5da6d..7072a4f17c9 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Pauli $Z$ gate. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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); diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRx.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRx.cs deleted file mode 100644 index df14696b85f..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRx.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_ApplyUncontrolledRx : IOperationFactory - { - void ApplyUncontrolledRx__Body(double angle, Qubit target); - - void ApplyUncontrolledRx__AdjointBody(double angle, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRy.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRy.cs deleted file mode 100644 index c817abd4cd9..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRy.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_ApplyUncontrolledRy : IOperationFactory - { - void ApplyUncontrolledRy__Body(double angle, Qubit target); - - void ApplyUncontrolledRy__AdjointBody(double angle, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRz.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRz.cs deleted file mode 100644 index 97bab6ea276..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledRz.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_ApplyUncontrolledRz : IOperationFactory - { - void ApplyUncontrolledRz__Body(double angle, Qubit target); - - void ApplyUncontrolledRz__AdjointBody(double angle, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledS.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledS.cs deleted file mode 100644 index 2ffe2a2e9af..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledS.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_ApplyUncontrolledS : IOperationFactory - { - void ApplyUncontrolledS__Body(Qubit target); - - void ApplyUncontrolledS__AdjointBody(Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledY.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledY.cs deleted file mode 100644 index a280bbc4d5c..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledY.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_ApplyUncontrolledY : IOperationFactory - { - void ApplyUncontrolledY__Body(Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Exp.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_Exp.cs deleted file mode 100644 index f02267efb24..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Exp.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_Exp : IOperationFactory - { - void Exp__Body(IQArray paulis, double angle, IQArray targets); - - void Exp__AdjointBody(IQArray paulis, double angle, IQArray targets); - - void Exp__ControlledBody(IQArray controls, IQArray paulis, double angle, IQArray targets); - - void Exp__ControlledAdjointBody(IQArray controls, IQArray paulis, double angle, IQArray targets); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingXX.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingXX.cs deleted file mode 100644 index 364d078bd31..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingXX.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_IsingXX : IOperationFactory - { - void IsingXX__Body(double angle, Qubit target1, Qubit target2); - - void IsingXX__AdjointBody(double angle, Qubit target1, Qubit target2); - - void IsingXX__ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2); - - void IsingXX__ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingYY.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingYY.cs deleted file mode 100644 index 606161eafda..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingYY.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_IsingYY : IOperationFactory - { - void IsingYY__Body(double angle, Qubit target1, Qubit target2); - - void IsingYY__AdjointBody(double angle, Qubit target1, Qubit target2); - - void IsingYY__ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2); - - void IsingYY__ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingZZ.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingZZ.cs deleted file mode 100644 index e53f81f828d..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_IsingZZ.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_IsingZZ : IOperationFactory - { - void IsingZZ__Body(double angle, Qubit target1, Qubit target2); - - void IsingZZ__AdjointBody(double angle, Qubit target1, Qubit target2); - - void IsingZZ__ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2); - - void IsingZZ__ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Measure.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_Measure.cs deleted file mode 100644 index 09caaa5ac47..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Measure.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_Measure : IOperationFactory - { - Result Measure__Body(IQArray paulis, IQArray targets); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_R.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_R.cs deleted file mode 100644 index d7853d09844..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_R.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_R : IOperationFactory - { - void R__Body(Pauli pauli, double angle, Qubit target); - - void R__AdjointBody(Pauli pauli, double angle, Qubit target); - - void R__ControlledBody(IQArray controls, Pauli pauli, double angle, Qubit target); - - void R__ControlledAdjointBody(IQArray controls, Pauli pauli, double angle, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Rx.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_Rx.cs deleted file mode 100644 index cad8505a864..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Rx.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_Rx : IOperationFactory - { - void Rx__Body(double angle, Qubit target); - - void Rx__AdjointBody(double angle, Qubit target); - - void Rx__ControlledBody(IQArray controls, double angle, Qubit target); - - void Rx__ControlledAdjointBody(IQArray controls, double angle, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Ry.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_Ry.cs deleted file mode 100644 index c8cee96909b..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Ry.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_Ry : IOperationFactory - { - void Ry__Body(double angle, Qubit target); - - void Ry__AdjointBody(double angle, Qubit target); - - void Ry__ControlledBody(IQArray controls, double angle, Qubit target); - - void Ry__ControlledAdjointBody(IQArray controls, double angle, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Rz.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_Rz.cs deleted file mode 100644 index 716e68c6dec..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Rz.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_Rz : IOperationFactory - { - void Rz__Body(double angle, Qubit target); - - void Rz__AdjointBody(double angle, Qubit target); - - void Rz__ControlledBody(IQArray controls, double angle, Qubit target); - - void Rz__ControlledAdjointBody(IQArray controls, double angle, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_S.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_S.cs deleted file mode 100644 index f26c0923d2a..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_S.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_S : IOperationFactory - { - void S__Body(Qubit target); - - void S__AdjointBody(Qubit target); - - void S__ControlledBody(IQArray controls, Qubit target); - - void S__ControlledAdjointBody(IQArray controls, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_SWAP.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_SWAP.cs deleted file mode 100644 index a987d1bcf3b..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_SWAP.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_SWAP : IOperationFactory - { - void SWAP__Body(Qubit target1, Qubit target2); - - void SWAP__ControlledBody(IQArray controls, Qubit target1, Qubit target2); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_T.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_T.cs deleted file mode 100644 index 1e665fc087f..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_T.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_T : IOperationFactory - { - void T__Body(Qubit target); - - void T__AdjointBody(Qubit target); - - void T__ControlledBody(IQArray controls, Qubit target); - - void T__ControlledAdjointBody(IQArray controls, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Z.cs b/src/Simulation/TargetDefinitions/Interfaces/IGate_Z.cs deleted file mode 100644 index 1264e6cd20a..00000000000 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Z.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; - -namespace Microsoft.Quantum.Intrinsic.Interfaces -{ - public interface IGate_Z : IOperationFactory - { - void Z__Body(Qubit target); - - void Z__ControlledBody(IQArray controls, Qubit target); - } -} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledZ.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyControlledX.cs similarity index 60% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledZ.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyControlledX.cs index ce04925ca51..b45cc6fc6cb 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledZ.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyControlledX.cs @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_ApplyUncontrolledZ : IOperationFactory + public interface IIntrinsicApplyControlledX : IOperationFactory { - void ApplyUncontrolledZ__Body(Qubit target); + void Body(Qubit control, Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledH.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyControlledZ.cs similarity index 60% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledH.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyControlledZ.cs index 6c3a3853527..dd6ad75933b 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledH.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyControlledZ.cs @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_ApplyUncontrolledH : IOperationFactory + public interface IIntrinsicApplyControlledZ : IOperationFactory { - void ApplyUncontrolledH__Body(Qubit target); + void Body(Qubit control, Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Reset.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledH.cs similarity index 65% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_Reset.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledH.cs index 7d9111327ad..3d53fcaa85b 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Reset.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledH.cs @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_Reset : IOperationFactory + public interface IIntrinsicApplyUncontrolledH : IOperationFactory { - void Reset__Body(Qubit target); + void Body(Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_H.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRx.cs similarity index 54% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_H.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRx.cs index a1cce04429e..96b459de2f2 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_H.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRx.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_H : IOperationFactory + public interface IIntrinsicApplyUncontrolledRx : IOperationFactory { - void H__Body(Qubit target); + void Body(double angle, Qubit target); - void H__ControlledBody(IQArray controls, Qubit target); + void AdjointBody(double angle, Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_X.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRy.cs similarity index 54% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_X.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRy.cs index 17d5aee37e3..b529aff8745 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_X.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRy.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_X : IOperationFactory + public interface IIntrinsicApplyUncontrolledRy : IOperationFactory { - void X__Body(Qubit target); + void Body(double angle, Qubit target); - void X__ControlledBody(IQArray controls, Qubit target); + void AdjointBody(double angle, Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_Y.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRz.cs similarity index 54% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_Y.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRz.cs index 87fbef8300e..105e43832fd 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_Y.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledRz.cs @@ -1,15 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_Y : IOperationFactory + public interface IIntrinsicApplyUncontrolledRz : IOperationFactory { - void Y__Body(Qubit target); + void Body(double angle, Qubit target); - void Y__ControlledBody(IQArray controls, Qubit target); + void AdjointBody(double angle, Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledX.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledS.cs similarity index 58% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledX.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledS.cs index 1f7163e9af1..7da220e5c19 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledX.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledS.cs @@ -1,13 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_ApplyUncontrolledX : IOperationFactory + public interface IIntrinsicApplyUncontrolledS : IOperationFactory { - void ApplyUncontrolledX__Body(Qubit target); + void Body(Qubit target); + + void AdjointBody(Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledSWAP.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledSWAP.cs new file mode 100644 index 00000000000..bb8d6aa87f7 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledSWAP.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicApplyUncontrolledSWAP : IOperationFactory + { + void Body(Qubit qubit1, Qubit qubit2); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyControlledX.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledT.cs similarity index 58% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyControlledX.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledT.cs index 180c37afce2..f54d4585668 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyControlledX.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledT.cs @@ -1,13 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_ApplyControlledX : IOperationFactory + public interface IIntrinsicApplyUncontrolledT : IOperationFactory { - void ApplyControlledX__Body(Qubit control, Qubit target); + void Body(Qubit target); + + void AdjointBody(Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledX.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledX.cs new file mode 100644 index 00000000000..47676385be1 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledX.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicApplyUncontrolledX : IOperationFactory + { + void Body(Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledY.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledY.cs new file mode 100644 index 00000000000..e838c812409 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledY.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicApplyUncontrolledY : IOperationFactory + { + void Body(Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledZ.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledZ.cs new file mode 100644 index 00000000000..130d50a755e --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicApplyUncontrolledZ.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicApplyUncontrolledZ : IOperationFactory + { + void Body(Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicExp.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicExp.cs new file mode 100644 index 00000000000..b2f248ddea3 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicExp.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicExp : IOperationFactory + { + void Body(IQArray paulis, double angle, IQArray targets); + + void AdjointBody(IQArray paulis, double angle, IQArray targets); + + void ControlledBody(IQArray controls, IQArray paulis, double angle, IQArray targets); + + void ControlledAdjointBody(IQArray controls, IQArray paulis, double angle, IQArray targets); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledSWAP.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicH.cs similarity index 56% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledSWAP.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicH.cs index e3e07a58db3..69c31d58538 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledSWAP.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicH.cs @@ -1,13 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_ApplyUncontrolledSWAP : IOperationFactory + public interface IIntrinsicH : IOperationFactory { - void ApplyUncontrolledSWAP__Body(Qubit qubit1, Qubit qubit2); + void Body(Qubit target); + + void ControlledBody(IQArray controls, Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingXX.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingXX.cs new file mode 100644 index 00000000000..ab75fc70631 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingXX.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicIsingXX : IOperationFactory + { + void Body(double angle, Qubit target1, Qubit target2); + + void AdjointBody(double angle, Qubit target1, Qubit target2); + + void ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2); + + void ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingYY.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingYY.cs new file mode 100644 index 00000000000..925cd2ff85d --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingYY.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicIsingYY : IOperationFactory + { + void Body(double angle, Qubit target1, Qubit target2); + + void AdjointBody(double angle, Qubit target1, Qubit target2); + + void ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2); + + void ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingZZ.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingZZ.cs new file mode 100644 index 00000000000..b7596ae74f8 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicIsingZZ.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicIsingZZ : IOperationFactory + { + void Body(double angle, Qubit target1, Qubit target2); + + void AdjointBody(double angle, Qubit target1, Qubit target2); + + void ControlledBody(IQArray controls, double angle, Qubit target1, Qubit target2); + + void ControlledAdjointBody(IQArray controls, double angle, Qubit target1, Qubit target2); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_M.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicM.cs similarity index 66% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_M.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicM.cs index 6cce4c7c6a5..9ca0649b202 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_M.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicM.cs @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_M : IOperationFactory + public interface IIntrinsicM : IOperationFactory { - Result M__Body(Qubit target); + Result Body(Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicMeasure.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicMeasure.cs new file mode 100644 index 00000000000..e37209415b4 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicMeasure.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicMeasure : IOperationFactory + { + Result Body(IQArray paulis, IQArray targets); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicR.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicR.cs new file mode 100644 index 00000000000..2e64412edcb --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicR.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicR : IOperationFactory + { + void Body(Pauli pauli, double angle, Qubit target); + + void AdjointBody(Pauli pauli, double angle, Qubit target); + + void ControlledBody(IQArray controls, Pauli pauli, double angle, Qubit target); + + void ControlledAdjointBody(IQArray controls, Pauli pauli, double angle, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicReset.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicReset.cs new file mode 100644 index 00000000000..44630470955 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicReset.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicReset : IOperationFactory + { + void Body(Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRx.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRx.cs new file mode 100644 index 00000000000..c71b59eb55b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRx.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicRx : IOperationFactory + { + void Body(double angle, Qubit target); + + void AdjointBody(double angle, Qubit target); + + void ControlledBody(IQArray controls, double angle, Qubit target); + + void ControlledAdjointBody(IQArray controls, double angle, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRy.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRy.cs new file mode 100644 index 00000000000..847e47022f9 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRy.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicRy : IOperationFactory + { + void Body(double angle, Qubit target); + + void AdjointBody(double angle, Qubit target); + + void ControlledBody(IQArray controls, double angle, Qubit target); + + void ControlledAdjointBody(IQArray controls, double angle, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRz.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRz.cs new file mode 100644 index 00000000000..55d2edc987e --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicRz.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicRz : IOperationFactory + { + void Body(double angle, Qubit target); + + void AdjointBody(double angle, Qubit target); + + void ControlledBody(IQArray controls, double angle, Qubit target); + + void ControlledAdjointBody(IQArray controls, double angle, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicS.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicS.cs new file mode 100644 index 00000000000..89210374a33 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicS.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicS : IOperationFactory + { + void Body(Qubit target); + + void AdjointBody(Qubit target); + + void ControlledBody(IQArray controls, Qubit target); + + void ControlledAdjointBody(IQArray controls, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledT.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicSWAP.cs similarity index 53% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledT.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicSWAP.cs index e06d80675a6..4532936adcd 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyUncontrolledT.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicSWAP.cs @@ -6,10 +6,10 @@ namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_ApplyUncontrolledT : IOperationFactory + public interface IIntrinsicSWAP : IOperationFactory { - void ApplyUncontrolledT__Body(Qubit target); + void Body(Qubit target1, Qubit target2); - void ApplyUncontrolledT__AdjointBody(Qubit target); + void ControlledBody(IQArray controls, Qubit target1, Qubit target2); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicT.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicT.cs new file mode 100644 index 00000000000..16998337cb5 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicT.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicT : IOperationFactory + { + void Body(Qubit target); + + void AdjointBody(Qubit target); + + void ControlledBody(IQArray controls, Qubit target); + + void ControlledAdjointBody(IQArray controls, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyControlledZ.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicX.cs similarity index 56% rename from src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyControlledZ.cs rename to src/Simulation/TargetDefinitions/Interfaces/IIntrinsicX.cs index f1277c03508..577fcc0a97f 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IGate_ApplyControlledZ.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicX.cs @@ -1,13 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using Microsoft.Quantum.Simulation.Core; namespace Microsoft.Quantum.Intrinsic.Interfaces { - public interface IGate_ApplyControlledZ : IOperationFactory + public interface IIntrinsicX : IOperationFactory { - void ApplyControlledZ__Body(Qubit control, Qubit target); + void Body(Qubit target); + + void ControlledBody(IQArray controls, Qubit target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicY.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicY.cs new file mode 100644 index 00000000000..7687d34fa30 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicY.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicY : IOperationFactory + { + void Body(Qubit target); + + void ControlledBody(IQArray controls, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicZ.cs b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicZ.cs new file mode 100644 index 00000000000..0cd14cc7396 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Interfaces/IIntrinsicZ.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Intrinsic.Interfaces +{ + public interface IIntrinsicZ : IOperationFactory + { + void Body(Qubit target); + + void ControlledBody(IQArray controls, Qubit target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IQSharpCore.cs b/src/Simulation/TargetDefinitions/Interfaces/IQSharpCore.cs index 6c47d4dd93e..230536babe0 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IQSharpCore.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IQSharpCore.cs @@ -4,14 +4,14 @@ namespace Microsoft.Quantum.Intrinsic.Interfaces { public interface IQSharpCore : - IGate_Exp, - IGate_H, - IGate_Measure, - IGate_R, - IGate_S, - IGate_T, - IGate_X, - IGate_Y, - IGate_Z + IIntrinsicExp, + IIntrinsicH, + IIntrinsicMeasure, + IIntrinsicR, + IIntrinsicS, + IIntrinsicT, + IIntrinsicX, + IIntrinsicY, + IIntrinsicZ { } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IType1Core.cs b/src/Simulation/TargetDefinitions/Interfaces/IType1Core.cs index fbf02b06a45..23ec062a98b 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IType1Core.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IType1Core.cs @@ -4,18 +4,18 @@ namespace Microsoft.Quantum.Intrinsic.Interfaces { public interface IType1Core : - IGate_ApplyControlledX, - IGate_ApplyControlledZ, - IGate_ApplyUncontrolledH, - IGate_ApplyUncontrolledRx, - IGate_ApplyUncontrolledRy, - IGate_ApplyUncontrolledRz, - IGate_ApplyUncontrolledS, - IGate_ApplyUncontrolledT, - IGate_ApplyUncontrolledX, - IGate_ApplyUncontrolledY, - IGate_ApplyUncontrolledZ, - IGate_M, - IGate_Reset + IIntrinsicApplyControlledX, + IIntrinsicApplyControlledZ, + IIntrinsicApplyUncontrolledH, + IIntrinsicApplyUncontrolledRx, + IIntrinsicApplyUncontrolledRy, + IIntrinsicApplyUncontrolledRz, + IIntrinsicApplyUncontrolledS, + IIntrinsicApplyUncontrolledT, + IIntrinsicApplyUncontrolledX, + IIntrinsicApplyUncontrolledY, + IIntrinsicApplyUncontrolledZ, + IIntrinsicM, + IIntrinsicReset { } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IType2Core.cs b/src/Simulation/TargetDefinitions/Interfaces/IType2Core.cs index 3603389e9f4..24ec4127be6 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IType2Core.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IType2Core.cs @@ -4,19 +4,19 @@ namespace Microsoft.Quantum.Intrinsic.Interfaces { public interface IType2Core : - IGate_H, - IGate_IsingXX, - IGate_IsingYY, - IGate_IsingZZ, - IGate_M, - IGate_Rx, - IGate_Ry, - IGate_Rz, - IGate_S, - IGate_SWAP, - IGate_T, - IGate_X, - IGate_Y, - IGate_Z + IIntrinsicH, + IIntrinsicIsingXX, + IIntrinsicIsingYY, + IIntrinsicIsingZZ, + IIntrinsicM, + IIntrinsicRx, + IIntrinsicRy, + IIntrinsicRz, + IIntrinsicS, + IIntrinsicSWAP, + IIntrinsicT, + IIntrinsicX, + IIntrinsicY, + IIntrinsicZ { } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Interfaces/IType3Core.cs b/src/Simulation/TargetDefinitions/Interfaces/IType3Core.cs index 9c34efb953e..fb79a8894c6 100644 --- a/src/Simulation/TargetDefinitions/Interfaces/IType3Core.cs +++ b/src/Simulation/TargetDefinitions/Interfaces/IType3Core.cs @@ -4,19 +4,19 @@ namespace Microsoft.Quantum.Intrinsic.Interfaces { public interface IType3Core : - IGate_ApplyControlledX, - IGate_ApplyControlledZ, - IGate_ApplyUncontrolledH, - IGate_ApplyUncontrolledRx, - IGate_ApplyUncontrolledRy, - IGate_ApplyUncontrolledRz, - IGate_ApplyUncontrolledS, - IGate_ApplyUncontrolledSWAP, - IGate_ApplyUncontrolledT, - IGate_ApplyUncontrolledX, - IGate_ApplyUncontrolledY, - IGate_ApplyUncontrolledZ, - IGate_M, - IGate_Reset + IIntrinsicApplyControlledX, + IIntrinsicApplyControlledZ, + IIntrinsicApplyUncontrolledH, + IIntrinsicApplyUncontrolledRx, + IIntrinsicApplyUncontrolledRy, + IIntrinsicApplyUncontrolledRz, + IIntrinsicApplyUncontrolledS, + IIntrinsicApplyUncontrolledSWAP, + IIntrinsicApplyUncontrolledT, + IIntrinsicApplyUncontrolledX, + IIntrinsicApplyUncontrolledY, + IIntrinsicApplyUncontrolledZ, + IIntrinsicM, + IIntrinsicReset { } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs index 0c5417ada18..1fcc9b663f9 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs @@ -2,7 +2,6 @@ // 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 @@ -32,7 +31,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// CNOT(control, target); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX") internal operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs index c91154afdab..de997a2bd74 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Controlled Z([control], target); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ") internal operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs index 8b0f82af9c2..dc282b001e3 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs @@ -2,7 +2,6 @@ // 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 @@ -21,7 +20,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs index af0e8fcac43..67ec399dc17 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs @@ -2,7 +2,6 @@ // 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 @@ -29,7 +28,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliX, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRx") internal operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs index 4c63a72fffe..b01e95321d8 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs @@ -2,7 +2,6 @@ // 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 @@ -29,7 +28,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliY, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRy") internal operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs index ffeb44ab440..4ae8e69c84c 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs @@ -2,7 +2,6 @@ // 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 @@ -29,7 +28,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliZ, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRz") internal operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs index f8fe46dd430..4314b1be9aa 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs @@ -2,7 +2,6 @@ // 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 @@ -20,7 +19,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS") internal operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledSWAP.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledSWAP.qs index 0bce09f38d6..5131366d57f 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledSWAP.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledSWAP.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the SWAP gate to a pair of qubits. Note that the Controlled functor @@ -34,7 +33,6 @@ namespace Microsoft.Quantum.Intrinsic { /// CNOT(qubit2, qubit1); /// CNOT(qubit1, qubit2); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledSWAP") operation ApplyUncontrolledSWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit is Adj { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs index 2fd4b11d41d..2a51a407196 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs @@ -2,7 +2,6 @@ // 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 @@ -20,7 +19,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT") internal operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs index 45a27d9a5f6..3ef07a1052b 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs @@ -2,7 +2,6 @@ // 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. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs index 8e9a2fe20bb..4209b2d3b42 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs @@ -2,7 +2,6 @@ // 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. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs index 302252cf68e..eedc7a4b7ff 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs @@ -2,7 +2,6 @@ // 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. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs b/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs index df58c4a3f3c..5283d126c34 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the exponential of a multi-qubit Pauli operator. @@ -23,7 +22,6 @@ namespace Microsoft.Quantum.Intrinsic { /// target register is to be rotated. /// ## qubits /// Register to apply the given rotation to. - @EnableTestingViaName("Test.TargetDefinitions.Exp") operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/H.qs b/src/Simulation/TargetDefinitions/Intrinsic/H.qs index 740796ddd0b..041926d8920 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/H.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/H.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Hadamard transformation to a single qubit. @@ -20,7 +19,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.H") operation H (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs index c20f4c56731..100481f9fcf 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the two qubit Ising $XX$ rotation gate. @@ -25,7 +24,6 @@ namespace Microsoft.Quantum.Intrinsic { /// The first qubit input to the gate. /// ## qubit1 /// The second qubit input to the gate. - @EnableTestingViaName("Test.TargetDefinitions.IsingXX") internal operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs index 39fe3a24ff5..ad2afb19265 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the two qubit Ising $YY$ rotation gate. @@ -25,7 +24,6 @@ namespace Microsoft.Quantum.Intrinsic { /// The first qubit input to the gate. /// ## qubit1 /// The second qubit input to the gate. - @EnableTestingViaName("Test.TargetDefinitions.IsingYY") internal operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs index c800c2b92f2..0453ad04a2a 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the two qubit Ising $ZZ$ rotation gate. @@ -25,7 +24,6 @@ namespace Microsoft.Quantum.Intrinsic { /// The first qubit input to the gate. /// ## qubit1 /// The second qubit input to the gate. - @EnableTestingViaName("Test.TargetDefinitions.IsingZZ") internal operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/M.qs b/src/Simulation/TargetDefinitions/Intrinsic/M.qs index 7c44f88a5d1..c02cbd2ef67 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/M.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/M.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Performs a measurement of a single qubit in the @@ -29,7 +28,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Measure([PauliZ], [qubit]); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.M") operation M (qubit : Qubit) : Result { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs b/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs index ada792ca5f4..c43d54d59fc 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs @@ -2,7 +2,6 @@ // 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 @@ -39,7 +38,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # 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 { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/R.qs b/src/Simulation/TargetDefinitions/Intrinsic/R.qs index 8deee174ebb..7ea77eaba43 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/R.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/R.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies a rotation about the given Pauli axis. @@ -26,7 +25,6 @@ namespace Microsoft.Quantum.Intrinsic { /// When called with `pauli = PauliI`, this operation applies /// a *global phase*. This phase can be significant /// when used with the `Controlled` functor. - @EnableTestingViaName("Test.TargetDefinitions.R") operation R (pauli : Pauli, theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs b/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs index a8b16345b5e..86a78b96f00 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs @@ -2,7 +2,6 @@ // 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 @@ -11,7 +10,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// The qubit whose state is to be reset to $\ket{0}$. - @EnableTestingViaName("Test.TargetDefinitions.Reset") operation Reset (qubit : Qubit) : Unit { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Rx.qs b/src/Simulation/TargetDefinitions/Intrinsic/Rx.qs index 20aa42633b7..62aa42f07b4 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Rx.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Rx.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliX, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Rx") operation Rx (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Ry.qs b/src/Simulation/TargetDefinitions/Intrinsic/Ry.qs index e8df5d1fe88..3308cd281db 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Ry.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Ry.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliY, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Ry") operation Ry (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Rz.qs b/src/Simulation/TargetDefinitions/Intrinsic/Rz.qs index ca7c2d4d74c..1d645c3aa44 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Rz.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Rz.qs @@ -2,7 +2,6 @@ // 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. @@ -28,7 +27,6 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliZ, theta, qubit); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.Rz") operation Rz (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/S.qs b/src/Simulation/TargetDefinitions/Intrinsic/S.qs index 816c8771b31..f934bf73ef5 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/S.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/S.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the π/4 phase gate to a single qubit. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.S") operation S (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs b/src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs index 9b9c80138ed..fc5ecff69f3 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the SWAP gate to a pair of qubits. @@ -33,7 +32,6 @@ namespace Microsoft.Quantum.Intrinsic { /// CNOT(qubit2, qubit1); /// CNOT(qubit1, qubit2); /// ``` - @EnableTestingViaName("Test.TargetDefinitions.SWAP") operation SWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/T.qs b/src/Simulation/TargetDefinitions/Intrinsic/T.qs index dc3affe449a..0f3dac1d95e 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/T.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/T.qs @@ -19,7 +19,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.T") operation T (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/X.qs b/src/Simulation/TargetDefinitions/Intrinsic/X.qs index 8b5f8feb62b..5a046afb5eb 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/X.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/X.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Pauli $X$ gate. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.X") operation X (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Y.qs b/src/Simulation/TargetDefinitions/Intrinsic/Y.qs index 92b28478843..722391a6f45 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Y.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Y.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Pauli $Y$ gate. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.Y") operation Y (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Z.qs b/src/Simulation/TargetDefinitions/Intrinsic/Z.qs index a05f34c60c8..2d2bd99df61 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Z.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Z.qs @@ -2,7 +2,6 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { - open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the Pauli $Z$ gate. @@ -19,7 +18,6 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. - @EnableTestingViaName("Test.TargetDefinitions.Z") operation Z (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type3.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type3.Package.props index ef68d7d949b..8babd91d65c 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type3.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type3.Package.props @@ -30,9 +30,6 @@ - - - diff --git a/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj index 0519a40b106..4e5201c870b 100644 --- a/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj +++ b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj index 5a3f78e20a5..380029157bd 100644 --- a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj +++ b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Type3Core/Microsoft.Quantum.Type3.Core.csproj b/src/Simulation/Type3Core/Microsoft.Quantum.Type3.Core.csproj index 7d9715f3020..241477d177b 100644 --- a/src/Simulation/Type3Core/Microsoft.Quantum.Type3.Core.csproj +++ b/src/Simulation/Type3Core/Microsoft.Quantum.Type3.Core.csproj @@ -1,4 +1,4 @@ - + @@ -8,4 +8,3 @@ - diff --git a/src/Xunit/Microsoft.Quantum.Xunit.nuspec b/src/Xunit/Microsoft.Quantum.Xunit.nuspec index 44fcb9344a9..52887b4328b 100644 --- a/src/Xunit/Microsoft.Quantum.Xunit.nuspec +++ b/src/Xunit/Microsoft.Quantum.Xunit.nuspec @@ -22,7 +22,7 @@ - +