Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 10 additions & 11 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ RUN apt-get -y update && \
apt-get -y install --no-install-recommends mono-complete nuget && \
apt-get clean && rm -rf /var/lib/apt/lists/

# Install CMake, Ninja, LLVM/Clang tools
RUN apt-get -y 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 && \
apt-get clean && rm -rf /var/lib/apt/lists/
RUN apt update \
&& apt-get install -y cmake \
ninja-build \
clang-11 \
clang-tidy-11 \
build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/

# Install C/C++ build tools and libraries
RUN apt-get -y update && \
apt-get install -y build-essential && \
apt-get clean && rm -rf /var/lib/apt/lists/
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
CMD [ "pwsh" ]
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,9 @@ ASALocalRun/
/src/Simulation/Simulators.Tests/TestProjects/QSharpExe/built
/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/built
dbw_test

# Jupyter caches
.ipynb_checkpoints

# Ignore drops from building native simulators.
xplat
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file configures the pre-commit tool to run an initial
# suite of lightweight tests on each commit, reducing the
# probability of failing in CI.
# For more information on pre-commit, see https://pre-commit.com/.
repos:
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
args: ['--manifest-path', 'src/Simulation/qdk_sim_rs/Cargo.toml', '--']
- id: cargo-check
args: ['--manifest-path', 'src/Simulation/qdk_sim_rs/Cargo.toml', '--']
# This step runs cargo-clippy, a linting tool provided with the
# Rust toolchain. Please see https://github.com/rust-lang/rust-clippy
# and https://rust-lang.github.io/rust-clippy/master/index.html
# for more information.
- id: clippy
args: ['--manifest-path', 'src/Simulation/qdk_sim_rs/Cargo.toml', '--']

22 changes: 22 additions & 0 deletions bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,35 @@ Push-Location (Join-Path $PSScriptRoot "build")
.\prerequisites.ps1
Pop-Location

Push-Location (Join-Path $PSScriptRoot "./src/Simulation/qdk_sim_rs")
# We use dotnet-script to inject the version number into Cargo.toml,
# so we go on ahead here and restore any missing tools.
# Since that Cargo.toml is referenced by CMake lists in the QIR
# runtime, this injection has to be the first thing we do.
dotnet tool restore
dotnet script inject-version.csx -- `
--template Cargo.toml.template `
--out-path Cargo.toml `
--version $Env:NUGET_VERSION;
Pop-Location

if (-not (Test-Path Env:AGENT_OS)) {
if ($Env:ENABLE_NATIVE -ne "false") {
Write-Host "Build release flavor of the native simulator"
$Env:BUILD_CONFIGURATION = "Release"
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Native")
.\build-native-simulator.ps1
Pop-Location
Push-Location (Join-Path $PSScriptRoot "src/Simulation/qdk_sim_rs")
# Don't run the experimental simulator build if we're local
# and prerequisites are missing.
$IsCI = "$Env:TF_BUILD" -ne "" -or "$Env:CI" -eq "true";
if ((Get-Command cargo -ErrorAction SilentlyContinue) -or $IsCI) {
.\build-qdk-sim-rs.ps1
} else {
Write-Verbose "cargo was not installed, skipping qdk_sim_rs build.";
}
Pop-Location
$Env:BUILD_CONFIGURATION = $null
}
if ($Env:ENABLE_QIRRUNTIME -ne "false") {
Expand Down
27 changes: 27 additions & 0 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ if ($Env:ENABLE_QIRRUNTIME -ne "false") {
Write-Host "Skipping build of qir runtime because ENABLE_QIRRUNTIME variable is set to: $Env:ENABLE_QIRRUNTIME"
}

if ($Env:ENABLE_EXPERIMENTALSIM -ne "false") {
if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {
# Cargo was missing, so cannot build experimental simulators.
# That's fine if running locally, we'll warn the user and then skip.
# On CI, though, we should fail when the experimental simulator build
# is turned on by ENABLE_EXPERIMENTALSIM, but we can't actually
# proceed.
if ("$Env:TF_BUILD" -ne "" -or "$Env:CI" -eq "true") {
Write-Host "##[error]Experimental simulators enabled, but cargo was not installed in CI pipeline.";
} else {
Write-Warning `
"Experimental simulators enabled, but cargo missing. " + `
"Either install cargo, or set `$Env:ENABLE_EXPERIMENTALSIM " + `
"to `"false`". Skipping experimental simulators.";
}
} else {
# Prerequisites are met, so let's go.
$expSim = (Join-Path $PSScriptRoot "../src/Simulation/qdk_sim_rs")
& "$expSim/build-qdk-sim-rs.ps1"
if ($LastExitCode -ne 0) {
$script:all_ok = $False
}
}
} else {
Write-Host "Skipping build of experimental simulators because ENABLE_OPENSIM variable is set to: $Env:ENABLE_OPENSIM."
}

function Build-One {
param(
[string]$action,
Expand Down
85 changes: 76 additions & 9 deletions build/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,36 @@ $ErrorActionPreference = 'Stop'
& "$PSScriptRoot/set-env.ps1"
$all_ok = $True

$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot "..");

Write-Host "##[info]Copy Native simulator xplat binaries"
pushd ../src/Simulation/Native
If (-not (Test-Path 'osx')) { mkdir 'osx' }
If (-not (Test-Path 'linux')) { mkdir 'linux' }
$DROP = "$Env:DROP_NATIVE/src/Simulation/Native/build/drop"
If (Test-Path "$DROP/libMicrosoft.Quantum.Simulator.Runtime.dylib") { copy "$DROP/libMicrosoft.Quantum.Simulator.Runtime.dylib" "osx/Microsoft.Quantum.Simulator.Runtime.dll" }
If (Test-Path "$DROP/libMicrosoft.Quantum.Simulator.Runtime.so") { copy "$DROP/libMicrosoft.Quantum.Simulator.Runtime.so" "linux/Microsoft.Quantum.Simulator.Runtime.dll" }
popd
Push-Location (Join-Path $PSScriptRoot ../src/Simulation/Native)
If (-not (Test-Path 'osx')) { mkdir 'osx' }
If (-not (Test-Path 'linux')) { mkdir 'linux' }
If (-not (Test-Path 'win10')) { mkdir 'win10' }

$DROP = "$Env:DROP_NATIVE/src/Simulation/Native/build/drop"
Write-Host "##[info]Copying Microsoft.Quantum.Simulator.Runtime files from $DROP...";
If (Test-Path "$DROP/libMicrosoft.Quantum.Simulator.Runtime.dylib") {
Copy-Item -Verbose "$DROP/libMicrosoft.Quantum.Simulator.Runtime.dylib" "osx/Microsoft.Quantum.Simulator.Runtime.dll"
}
If (Test-Path "$DROP/libMicrosoft.Quantum.Simulator.Runtime.so") {
Copy-Item -Verbose "$DROP/libMicrosoft.Quantum.Simulator.Runtime.so" "linux/Microsoft.Quantum.Simulator.Runtime.dll"
}


$DROP = "$Env:DROP_NATIVE/src/Simulation/qdk_sim_rs/drop";
Write-Host "##[info]Copying qdk_sim_rs files from $DROP...";
if (Test-Path "$DROP/libqdk_sim.dylib") {
Copy-Item -Verbose "$DROP/libqdk_sim.dylib" "osx/Microsoft.Quantum.Experimental.Simulators.Runtime.dll"
}
if (Test-Path "$DROP/libqdk_sim.so") {
Copy-Item -Verbose "$DROP/libqdk_sim.so" "linux/Microsoft.Quantum.Experimental.Simulators.Runtime.dll"
}
if (Test-Path "$DROP/qdk_sim.dll") {
Copy-Item -Verbose "$DROP/qdk_sim.dll" "win10/Microsoft.Quantum.Experimental.Simulators.Runtime.dll"
}
Pop-Location


function Pack-One() {
Expand All @@ -31,7 +53,7 @@ function Pack-One() {
$version = $Env:NUGET_VERSION
}

nuget pack $project `
nuget pack (Join-Path $PSScriptRoot $project) `
-OutputDirectory $Env:NUGET_OUTDIR `
-Properties Configuration=$Env:BUILD_CONFIGURATION `
-Version $version `
Expand Down Expand Up @@ -68,7 +90,7 @@ function Pack-Dotnet() {
$version = $Env:NUGET_VERSION
}

dotnet pack $project `
dotnet pack (Join-Path $PSScriptRoot $project) `
-o $Env:NUGET_OUTDIR `
-c $Env:BUILD_CONFIGURATION `
-v detailed `
Expand All @@ -87,6 +109,49 @@ function Pack-Dotnet() {
}


function Pack-Crate() {
param(
[string]
$PackageDirectory,

[string]
$OutPath
);

"##[info]Packing crate at $PackageDirectory to $OutPath..." | Write-Host

# Resolve relative to where the build script is located,
# not the PackageDirectory.
if (-not [IO.Path]::IsPathRooted($OutPath)) {
$OutPath = Resolve-Path (Join-Path $PSScriptRoot $OutPath);
}
Push-Location (Join-Path $PSScriptRoot $PackageDirectory)
cargo package;
Copy-Item -Force -Recurse (Join-Path . "target" "package") $OutPath;
Pop-Location
}

function Pack-Wheel() {
param(
[string]
$PackageDirectory,

[string]
$OutPath
);

"##[info]Packing wheel at $PackageDirectory to $OutPath..." | Write-Host

# Resolve relative to where the build script is located,
# not the PackageDirectory.
if (-not [IO.Path]::IsPathRooted($OutPath)) {
$OutPath = Resolve-Path (Join-Path $PSScriptRoot $OutPath);
}
Push-Location (Join-Path $PSScriptRoot $PackageDirectory)
pip wheel --wheel-dir $OutPath .;
Pop-Location
}

Write-Host "##[info]Using nuget to create packages"
Pack-Dotnet '../src/Azure/Azure.Quantum.Client/Microsoft.Azure.Quantum.Client.csproj'
Pack-One '../src/Simulation/CSharpGeneration/Microsoft.Quantum.CSharpGeneration.fsproj' '-IncludeReferencedProjects'
Expand All @@ -102,6 +167,8 @@ Pack-Dotnet '../src/Simulation/Type3Core/Microsoft.Quantum.Type3.Core.csproj'
Pack-One '../src/Simulation/Simulators/Microsoft.Quantum.Simulators.nuspec'
Pack-One '../src/Quantum.Development.Kit/Microsoft.Quantum.Development.Kit.nuspec'
Pack-One '../src/Xunit/Microsoft.Quantum.Xunit.csproj'
Pack-Crate -PackageDirectory "../src/Simulation/qdk_sim_rs" -OutPath $Env:CRATE_OUTDIR;
Pack-Wheel -PackageDirectory "../src/Simulation/qdk_sim_rs" -OutPath $Env:WHEEL_OUTDIR;
Pack-One '../src/Qir/Runtime/Microsoft.Quantum.Qir.Runtime.nuspec' -ForcePrerelease

if (-not $all_ok) {
Expand Down
20 changes: 19 additions & 1 deletion build/set-env.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ If ($Env:BUILD_BUILDNUMBER -eq $null) { $Env:BUILD_BUILDNUMBER ="0.0.1.0" }
If ($Env:BUILD_CONFIGURATION -eq $null) { $Env:BUILD_CONFIGURATION ="Debug" }
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:PYTHON_VERSION -eq $null) { $Env:PYTHON_VERSION = "${Env:ASSEMBLY_VERSION}a1" }
If ($Env:NUGET_VERSION -eq $null) { $Env:NUGET_VERSION ="0.0.1-alpha" }

If (($Env:ENABLE_NATIVE -ne "false") -and ($Env:NATIVE_SIMULATOR -eq $null) ) {
$Env:NATIVE_SIMULATOR = (Join-Path $PSScriptRoot "..\src\Simulation\Native\build\drop")
Expand All @@ -20,10 +21,27 @@ if ($Env:ENABLE_QIRRUNTIME -ne "false" -and $Env:QIR_DROPS -eq $null) {
}

If ($Env:DROPS_DIR -eq $null) { $Env:DROPS_DIR = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\drops")) }
if ($Env:DROP_NATIVE -eq $null) {
$Env:DROP_NATIVE = (Join-Path $PSScriptRoot "..")
}

If ($Env:NUGET_OUTDIR -eq $null) { $Env:NUGET_OUTDIR = (Join-Path $Env:DROPS_DIR "nugets") }
If (-not (Test-Path -Path $Env:NUGET_OUTDIR)) { [IO.Directory]::CreateDirectory($Env:NUGET_OUTDIR) }

If ($Env:CRATE_OUTDIR -eq $null) { $Env:CRATE_OUTDIR = (Join-Path $Env:DROPS_DIR "crates") }
If (-not (Test-Path -Path $Env:CRATE_OUTDIR)) { [IO.Directory]::CreateDirectory($Env:CRATE_OUTDIR) }

If ($Env:WHEEL_OUTDIR -eq $null) { $Env:WHEEL_OUTDIR = (Join-Path $Env:DROPS_DIR "wheels") }
If (-not (Test-Path -Path $Env:WHEEL_OUTDIR)) { [IO.Directory]::CreateDirectory($Env:WHEEL_OUTDIR) }

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) }

Get-ChildItem @(
"Env:\DROPS_DIR",
"Env:\DROP_NATIVE",
"Env:\NUGET_OUTDIR",
"Env:\CRATE_OUTDIR",
"Env:\WHEEL_OUTDIR",
"Env:\DOCS_OUTDIR"
) | Format-Table
17 changes: 17 additions & 0 deletions build/steps-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ steps:
packageType: sdk
version: '3.1.300'

- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
displayName: Install rust
condition: ne( variables['Agent.OS'], 'Windows_NT' )
- script: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
rustup-init.exe -y
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
displayName: Windows install rust
condition: eq( variables['Agent.OS'], 'Windows_NT' )

- script: |
rustup install nightly
rustup component add rustfmt clippy
rustup component add rustfmt clippy --toolchain nightly
displayName: Enable Rust formatting and nightly options.

##
# Custom pre-reqs
Expand Down
27 changes: 27 additions & 0 deletions build/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ if ($Env:ENABLE_QIRRUNTIME -ne "false") {
Write-Host "Skipping test of qir runtime because ENABLE_QIRRUNTIME variable is set to: $Env:ENABLE_QIRRUNTIME."
}


if ($Env:ENABLE_EXPERIMENTALSIM -ne "false") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in the previous review, but this script should warn if cargo is missing and skip the test like the build script does. That way test.ps1 won't fail for folks who haven't built opensim due to missing cargo install.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, let me fix that quickly, then.

if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {
# Cargo was missing, so cannot test experimental simulators.
# That's fine if running locally, we'll warn the user and then skip.
# On CI, though, we should fail when the experimental simulator build
# is turned on by ENABLE_EXPERIMENTALSIM, but we can't actually
# proceed.
if ("$Env:TF_BUILD" -ne "" -or "$Env:CI" -eq "true") {
Write-Host "##[error]Experimental simulators enabled, but cargo was not installed in CI pipeline.";
} else {
Write-Warning `
"Experimental simulators enabled, but cargo missing. " + `
"Either install cargo, or set `$Env:ENABLE_EXPERIMENTALSIM " + `
"to `"false`". Skipping experimental simulators.";
}
} else {
$expSim = (Join-Path $PSScriptRoot "../src/Simulation/qdk_sim_rs")
& "$expSim/test-qdk-sim-rs.ps1"
if ($LastExitCode -ne 0) {
$script:all_ok = $False
}
}
} else {
Write-Host "Skipping test of experimental simulators because ENABLE_OPENSIM variable is set to: $Env:ENABLE_OPENSIM."
}

if (-not $all_ok) {
throw "At least one project failed during testing. Check the logs."
}
Loading