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

Commit 94fc56b

Browse files
authored
Merge pull request #918 from microsoft/kuzminrobin/sparseSim
Sparse Simulator
2 parents a0b5d73 + 7366e7d commit 94fc56b

File tree

89 files changed

+2897
-1102
lines changed

Some content is hidden

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

89 files changed

+2897
-1102
lines changed

bootstrap.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ if (-not (Test-Path Env:/AGENT_OS)) { # If no
2828
Pop-Location
2929

3030
Write-Host "Build release flavor of the Sparse Simulator"
31-
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators/SparseSimulator")
32-
.\build.ps1
33-
Pop-Location
31+
Invoke-Expression (Join-Path $PSScriptRoot "src" "Simulation" "NativeSparseSimulator" "build.ps1")
3432

3533
Push-Location (Join-Path $PSScriptRoot "src/Simulation/qdk_sim_rs")
3634
# Don't run the experimental simulator build if we're local

build/build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if ($Env:ENABLE_NATIVE -ne "false") {
2323
$script:all_ok = $False
2424
}
2525

26-
( & (Join-Path $PSScriptRoot .. src Simulation Simulators SparseSimulator build.ps1) ) || ( $script:all_ok = $False )
26+
( & (Join-Path $PSScriptRoot .. src Simulation NativeSparseSimulator build.ps1) ) || ( $script:all_ok = $False )
2727
} else {
2828
Write-Host "Skipping build of native simulator because ENABLE_NATIVE variable is set to: $Env:ENABLE_NATIVE."
2929
}

build/test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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 )
8+
( & (Join-Path $PSScriptRoot .. src Simulation NativeSparseSimulator test.ps1 ) ) || ( $script:all_ok = $False )
99

1010
$nativeSimulator = (Join-Path $PSScriptRoot "../src/Simulation/Native")
1111
& "$nativeSimulator/test-native-simulator.ps1"

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.185393-alpha"
3+
"Microsoft.Quantum.Sdk": "0.22.186614-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:

src/Qir/Tools/Microsoft.Quantum.Qir.Runtime.Tools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
<ItemGroup>
3838
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
39-
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.22.185393-alpha" />
39+
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.22.186614-beta" />
4040
</ItemGroup>
4141

4242
<ItemGroup>

src/Simulation/AutoSubstitution/Microsoft.Quantum.AutoSubstitution.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.22.185393-alpha" />
22+
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.22.186614-beta" />
2323
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.6.0" />
2424
</ItemGroup>
2525

src/Simulation/Common/Simulators.Dev.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<NativeRootPath>$([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/Native))</NativeRootPath>
88
<NativeBuildPath>$([MSBuild]::NormalizePath($(NativeRootPath)/build/drop))</NativeBuildPath>
99
<ExperimentalSimBuildPath>$([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/qdk_sim_rs/drop))</ExperimentalSimBuildPath>
10+
<NativeSparseSimBuildPath>$([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/NativeSparseSimulator/build))</NativeSparseSimBuildPath>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
@@ -26,6 +27,11 @@
2627
<NativeDll Include="$([MSBuild]::NormalizePath($(ExperimentalSimBuildPath)/libqdk_sim.dylib))" Dest="osx/Microsoft.Quantum.Experimental.Simulators.Runtime.dll" />
2728
<NativeDll Include="$([MSBuild]::NormalizePath($(ExperimentalSimBuildPath)/libqdk_sim.so))" Dest="linux/Microsoft.Quantum.Experimental.Simulators.Runtime.dll" />
2829
<NativeDll Include="$([MSBuild]::NormalizePath($(ExperimentalSimBuildPath)/qdk_sim.dll))" Dest="win10/Microsoft.Quantum.Experimental.Simulators.Runtime.dll" />
30+
31+
<!-- Native Sparse Simulator: -->
32+
<NativeDll Include="$([MSBuild]::NormalizePath($(NativeSparseSimBuildPath)/libSparseQuantumSimulator.dylib))" Dest="osx/libSparseQuantumSimulator.dylib" />
33+
<NativeDll Include="$([MSBuild]::NormalizePath($(NativeSparseSimBuildPath)/libSparseQuantumSimulator.so))" Dest="linux/libSparseQuantumSimulator.so" />
34+
<NativeDll Include="$([MSBuild]::NormalizePath($(NativeSparseSimBuildPath)/SparseQuantumSimulator.dll))" Dest="win10/SparseQuantumSimulator.dll" />
2935
</ItemGroup>
3036

3137
<Copy

0 commit comments

Comments
 (0)