Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Replace C++ QIR Runtime with Rust QIR stdlib (#1087)
Browse files Browse the repository at this point in the history
* Add parallel Rust QIR Runtime

* Remove old dependencies

* Use --all-targets clippy, corresponding fixes

* Add conditionals instrinc support, result_to_string

* Add QIR simulator support

* Share C++ tests across Rust impl

* Add to build scripts

* Fix build ordering

* Fix CI cleanup

* More build fixes

* Fix build bug

* Minor error message fix

* Move result related api into sim

* refactor qir_runtime, split out qir_sim

* Use BigUint for sparse sim indexing

* Type updates, sparse nearly_zero fix

* Consolidation and optimization of sparse sim

* Rust qubit/result to string fixes

* Fullstate sim as QIR backend, staticlib runtime

* rename runtime to stdlib

* rename sim to backend

* remove conditionals support

* Fix public module ref

* Update cmdline tool to use simulator QIR backend

* Use whole-archive linking on non-Windows

* Use thread_local for simulator init

* Use all_load on MacOS

* Skip QIR libs,include for runtime tool

* Use force_load on MacOs

* Try alternate MacOS linking strategy

* Use full path in MacOs linking

* Try explicit lib name

* Clean up and comments

* Remove QIR C++ runtime, rename folders

* Use environment variables in native sim build

* Put back Tools tests

* Remove tracer test from solution

* Remove unused qir_backend

* Include full state sim lib in nuget package

* Update array unit tests

* Update bigint unit tests

* Update range unit tests

* Update strings unit tests

* __quantum__rt__fail will print string before panic

* Fix broken readme links

* Fix formatting in arrays.rs

* Clarifying comments, minor fixes from initial review

* Fix formatting

* Add `__quantum__rt__message_record_output`

* Clean up file encoding for .cargo/config.toml

* Updating script patterns

* Updates from PR feedback

* Fix double free typo in tests

* More updates from PR feedback

* Remove leftover debug line
  • Loading branch information
swernli authored Sep 16, 2022
1 parent 1ae7e69 commit 5a4fb4f
Show file tree
Hide file tree
Showing 180 changed files with 3,172 additions and 12,659 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ out/
# Ignore drops from building native simulators.
xplat
src/Simulation/Native/win10/Microsoft.Quantum.Simulator.Runtime.dll
src/Simulation/Native/win10/Microsoft.Quantum.Simulator.Runtime.lib
src/Simulation/Native/linux/libMicrosoft.Quantum.Simulator.Runtime.so
src/Simulation/Native/osx/libMicrosoft.Quantum.Simulator.Runtime.dylib
src/Simulation/Native/win10/Microsoft.Quantum.SparseSimulator.Runtime.dll
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

members = [
"src/Simulation/qdk_sim_rs",
"src/Qir/Runtime/stdlib",
]

[profile.release]
debug = true
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
opt-level = 3
panic = 'unwind'
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ You may also visit our [Quantum](https://github.com/microsoft/quantum) repositor

Note that when building from source, this repository is configured so that .NET will automatically look at the [Quantum Development Kit prerelease feed](https://dev.azure.com/ms-quantum-public/Microsoft%20Quantum%20(public)/_packaging?_a=feed&feed=alpha) in addition to any other feeds you may have configured.

Building **QIR Runtime** isn't enabled by default yet. Please see [its readme](./src/Qir/Runtime/README.md) for details.

### All platforms ###

1. Install the pre-reqs:
Expand Down
22 changes: 0 additions & 22 deletions Simulation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QIR-static", "QIR-static",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "qir-gen", "src\Qir\Tests\QIR-static\qsharp\qir-gen.csproj", "{33ED37AB-61B1-4A49-9952-58D19AA8EF30}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QIR-tracer", "QIR-tracer", "{522EAA31-6317-42D5-831F-C39313DF03A0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tracer-qir", "src\Qir\Tests\QIR-tracer\qsharp\tracer-qir.csproj", "{002174F4-BFA8-4675-908D-0E9C32ED951A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{AAFB81D3-BC87-404D-BA64-AF40B2D2E45A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "StandaloneInputReference", "StandaloneInputReference", "{A7DB7367-9FD6-4164-8263-A05077BE54AB}"
Expand Down Expand Up @@ -772,22 +768,6 @@ Global
{33ED37AB-61B1-4A49-9952-58D19AA8EF30}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{33ED37AB-61B1-4A49-9952-58D19AA8EF30}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{33ED37AB-61B1-4A49-9952-58D19AA8EF30}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Debug|x64.ActiveCfg = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Debug|x64.Build.0 = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Release|Any CPU.Build.0 = Release|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Release|x64.ActiveCfg = Release|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.Release|x64.Build.0 = Release|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{002174F4-BFA8-4675-908D-0E9C32ED951A}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{D7D34736-A719-4B45-A33F-2723F59EC29D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7D34736-A719-4B45-A33F-2723F59EC29D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7D34736-A719-4B45-A33F-2723F59EC29D}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1039,8 +1019,6 @@ Global
{5DBF6402-D9CD-4470-A309-3755CFDA42CF} = {3DFACF7F-D5C2-455B-AB8A-26908DEF7E2D}
{54000816-122C-4AA0-9FE9-B0ABB9547232} = {7F7BB60A-5DCB-469E-8546-1BE9E3CAC833}
{33ED37AB-61B1-4A49-9952-58D19AA8EF30} = {54000816-122C-4AA0-9FE9-B0ABB9547232}
{522EAA31-6317-42D5-831F-C39313DF03A0} = {7F7BB60A-5DCB-469E-8546-1BE9E3CAC833}
{002174F4-BFA8-4675-908D-0E9C32ED951A} = {522EAA31-6317-42D5-831F-C39313DF03A0}
{AAFB81D3-BC87-404D-BA64-AF40B2D2E45A} = {F6C2D4C0-12DC-40E3-9C86-FA5308D9B567}
{A7DB7367-9FD6-4164-8263-A05077BE54AB} = {AAFB81D3-BC87-404D-BA64-AF40B2D2E45A}
{D7D34736-A719-4B45-A33F-2723F59EC29D} = {A7DB7367-9FD6-4164-8263-A05077BE54AB}
Expand Down
18 changes: 10 additions & 8 deletions bootstrap.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#Requires -PSEdition Core

$ErrorActionPreference = 'Stop'

Push-Location (Join-Path $PSScriptRoot "build")
Expand All @@ -13,6 +15,14 @@ Push-Location (Join-Path $PSScriptRoot "./src/Simulation/qdk_sim_rs")
Pop-Location

if (-not (Test-Path Env:/AGENT_OS)) { # If not CI build, i.e. local build (if AGENT_OS envvar is not defined)
if ($Env:ENABLE_QIRRUNTIME -ne "false") {
Write-Host "Build release flavor of the QIR standard library"
$Env:BUILD_CONFIGURATION = "Release"
Push-Location (Join-Path $PSScriptRoot "src/Qir/Runtime")
.\build-qir-stdlib.ps1
Pop-Location
$Env:BUILD_CONFIGURATION = $null
}
if ($Env:ENABLE_NATIVE -ne "false") {
$Env:BUILD_CONFIGURATION = "Release"
Write-Host "Build release flavor of the full state simulator"
Expand All @@ -35,14 +45,6 @@ if (-not (Test-Path Env:/AGENT_OS)) { # If no
Pop-Location
$Env:BUILD_CONFIGURATION = $null
}
if ($Env:ENABLE_QIRRUNTIME -ne "false") {
Write-Host "Build release flavor of the QIR Runtime"
$Env:BUILD_CONFIGURATION = "Release"
Push-Location (Join-Path $PSScriptRoot "src/Qir/Runtime")
.\build-qir-runtime.ps1
Pop-Location
$Env:BUILD_CONFIGURATION = $null
}

Write-Host "Build simulation solution"
dotnet build Simulation.sln
Expand Down
6 changes: 4 additions & 2 deletions build/build.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#Requires -PSEdition Core

$ErrorActionPreference = 'Stop'

& "$PSScriptRoot/set-env.ps1"
$all_ok = $True

if ($Env:ENABLE_QIRRUNTIME -ne "false") {
$qirRuntime = (Join-Path $PSScriptRoot "../src/Qir/Runtime")
& "$qirRuntime/build-qir-runtime.ps1"
$qirStdLibPath = (Join-Path $PSScriptRoot .. src Qir Runtime build-qir-stdlib.ps1)
& $qirStdLibPath
if ($LastExitCode -ne 0) {
$script:all_ok = $False
}
Expand Down
6 changes: 1 addition & 5 deletions build/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ $artifacts = @{

Native = @(
".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulator.Runtime.dll",
".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.SparseSimulator.Runtime.dll",
".\src\Qir\Runtime\bin\$Env:BUILD_CONFIGURATION\bin\Microsoft.Quantum.Qir.QSharp.Core.dll",
".\src\Qir\Runtime\bin\$Env:BUILD_CONFIGURATION\bin\Microsoft.Quantum.Qir.QSharp.Foundation.dll",
".\src\Qir\Runtime\bin\$Env:BUILD_CONFIGURATION\bin\Microsoft.Quantum.Qir.Runtime.dll",
".\src\Qir\Runtime\bin\$Env:BUILD_CONFIGURATION\bin\Microsoft.Quantum.Qir.Tracer.dll"
".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.SparseSimulator.Runtime.dll"
) | ForEach-Object { Join-Path $PSScriptRoot (Join-Path ".." $_) };
}

Expand Down
3 changes: 3 additions & 0 deletions build/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Push-Location (Join-Path $PSScriptRoot ../src/Simulation/Native)
If (Test-Path "$DROP/Microsoft.Quantum.Simulator.Runtime.dll") {
Copy-Item -Verbose "$DROP/Microsoft.Quantum.Simulator.Runtime.dll" "win10/Microsoft.Quantum.Simulator.Runtime.dll"
}
If (Test-Path "$DROP/Microsoft.Quantum.Simulator.Runtime.lib") {
Copy-Item -Verbose "$DROP/Microsoft.Quantum.Simulator.Runtime.lib" "win10/Microsoft.Quantum.Simulator.Runtime.lib"
}

$DROP = "$Env:DROP_NATIVE/src/Simulation/NativeSparseSimulator/build"
Write-Host "##[info]Copying NativeSparseSimulator files from $DROP...";
Expand Down
10 changes: 10 additions & 0 deletions build/set-env.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#Requires -PSEdition Core

$ErrorActionPreference = 'Stop'

Write-Host "Setting up build environment variables"
Expand Down Expand Up @@ -39,10 +41,18 @@ If (-not (Test-Path -Path $Env:WHEEL_OUTDIR)) { [IO.Directory]::CreateDirectory(
If ($Env:DOCS_OUTDIR -eq $null) { $Env:DOCS_OUTDIR = (Join-Path $Env:DROPS_DIR "docs") }
If (-not (Test-Path -Path $Env:DOCS_OUTDIR)) { [IO.Directory]::CreateDirectory($Env:DOCS_OUTDIR) }

$env:BUILD_PLATFORM = "win-x64"
if ($IsLinux) {
$env:BUILD_PLATFORM = "linux-x64"
} elseif ($IsMacOS) {
$env:BUILD_PLATFORM = "osx-x64"
}

Get-ChildItem -Path Env:/* -Include @(
"BUILD_BUILDNUMBER",
"BUILD_CONFIGURATION",
"BUILD_VERBOSITY",
"BUILD_PLATFORM",
"ASSEMBLY_VERSION",
"PYTHON_VERSION",
"NUGET_VERSION",
Expand Down
14 changes: 7 additions & 7 deletions build/steps-codecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ steps:
packageType: sdk
version: '6.0.x'

# QIR Runtime:
# QIR stdlib:
- pwsh: src/Qir/Runtime/prerequisites.ps1
displayName: "Install QIR Runtime Prerequisites"
displayName: "Install QIR stdlib Prerequisites"
workingDirectory: $(System.DefaultWorkingDirectory)

- pwsh: src/Qir/Runtime/build-qir-runtime.ps1
displayName: "Build QIR Runtime"
- pwsh: src/Qir/Runtime/build-qir-stdlib.ps1
displayName: "Build QIR stdlib"
workingDirectory: $(System.DefaultWorkingDirectory)

# Native Simulator (needed to build and run the QIR tests):
Expand All @@ -33,9 +33,9 @@ steps:
displayName: "Build Native Simulator"
workingDirectory: $(System.DefaultWorkingDirectory)/src/Simulation/Native

# QIR Runtime Tests:
- pwsh: src/Qir/Runtime/test-qir-runtime.ps1
displayName: "Test QIR Runtime"
# QIR stdlib Tests:
- pwsh: src/Qir/Runtime/test-qir-stdlib.ps1
displayName: "Test QIR stdlib"
workingDirectory: $(System.DefaultWorkingDirectory)

# QIR Tests:
Expand Down
7 changes: 5 additions & 2 deletions build/steps-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ steps:
displayName: Windows install rust
condition: eq( variables['Agent.OS'], 'Windows_NT' )

# Installs Rust nightly toolchain and components.
# Note: the llvm-tools-preview component can be removed once QIR range support is simplified.
# See https://github.com/microsoft/qsharp-language/issues/108
- script: |
rustup install nightly
rustup component add rustfmt clippy
rustup component add rustfmt clippy --toolchain nightly
rustup component add rustfmt clippy llvm-tools-preview
rustup component add rustfmt clippy llvm-tools-preview --toolchain nightly
displayName: Enable Rust formatting and nightly options.

##
Expand Down
6 changes: 4 additions & 2 deletions build/test.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#Requires -PSEdition Core

& "$PSScriptRoot/set-env.ps1"
$all_ok = $True

Expand Down Expand Up @@ -43,8 +45,8 @@ function Test-One {
Test-One '../Simulation.sln'

if ($Env:ENABLE_QIRRUNTIME -ne "false") {
$qirRuntime = (Join-Path $PSScriptRoot "../src/Qir/Runtime")
& "$qirRuntime/test-qir-runtime.ps1"
$qirStdLibPath = (Join-Path $PSScriptRoot .. src Qir Runtime test-qir-stdlib.ps1)
& $qirStdLibPath
if ($LastExitCode -ne 0) {
$script:all_ok = $False
}
Expand Down
File renamed without changes.
8 changes: 1 addition & 7 deletions src/Qir/CommandLineTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ private static Command CreateBuildCommand()
settings.QSharpDll,
settings.LibraryDirectories,
settings.IncludeDirectories,
settings.ExecutablesDirectory,
settings.Debug)),
settings.ExecutablesDirectory)),
TreatUnmatchedTokensAsErrors = true
};

Expand Down Expand Up @@ -153,11 +152,6 @@ public sealed class BuildOptions
/// The path to the output directory where the created executables will be placed.
/// </summary>
public DirectoryInfo ExecutablesDirectory { get; set; }

/// <summary>
/// Enable additional debugging checks at runtime.
/// </summary>
public bool Debug { get; set; }
}
}
}
Loading

0 comments on commit 5a4fb4f

Please sign in to comment.