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

Commit e5be79b

Browse files
bettinaheimDmitryVasilevskysam-jaquesDmitry Vasilevskythomashaener
authored
Sparse simulator (core components) (#939)
Co-authored-by: DmitryVasilevsky <[email protected]> Co-authored-by: Sam Jaques <[email protected]> Co-authored-by: Dmitry Vasilevsky <[email protected]> Co-authored-by: Thomas Haener <[email protected]> Co-authored-by: Robin Kuzmin <[email protected]> Co-authored-by: Thomas Haener <[email protected]> Co-authored-by: Robin Kuzmin <[email protected]> Co-authored-by: Bettina Heim <[email protected]>
1 parent 2e9962e commit e5be79b

File tree

82 files changed

+7421
-886
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+7421
-886
lines changed

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ ClientBin/
232232
*.publishsettings
233233
orleans.codegen.cs
234234

235-
# Including strong name files can present a security risk
235+
# Including strong name files can present a security risk
236236
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
237237
#*.snk
238238

@@ -328,7 +328,7 @@ __pycache__/
328328
# OpenCover UI analysis results
329329
OpenCover/
330330

331-
# Azure Stream Analytics local run output
331+
# Azure Stream Analytics local run output
332332
ASALocalRun/
333333

334334
# MSBuild Binary and Structured Log
@@ -337,7 +337,7 @@ ASALocalRun/
337337
# NVidia Nsight GPU debugger configuration file
338338
*.nvuser
339339

340-
# MFractors (Xamarin productivity tool) working folder
340+
# MFractors (Xamarin productivity tool) working folder
341341
.mfractor/
342342

343343
/src/Simulation/Simulators.Tests/TestProjects/QSharpExe/built
@@ -357,6 +357,9 @@ xplat
357357
src/Simulation/Native/win10/Microsoft.Quantum.Simulator.Runtime.dll
358358
src/Simulation/Native/linux/libMicrosoft.Quantum.Simulator.Runtime.so
359359
src/Simulation/Native/osx/libMicrosoft.Quantum.Simulator.Runtime.dylib
360+
src/Simulation/Native/win10/SparseQuantumSimulator.dll
361+
src/Simulation/Native/linux/libSparseQuantumSimulator.so
362+
src/Simulation/Native/osx/libSparseQuantumSimulator.dylib
360363
src/Simulation/Native/win10/Microsoft.Quantum.Experimental.Simulators.Runtime.dll
361364
src/Simulation/Native/linux/Microsoft.Quantum.Experimental.Simulators.Runtime.dll
362365
src/Simulation/Native/osx/Microsoft.Quantum.Experimental.Simulators.Runtime.dll

Simulation.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ Global
855855
{EB6E3DBD-C884-4241-9BC4-8281191D1F53} = {34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}
856856
{E1A463D7-2E23-4134-BE04-1EFF7A546813} = {93409CC3-8DF9-45FA-AE21-16A19FDEF650}
857857
{789C86D9-CE77-40DA-BDDD-979436952512} = {93409CC3-8DF9-45FA-AE21-16A19FDEF650}
858-
{7E24885B-D86D-477E-A840-06FA53C33FE1} = {34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}
858+
{7E24885B-D86D-477E-A840-06FA53C33FE1} = {93409CC3-8DF9-45FA-AE21-16A19FDEF650}
859859
{7F80466B-A6B5-4EF1-A9E9-22ABAE3C20C1} = {34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}
860860
{7F7BB60A-5DCB-469E-8546-1BE9E3CAC833} = {F6C2D4C0-12DC-40E3-9C86-FA5308D9B567}
861861
{EAC5EAE7-D1B3-4726-AFDB-73000E62176A} = {7F7BB60A-5DCB-469E-8546-1BE9E3CAC833}

bootstrap.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ 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 full state simulator"
2626
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Native")
2727
.\build-native-simulator.ps1
2828
Pop-Location
29+
30+
Write-Host "Build release flavor of the Sparse Simulator"
31+
Invoke-Expression (Join-Path $PSScriptRoot "src" "Simulation" "NativeSparseSimulator" "build.ps1")
32+
2933
Push-Location (Join-Path $PSScriptRoot "src/Simulation/qdk_sim_rs")
3034
# Don't run the experimental simulator build if we're local
3135
# and prerequisites are missing.

build/build.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ if ($Env:ENABLE_NATIVE -ne "false") {
2222
if ($LastExitCode -ne 0) {
2323
$script:all_ok = $False
2424
}
25+
26+
( & (Join-Path $PSScriptRoot .. src Simulation NativeSparseSimulator build.ps1) ) || ( $script:all_ok = $False )
2527
} else {
2628
Write-Host "Skipping build of native simulator because ENABLE_NATIVE variable is set to: $Env:ENABLE_NATIVE."
2729
}

build/pack.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ Push-Location (Join-Path $PSScriptRoot ../src/Simulation/Native)
2626
Copy-Item -Verbose "$DROP/Microsoft.Quantum.Simulator.Runtime.dll" "win10/Microsoft.Quantum.Simulator.Runtime.dll"
2727
}
2828

29+
$DROP = "$Env:DROP_NATIVE/src/Simulation/NativeSparseSimulator/build"
30+
Write-Host "##[info]Copying NativeSparseSimulator files from $DROP...";
31+
If (Test-Path "$DROP/libSparseQuantumSimulator.dylib") {
32+
Copy-Item -Verbose "$DROP/libSparseQuantumSimulator.dylib" "osx/libSparseQuantumSimulator.dylib"
33+
}
34+
If (Test-Path "$DROP/libSparseQuantumSimulator.so") {
35+
Copy-Item -Verbose "$DROP/libSparseQuantumSimulator.so" "linux/libSparseQuantumSimulator.so"
36+
}
37+
If (Test-Path "$DROP/SparseQuantumSimulator.dll") {
38+
Copy-Item -Verbose "$DROP/SparseQuantumSimulator.dll" "win10/SparseQuantumSimulator.dll"
39+
}
2940

3041
$DROP = "$Env:DROP_NATIVE/src/Simulation/qdk_sim_rs/drop";
3142
Write-Host "##[info]Copying qdk_sim_rs files from $DROP...";
@@ -43,7 +54,7 @@ Pop-Location
4354

4455
function Pack-One() {
4556
Param(
46-
$project,
57+
$project,
4758
$option1 = "",
4859
$option2 = "",
4960
$option3 = "",
@@ -74,7 +85,7 @@ function Pack-One() {
7485

7586
function Pack-Dotnet() {
7687
Param(
77-
$project,
88+
$project,
7889
$option1 = "",
7990
$option2 = "",
8091
$option3 = "",

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 NativeSparseSimulator 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) {

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"msbuild-sdks": {
3-
"Microsoft.Quantum.Sdk": "0.22.192799-alpha"
3+
"Microsoft.Quantum.Sdk": "0.22.192949-beta"
44
}
55
}

src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ namespace Quantum
159159
{
160160
std::cout << "*********************" << std::endl;
161161
this->GetState(
162-
[](size_t idx, double re, double im)
162+
[](const char* idx, double re, double im)
163163
{
164164
if (!Close(re, 0.0) || !Close(im, 0.0))
165165
{
166-
std::cout << "|" << std::bitset<8>(idx) << ">: " << re << "+" << im << "i" << std::endl;
166+
std::cout << "|" << idx << ">: " << re << "+" << im << "i" << std::endl;
167167
}
168168
return true;
169169
});

src/Qir/Runtime/public/QSharpSimApi_I.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ namespace Quantum
6464

6565
// The callback should be invoked on each basis vector (in the standard computational basis) in little-endian
6666
// order until it returns `false` or the state is fully dumped.
67-
typedef bool (*TGetStateCallback)(size_t /*basis vector*/, double /* amplitude Re*/, double /* amplitude Im*/);
67+
typedef bool (*TGetStateCallback)(const char* /*basis vector*/, double /* amplitude Re*/,
68+
double /* amplitude Im*/);
6869

6970
// Deprecated, use `DumpMachine()` and `DumpRegister()` instead.
7071
virtual void GetState(TGetStateCallback callback) = 0;

src/Qir/Tests/FullstateSimulator/FullstateSimulatorTests.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <complex>
55
#include <memory>
6+
#include <string>
67
#include <vector>
78

89
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
@@ -347,9 +348,14 @@ TEST_CASE("Fullstate simulator: get qubit state of Bell state", "[fullstate_simu
347348
// 1/sqrt(2)(|00> + |11>)x|0>
348349

349350
dynamic_cast<IDiagnostics*>(sim.get())->GetState(
350-
[](size_t idx, double re, double im)
351+
[](const char* idxStr, double re, double im)
351352
{
352353
norm += re * re + im * im;
354+
size_t idx = 0;
355+
for (size_t i = 0; idxStr[i] != '\0'; ++i)
356+
{
357+
idx |= (idxStr[i] == '1' ? 1u : 0u) << i;
358+
}
353359
REQUIRE(idx < 4);
354360
switch (idx)
355361
{
@@ -372,9 +378,14 @@ TEST_CASE("Fullstate simulator: get qubit state of Bell state", "[fullstate_simu
372378
// 1/sqrt(2)(|00> + |11>)xi|1>
373379

374380
dynamic_cast<IDiagnostics*>(sim.get())->GetState(
375-
[](size_t idx, double re, double im)
381+
[](const char* idxStr, double re, double im)
376382
{
377383
norm += re * re + im * im;
384+
size_t idx = 0;
385+
for (size_t i = 0; idxStr[i] != '\0'; ++i)
386+
{
387+
idx |= (idxStr[i] == '1' ? 1u : 0u) << i;
388+
}
378389
switch (idx)
379390
{
380391
case 4:

0 commit comments

Comments
 (0)