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
7 changes: 6 additions & 1 deletion bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ 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_NATIVE -ne "false") {
Write-Host "Build release flavor of the native simulator"
$Env:BUILD_CONFIGURATION = "Release"
Write-Host "Build release flavor of the Sparse Simulator"
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators/SparseSimulator")
.\build.ps1
Pop-Location

Write-Host "Build release flavor of the full state simulator"
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Native")
.\build-native-simulator.ps1
Pop-Location
Expand Down
2 changes: 2 additions & 0 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ if ($Env:ENABLE_QIRRUNTIME -ne "false") {
}

if ($Env:ENABLE_NATIVE -ne "false") {
( & (Join-Path $PSScriptRoot .. src Simulation Simulators SparseSimulator build.ps1) ) || ( $script:all_ok = $False )

$nativeSimulator = (Join-Path $PSScriptRoot "../src/Simulation/Native")
& "$nativeSimulator/build-native-simulator.ps1"
if ($LastExitCode -ne 0) {
Expand Down
2 changes: 2 additions & 0 deletions build/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
$all_ok = $True

if ($Env:ENABLE_NATIVE -ne "false") {
( & (Join-Path $PSScriptRoot .. src Simulation Simulators SparseSimulator test.ps1) ) || ( $script:all_ok = $False )

$nativeSimulator = (Join-Path $PSScriptRoot "../src/Simulation/Native")
& "$nativeSimulator/test-native-simulator.ps1"
if ($LastExitCode -ne 0) {
Expand Down
7 changes: 4 additions & 3 deletions src/Qir/Runtime/prerequisites.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
if ($Env:ENABLE_QIRRUNTIME -ne "false") {
if (($IsWindows) -or ((Test-Path Env:/AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) {
if (!(Get-Command clang -ErrorAction SilentlyContinue) -or `
!(Get-Command clang-format -ErrorAction SilentlyContinue)) {
choco install llvm --version=11.1.0
Write-Host "##vso[task.setvariable variable=PATH;]$Env:Path;C:\Program Files\LLVM\bin"
!(Get-Command clang-format -ErrorAction SilentlyContinue) -or `
(Test-Path Env:/AGENT_OS)) {
choco install llvm --version=11.1.0 --allow-downgrade
Write-Host "##vso[task.setvariable variable=PATH;]$($env:SystemDrive)\Program Files\LLVM\bin;$Env:PATH"
}
if (!(Get-Command ninja -ErrorAction SilentlyContinue)) {
choco install ninja
Expand Down
5 changes: 3 additions & 2 deletions src/Qir/qir-utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ function Build-CMakeProject {
$env:CXX = "clang++.exe"
$env:RC = "clang++.exe"

if (!(Get-Command clang -ErrorAction SilentlyContinue) -and (choco find --idonly -l llvm) -contains "llvm") {
if ((!(Get-Command clang -ErrorAction SilentlyContinue) -and (choco find --idonly -l llvm) -contains "llvm") -or `
(Test-Path Env:/AGENT_OS)) {
# LLVM was installed by Chocolatey, so add the install location to the path.
$env:PATH += ";$($env:SystemDrive)\Program Files\LLVM\bin"
$env:PATH = "$($env:SystemDrive)\Program Files\LLVM\bin;$env:Path"
}

if (Get-Command clang-tidy -ErrorAction SilentlyContinue) {
Expand Down
17 changes: 1 addition & 16 deletions src/Simulation/Simulators/SparseSimulator/Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,14 @@ set(CMAKE_MACOSX_RPATH 1)
# Main build files
add_library(SparseQuantumSimulator SHARED factory.cpp capi.cpp)

# Set OpenMP if it is available
find_package(OpenMP REQUIRED)
if(OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
if (OpenMP_CXX_VERSION_MAJOR GREATER_EQUAL 3)
target_compile_definitions(SparseQuantumSimulator PRIVATE DOMP_GE_V3=1)
endif()
endif()

# Windows adds a special dllexport command which must be defined
if (WIN32)
target_compile_options(SparseQuantumSimulator PUBLIC -fdeclspec)
target_compile_definitions(SparseQuantumSimulator PRIVATE BUILD_DLL=1)
endif()
# Try to optimize with gcc
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(SparseQuantumSimulator PUBLIC -O3 -ftree-vectorize -mavx2 -mfma -fopenmp)
endif()

# Sets NDEBUG to true for all non-debug settings
if (NOT (CMAKE_BUILD_TYPE:STRING STREQUAL "Debug"))
target_compile_definitions(SparseQuantumSimulator PRIVATE NDEBUG=1)
target_compile_options(SparseQuantumSimulator PUBLIC -O3 -ftree-vectorize -mavx2 -mfma)
endif()

message("Compiler flags: ${CMAKE_CXX_FLAGS_RELEASE}")
7 changes: 6 additions & 1 deletion src/Simulation/Simulators/SparseSimulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ This is a an alternative quantum simulator, compatible with Q\# and Microsoft's
- Dotnet cake v1.1.0

# Setup
To build the Sparse Simulator, call `dotnet restore` from the main `SparseSimulator` folder, then `dotnet cake`. This builds the C++ backend and the C\# interface.
Bild:
```
cd SparseSimulator
pwsh ./build.ps1
```
This builds the C++ backend and the C\# interface.

To use the SparseSimulator in a Q\# project, ensure that it includes
```xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<!--From qsharp-runtime /src/Simulation/common/Simulators.Dev.props-->
<PropertyGroup Condition="'$(QsimDll)' == ''">
<QsimDllMac>..\Native\build\libSparseQuantumSimulator.dylib</QsimDllMac>
<QsimDllLinux>..\Native\build\libSparseQuantumSimulator.so</QsimDllLinux>
<QsimDllMac>..\Native\build\$(Configuration)\libSparseQuantumSimulator.dylib</QsimDllMac>
<QsimDllLinux>..\Native\build\$(Configuration)\libSparseQuantumSimulator.so</QsimDllLinux>
<QsimDllWindows>..\Native\build\$(Configuration)\SparseQuantumSimulator.dll</QsimDllWindows>
<QSimDll Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(QsimDllMac)</QSimDll>
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(QsimDllLinux)</QSimDll>
Expand Down
72 changes: 0 additions & 72 deletions src/Simulation/Simulators/SparseSimulator/build.cake

This file was deleted.

70 changes: 70 additions & 0 deletions src/Simulation/Simulators/SparseSimulator/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#Requires -Version 7.1

& (Join-Path $PSScriptRoot .. .. .. .. build set-env.ps1)
$FailureCommands = 'Write-Host "##vso[task.logissue type=error;] Failed to build SparseSimulator. See errors below or above." ; Pop-Location ; Exit 1'

# BULD NATIVE PART

# mkdir Native\build\(Debug|Release)
$BuildDir = (Join-Path $PSScriptRoot "Native" "build" $Env:BUILD_CONFIGURATION)
if (-not (Test-Path $BuildDir)) {
New-Item -Path $BuildDir -ItemType "directory" | Out-Null
}

# pushd Native\build\(Debug|Release)
Push-Location $BuildDir

$CmakeConfigCommand = "cmake -G Ninja -D CMAKE_VERBOSE_MAKEFILE:BOOL=ON -D CMAKE_BUILD_TYPE=$Env:BUILD_CONFIGURATION -S ..\.. " # Without `-G Ninja` the compiler chosen is always `cl.exe`.

if (($IsMacOS) -or ((Test-Path Env:/AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin"))))
{
Write-Host "On MacOS build using the default C/C++ compiler (should be AppleClang)"
}
else {
if (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin"))))
{
Write-Host "On Linux build using Clang"
$CC = "clang-11"
$CXX = "clang++-11"
#$clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy-11"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to preserve the clangTidy fragments for now.

}
elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win"))))
{
Write-Host "On Windows build using Clang"
$CC = "clang.exe"
$CXX = "clang++.exe"

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 (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"
#}
Comment on lines +45 to +50
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to preserve the clangTidy fragments for now.

}

$CmakeConfigCommand += " -D CMAKE_C_COMPILER=$CC -D CMAKE_CXX_COMPILER=$CXX "
}

# Generate the build scripts:
( Invoke-Expression $CmakeConfigCommand ) || ( Invoke-Expression $FailureCommands )

# Invoke the build scripts:
( cmake --build . ) || ( Invoke-Expression $FailureCommands )

# popd
Pop-Location


# BUILD C# PART AND TESTS

Push-Location $PSScriptRoot
( dotnet build . --configuration $Env:BUILD_CONFIGURATION ) || ( Invoke-Expression $FailureCommands )
Pop-Location
11 changes: 11 additions & 0 deletions src/Simulation/Simulators/SparseSimulator/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

& (Join-Path $PSScriptRoot .. .. .. .. build set-env.ps1)

$FailureCommands = 'Write-Host "##vso[task.logissue type=error;] Failed to test SparseSimulator. See errors below or above." ; Pop-Location ; Exit 1'

Push-Location $PSScriptRoot
( dotnet test . --configuration $Env:BUILD_CONFIGURATION ) || `
( Invoke-Expression $FailureCommands )
Pop-Location