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

Replace C++ QIR Runtime with Rust QIR stdlib #1087

Merged
merged 58 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3fafd0f
Add parallel Rust QIR Runtime
swernli Aug 23, 2022
27465c7
Remove old dependencies
swernli Aug 23, 2022
8460887
Use --all-targets clippy, corresponding fixes
swernli Aug 25, 2022
297ff7e
Add conditionals instrinc support, result_to_string
swernli Aug 25, 2022
826287c
Add QIR simulator support
swernli Aug 26, 2022
14fe034
Share C++ tests across Rust impl
swernli Aug 26, 2022
94a1bd9
Add to build scripts
swernli Aug 26, 2022
eb94c17
Fix build ordering
swernli Aug 26, 2022
8e2a89b
Fix CI cleanup
swernli Aug 27, 2022
f1f2f66
More build fixes
swernli Aug 27, 2022
55e30fd
Fix build bug
swernli Aug 28, 2022
65c3e8c
Minor error message fix
swernli Aug 29, 2022
8d61ef1
Merge remote-tracking branch 'origin/main' into swernli/rust-qir-runtime
swernli Aug 29, 2022
af6cd94
Move result related api into sim
swernli Aug 29, 2022
61e43f0
refactor qir_runtime, split out qir_sim
swernli Aug 30, 2022
4a0cfad
Use BigUint for sparse sim indexing
swernli Aug 30, 2022
06de82b
Type updates, sparse nearly_zero fix
swernli Sep 1, 2022
62e3ff6
Consolidation and optimization of sparse sim
swernli Sep 2, 2022
4640bf2
Rust qubit/result to string fixes
swernli Sep 3, 2022
402bc44
Fullstate sim as QIR backend, staticlib runtime
swernli Sep 3, 2022
8f1cda8
rename runtime to stdlib
swernli Sep 3, 2022
cd16687
rename sim to backend
swernli Sep 3, 2022
de289c0
remove conditionals support
swernli Sep 3, 2022
781c096
Fix public module ref
swernli Sep 3, 2022
c329e58
Update cmdline tool to use simulator QIR backend
swernli Sep 6, 2022
ee1466e
Merge remote-tracking branch 'origin/main' into swernli/rust-qir-runtime
swernli Sep 6, 2022
9276d2d
Use whole-archive linking on non-Windows
swernli Sep 6, 2022
4fdb5d1
Use thread_local for simulator init
swernli Sep 6, 2022
6abef66
Use all_load on MacOS
swernli Sep 6, 2022
2bc0e7a
Skip QIR libs,include for runtime tool
swernli Sep 6, 2022
2ee9938
Use force_load on MacOs
swernli Sep 6, 2022
e4a86d7
Try alternate MacOS linking strategy
swernli Sep 6, 2022
9d11f51
Use full path in MacOs linking
swernli Sep 7, 2022
c5920ba
Try explicit lib name
swernli Sep 7, 2022
997e1d3
Clean up and comments
swernli Sep 7, 2022
78aced6
Remove QIR C++ runtime, rename folders
swernli Sep 7, 2022
7aaa60f
Use environment variables in native sim build
swernli Sep 7, 2022
8021315
Put back Tools tests
swernli Sep 7, 2022
11f0670
Remove tracer test from solution
swernli Sep 7, 2022
3f38b9e
Remove unused qir_backend
swernli Sep 7, 2022
184fb72
Include full state sim lib in nuget package
swernli Sep 8, 2022
e59fe1c
Update array unit tests
swernli Sep 13, 2022
0fcb85f
Update bigint unit tests
swernli Sep 13, 2022
221956b
Update range unit tests
swernli Sep 13, 2022
cb5b341
Update strings unit tests
swernli Sep 14, 2022
2ce6a2e
__quantum__rt__fail will print string before panic
swernli Sep 14, 2022
fd0226d
Fix broken readme links
swernli Sep 14, 2022
3395708
Fix formatting in arrays.rs
swernli Sep 14, 2022
4ed00e3
Clarifying comments, minor fixes from initial review
swernli Sep 14, 2022
80c0d81
Fix formatting
swernli Sep 14, 2022
a504342
Add `__quantum__rt__message_record_output`
swernli Sep 14, 2022
3ebd9ff
Merge branch 'main' into swernli/rust-qir-runtime
swernli Sep 14, 2022
a25e80e
Clean up file encoding for .cargo/config.toml
swernli Sep 15, 2022
c7168d3
Updating script patterns
swernli Sep 15, 2022
c494888
Updates from PR feedback
swernli Sep 15, 2022
637bfbc
Fix double free typo in tests
swernli Sep 16, 2022
986471e
More updates from PR feedback
swernli Sep 16, 2022
8d0635e
Remove leftover debug line
swernli Sep 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
swernli marked this conversation as resolved.
Show resolved Hide resolved
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"
swernli marked this conversation as resolved.
Show resolved Hide resolved
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
swernli marked this conversation as resolved.
Show resolved Hide resolved
rustup component add rustfmt clippy llvm-tools-preview --toolchain nightly
kuzminrobin marked this conversation as resolved.
Show resolved Hide resolved
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.
137 changes: 0 additions & 137 deletions src/Qir/Common/Include/SimulatorStub.hpp

This file was deleted.

Loading