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

Commit 5c02b2d

Browse files
kuzminrobinswernli
andauthored
Added building SparseSimulator without Cake (#840)
* Added building SparseSimulator without Cake. * Updated the README.md, removed build.cake * Added SparseSimulator to CI build and test Co-authored-by: Stefan J. Wernli <[email protected]>
1 parent a42ada2 commit 5c02b2d

File tree

11 files changed

+107
-97
lines changed

11 files changed

+107
-97
lines changed

bootstrap.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ Pop-Location
2121

2222
if (-not (Test-Path Env:/AGENT_OS)) { # If not CI build, i.e. local build (if AGENT_OS envvar is not defined)
2323
if ($Env:ENABLE_NATIVE -ne "false") {
24-
Write-Host "Build release flavor of the native simulator"
2524
$Env:BUILD_CONFIGURATION = "Release"
25+
Write-Host "Build release flavor of the Sparse Simulator"
26+
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators/SparseSimulator")
27+
.\build.ps1
28+
Pop-Location
29+
30+
Write-Host "Build release flavor of the full state simulator"
2631
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Native")
2732
.\build-native-simulator.ps1
2833
Pop-Location

build/build.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if ($Env:ENABLE_QIRRUNTIME -ne "false") {
1717
}
1818

1919
if ($Env:ENABLE_NATIVE -ne "false") {
20+
( & (Join-Path $PSScriptRoot .. src Simulation Simulators SparseSimulator build.ps1) ) || ( $script:all_ok = $False )
21+
2022
$nativeSimulator = (Join-Path $PSScriptRoot "../src/Simulation/Native")
2123
& "$nativeSimulator/build-native-simulator.ps1"
2224
if ($LastExitCode -ne 0) {

build/test.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
$all_ok = $True
66

77
if ($Env:ENABLE_NATIVE -ne "false") {
8+
( & (Join-Path $PSScriptRoot .. src Simulation Simulators SparseSimulator test.ps1) ) || ( $script:all_ok = $False )
9+
810
$nativeSimulator = (Join-Path $PSScriptRoot "../src/Simulation/Native")
911
& "$nativeSimulator/test-native-simulator.ps1"
1012
if ($LastExitCode -ne 0) {

src/Qir/Runtime/prerequisites.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
if ($Env:ENABLE_QIRRUNTIME -ne "false") {
77
if (($IsWindows) -or ((Test-Path Env:/AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) {
88
if (!(Get-Command clang -ErrorAction SilentlyContinue) -or `
9-
!(Get-Command clang-format -ErrorAction SilentlyContinue)) {
10-
choco install llvm --version=11.1.0
11-
Write-Host "##vso[task.setvariable variable=PATH;]$Env:Path;C:\Program Files\LLVM\bin"
9+
!(Get-Command clang-format -ErrorAction SilentlyContinue) -or `
10+
(Test-Path Env:/AGENT_OS)) {
11+
choco install llvm --version=11.1.0 --allow-downgrade
12+
Write-Host "##vso[task.setvariable variable=PATH;]$($env:SystemDrive)\Program Files\LLVM\bin;$Env:PATH"
1213
}
1314
if (!(Get-Command ninja -ErrorAction SilentlyContinue)) {
1415
choco install ninja

src/Qir/qir-utils.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ function Build-CMakeProject {
192192
$env:CXX = "clang++.exe"
193193
$env:RC = "clang++.exe"
194194

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

200201
if (Get-Command clang-tidy -ErrorAction SilentlyContinue) {

src/Simulation/Simulators/SparseSimulator/Native/CMakeLists.txt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,14 @@ set(CMAKE_MACOSX_RPATH 1)
99
# Main build files
1010
add_library(SparseQuantumSimulator SHARED factory.cpp capi.cpp)
1111

12-
# Set OpenMP if it is available
13-
find_package(OpenMP REQUIRED)
14-
if(OpenMP_CXX_FOUND)
15-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
16-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
17-
if (OpenMP_CXX_VERSION_MAJOR GREATER_EQUAL 3)
18-
target_compile_definitions(SparseQuantumSimulator PRIVATE DOMP_GE_V3=1)
19-
endif()
20-
endif()
21-
2212
# Windows adds a special dllexport command which must be defined
2313
if (WIN32)
2414
target_compile_options(SparseQuantumSimulator PUBLIC -fdeclspec)
2515
target_compile_definitions(SparseQuantumSimulator PRIVATE BUILD_DLL=1)
2616
endif()
2717
# Try to optimize with gcc
2818
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
29-
target_compile_options(SparseQuantumSimulator PUBLIC -O3 -ftree-vectorize -mavx2 -mfma -fopenmp)
30-
endif()
31-
32-
# Sets NDEBUG to true for all non-debug settings
33-
if (NOT (CMAKE_BUILD_TYPE:STRING STREQUAL "Debug"))
34-
target_compile_definitions(SparseQuantumSimulator PRIVATE NDEBUG=1)
19+
target_compile_options(SparseQuantumSimulator PUBLIC -O3 -ftree-vectorize -mavx2 -mfma)
3520
endif()
3621

3722
message("Compiler flags: ${CMAKE_CXX_FLAGS_RELEASE}")

src/Simulation/Simulators/SparseSimulator/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ This is a an alternative quantum simulator, compatible with Q\# and Microsoft's
1717
- Dotnet cake v1.1.0
1818

1919
# Setup
20-
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.
20+
Bild:
21+
```
22+
cd SparseSimulator
23+
pwsh ./build.ps1
24+
```
25+
This builds the C++ backend and the C\# interface.
2126

2227
To use the SparseSimulator in a Q\# project, ensure that it includes
2328
```xml

src/Simulation/Simulators/SparseSimulator/SparseSimulatorCS/SparseSimulator.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<!--From qsharp-runtime /src/Simulation/common/Simulators.Dev.props-->
1010
<PropertyGroup Condition="'$(QsimDll)' == ''">
11-
<QsimDllMac>..\Native\build\libSparseQuantumSimulator.dylib</QsimDllMac>
12-
<QsimDllLinux>..\Native\build\libSparseQuantumSimulator.so</QsimDllLinux>
11+
<QsimDllMac>..\Native\build\$(Configuration)\libSparseQuantumSimulator.dylib</QsimDllMac>
12+
<QsimDllLinux>..\Native\build\$(Configuration)\libSparseQuantumSimulator.so</QsimDllLinux>
1313
<QsimDllWindows>..\Native\build\$(Configuration)\SparseQuantumSimulator.dll</QsimDllWindows>
1414
<QSimDll Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(QsimDllMac)</QSimDll>
1515
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(QsimDllLinux)</QSimDll>

src/Simulation/Simulators/SparseSimulator/build.cake

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
#Requires -Version 7.1
5+
6+
& (Join-Path $PSScriptRoot .. .. .. .. build set-env.ps1)
7+
$FailureCommands = 'Write-Host "##vso[task.logissue type=error;] Failed to build SparseSimulator. See errors below or above." ; Pop-Location ; Exit 1'
8+
9+
# BULD NATIVE PART
10+
11+
# mkdir Native\build\(Debug|Release)
12+
$BuildDir = (Join-Path $PSScriptRoot "Native" "build" $Env:BUILD_CONFIGURATION)
13+
if (-not (Test-Path $BuildDir)) {
14+
New-Item -Path $BuildDir -ItemType "directory" | Out-Null
15+
}
16+
17+
# pushd Native\build\(Debug|Release)
18+
Push-Location $BuildDir
19+
20+
$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`.
21+
22+
if (($IsMacOS) -or ((Test-Path Env:/AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin"))))
23+
{
24+
Write-Host "On MacOS build using the default C/C++ compiler (should be AppleClang)"
25+
}
26+
else {
27+
if (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin"))))
28+
{
29+
Write-Host "On Linux build using Clang"
30+
$CC = "clang-11"
31+
$CXX = "clang++-11"
32+
#$clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy-11"
33+
}
34+
elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win"))))
35+
{
36+
Write-Host "On Windows build using Clang"
37+
$CC = "clang.exe"
38+
$CXX = "clang++.exe"
39+
40+
if (!(Get-Command clang -ErrorAction SilentlyContinue) -and (choco find --idonly -l llvm) -contains "llvm") {
41+
# LLVM was installed by Chocolatey, so add the install location to the path.
42+
$env:PATH += ";$($env:SystemDrive)\Program Files\LLVM\bin"
43+
}
44+
45+
#if (Get-Command clang-tidy -ErrorAction SilentlyContinue) {
46+
# # Only run clang-tidy if it's installed. This is because the package used by chocolatey on
47+
# # the build pipeline doesn't include clang-tidy, so we allow skipping that there and let
48+
# # the Linux build catch tidy issues.
49+
# $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy"
50+
#}
51+
}
52+
53+
$CmakeConfigCommand += " -D CMAKE_C_COMPILER=$CC -D CMAKE_CXX_COMPILER=$CXX "
54+
}
55+
56+
# Generate the build scripts:
57+
( Invoke-Expression $CmakeConfigCommand ) || ( Invoke-Expression $FailureCommands )
58+
59+
# Invoke the build scripts:
60+
( cmake --build . ) || ( Invoke-Expression $FailureCommands )
61+
62+
# popd
63+
Pop-Location
64+
65+
66+
# BUILD C# PART AND TESTS
67+
68+
Push-Location $PSScriptRoot
69+
( dotnet build . --configuration $Env:BUILD_CONFIGURATION ) || ( Invoke-Expression $FailureCommands )
70+
Pop-Location

0 commit comments

Comments
 (0)