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
Show all changes
111 commits
Select commit Hold shift + click to select a range
ca33196
Sparse simulator by Samuel Jaques (#835)
DmitryVasilevsky Sep 28, 2021
37faffb
Feedback: removed empty constructor, added .md formatting
Sep 29, 2021
605014c
Feedback: removed single precision, adjusted formatting
Sep 29, 2021
673e095
Removed amplitude probes
Sep 29, 2021
a42ada2
Removed sampling without state modification
Sep 29, 2021
5c02b2d
Added building SparseSimulator without Cake (#840)
kuzminrobin Oct 4, 2021
7d487b5
Use Catch2 for testing.
thomashaener Oct 6, 2021
6cf6e5b
Address build errors.
thomashaener Oct 6, 2021
ef46fcb
.
thomashaener Oct 6, 2021
4e7f38d
Merge pull request #849 from thomashaener/feature/sparse-simulator
thomashaener Oct 6, 2021
04e0e3a
Merge branch 'main' into feature/sparse-simulator
Oct 11, 2021
22a61a0
Dmitryv/removing probes qs (#850)
DmitryVasilevsky Oct 12, 2021
d0c0285
Reduced use of unsigned: logical_qubit_id, size_t, std::mt19937::resu…
Oct 12, 2021
a66172d
Changed qubit type in sparse simulator to intptr_t (#852)
DmitryVasilevsky Oct 13, 2021
76dddfd
Broken up QuantumSimulator into CommonNativeSimulator and QuantumSimu…
kuzminrobin Oct 19, 2021
e8c2ed0
Reverting the Allocate() change. (#857)
kuzminrobin Oct 19, 2021
43d4f99
Merging `main` to `feature/sparse-simulator` (#905)
kuzminrobin Jan 21, 2022
ebac702
Merging `main` to `feature/sparse-simulator`. (#913)
kuzminrobin Jan 25, 2022
c5a5c94
Merge branch 'main' into feature/sparse-simulator
kuzminrobin Feb 4, 2022
a0b5d73
Merge pull request #925 from microsoft/kuzminrobin/sparse-simulatorMe…
kuzminrobin Feb 4, 2022
a0047a5
Added QubitIds implementation.
kuzminrobin Jan 20, 2022
77275a4
Added SparseSimulator2.
kuzminrobin Jan 21, 2022
d4fcc7c
Moved SparseSimulator/Native to a separate directory NativeSparseSimu…
kuzminrobin Jan 21, 2022
27cd686
Added NativeSparseSimulator/build.ps1.
kuzminrobin Jan 21, 2022
bc3f156
Added testing.
kuzminrobin Jan 25, 2022
720fe1e
Removed BUILD_CONFIGURATION from the build path.
kuzminrobin Jan 25, 2022
ff1adbb
Added copying of the SparseSim DLLs.
kuzminrobin Jan 25, 2022
79b441c
Added to the testst the invocation of the SparseSim.
kuzminrobin Jan 25, 2022
381d844
Added SparseSim tests to .cs.
kuzminrobin Jan 25, 2022
a81349a
Added SparseSim to the entryPointDriver.
kuzminrobin Jan 25, 2022
2f49289
Added "RelWithDebInfo" and test invocation.
kuzminrobin Jan 25, 2022
deacd67
Added the build invocation from bootstrap.ps1.
kuzminrobin Jan 25, 2022
0753bad
Build fix.
kuzminrobin Jan 25, 2022
c90b0fd
Commented out the SparseSim from the EntryPointDriver.
kuzminrobin Jan 25, 2022
2e27886
Fixed ReleaseOne().
kuzminrobin Jan 25, 2022
0045bf7
Commented out SparseSimulator2 for QSimVerifyT().
kuzminrobin Jan 26, 2022
e24f83d
Minor clean-up, clarification.
kuzminrobin Jan 26, 2022
73ed4c1
clang-format and remove .dll.
thomashaener Jan 26, 2022
f47e642
clang-format-11.
thomashaener Jan 26, 2022
f98570e
Fix assertion testing.
thomashaener Jan 26, 2022
65fd5a1
Don't throw on releasing nonzero qubit; return false instead.
thomashaener Jan 26, 2022
ebd3397
Prohibit caching of assertions for proper forwarding to C#.
thomashaener Jan 26, 2022
e03dec7
Polish assertion code.
thomashaener Jan 26, 2022
f0ff9d8
Fix Pauli-measurement issue.
thomashaener Jan 27, 2022
7cbf288
Add MCS, T, and ajoints to NativeWrappers.
thomashaener Jan 27, 2022
cf4d356
Resolved some of the CR feedback.
kuzminrobin Jan 27, 2022
9461c5e
Added forgotten file.
kuzminrobin Jan 27, 2022
ed6dbd7
Fix issues with int/bool/long.
thomashaener Jan 28, 2022
32a0686
Bool/Int for M().
thomashaener Jan 28, 2022
7c1946d
Remove cout.
thomashaener Jan 28, 2022
83deeac
Fix CZ commutation rule.
thomashaener Jan 28, 2022
db965f6
MCR1: remove basis arg.
thomashaener Jan 31, 2022
0d16530
Select different SDK version.
thomashaener Jan 31, 2022
174107d
Code readability.
thomashaener Jan 31, 2022
e3f6982
Clean up precision settings.
thomashaener Jan 31, 2022
e80c563
Fix typo.
thomashaener Jan 31, 2022
bd9c01b
Sign convention for MCR.
thomashaener Jan 31, 2022
3ae6fa7
Same.
thomashaener Jan 31, 2022
c4aafdb
Forward sim_dump to capi.
thomashaener Jan 31, 2022
77316a3
Fixed the NativeSparseSimulator/test.ps1
kuzminrobin Jan 27, 2022
6296415
Refactored the multi-simulaotr tests.
kuzminrobin Jan 28, 2022
b8a19d6
Adapt dump functionality to current implementation of full state simu…
thomashaener Feb 1, 2022
5ed39a8
Allow qubit release in |1>.
thomashaener Feb 1, 2022
374b78b
First steps toward char*-representation for basis state labels.
thomashaener Feb 2, 2022
51b6a51
Convert basis state label to bitstring in full state.
thomashaener Feb 2, 2022
a7a328b
Adapt QIR simulator.
thomashaener Feb 2, 2022
4c72972
Same.
thomashaener Feb 2, 2022
520b1d9
Clang-format.
thomashaener Feb 2, 2022
cab3384
Adapt QIR tests.
thomashaener Feb 2, 2022
f50b07a
Update C# dump: Convert binary string to decimal string.
thomashaener Feb 2, 2022
a3bdd76
Code style for c++.
thomashaener Feb 2, 2022
bfbb60c
Qir tests: char* is a string of bits (not decimal).
thomashaener Feb 2, 2022
931f29b
.
thomashaener Feb 2, 2022
ef47c9f
Remove TODO and replace comparator in DisplayableState.
thomashaener Feb 2, 2022
842c87e
Commented out the SparseSimulator2 for BasicExecution() test.
kuzminrobin Feb 2, 2022
d39a457
Minor code clean-up.
kuzminrobin Feb 3, 2022
cb8e5c1
Minor clean-up.
kuzminrobin Feb 3, 2022
278c677
Forward to non-controlled gates if controls.size()==0.
thomashaener Feb 3, 2022
50a16a1
Fix register dump logic.
thomashaener Feb 3, 2022
9cb17ae
Remove outdated comment.
thomashaener Feb 3, 2022
d7213b2
.
thomashaener Feb 3, 2022
3b5c425
Consistent behavior w.r.t. precision and check if wavefunction split …
thomashaener Feb 3, 2022
984f4e7
Post-rebase fix.
kuzminrobin Feb 4, 2022
1a7dcd0
Clang-format-13 reformatting.
kuzminrobin Feb 4, 2022
73d2db9
Renamed teh older SparseSimulator to SparseSimulatorDeprecated.
kuzminrobin Feb 5, 2022
178528a
Renamed SparseSimulator2 to SparseSimulator.
kuzminrobin Feb 5, 2022
5659982
Switched from string index to BigInteger index.
kuzminrobin Feb 9, 2022
f773f38
Updated teh QDK/SDK version.
kuzminrobin Feb 9, 2022
82f6c77
Fixed endianness.
kuzminrobin Feb 9, 2022
9cee1a4
CR changes.
kuzminrobin Feb 9, 2022
6169aa6
String reverse fix.
kuzminrobin Feb 9, 2022
8c1dfde
Refactored BasisStateLabel.
kuzminrobin Feb 9, 2022
1d7bc32
Build fix.
kuzminrobin Feb 9, 2022
759ccc2
Added NativeSparseSimulator/.gitignore.
kuzminrobin Feb 9, 2022
3dadeb9
Renamed SparseSimulator2.cs to SparseSimulator.cs.
kuzminrobin Feb 9, 2022
a26bae7
Renamed SparseSimulator2/ to SparseSimulator/.
kuzminrobin Feb 9, 2022
da31423
Minor clean-up.
kuzminrobin Feb 10, 2022
0f33534
Moved the extensions to the approppriate class.
kuzminrobin Feb 10, 2022
84118d5
Renamed ParseUnsignedLEBitString to BasisStateLabelToBigInt.
kuzminrobin Feb 10, 2022
80027f7
Minor clean-up.
kuzminrobin Feb 10, 2022
6ccdf4d
Add extended dump functionality (similar to DumpToLocation).
thomashaener Feb 10, 2022
7366e7d
Fixed the Dump callback return type.
kuzminrobin Feb 11, 2022
94fc56b
Merge pull request #918 from microsoft/kuzminrobin/sparseSim
kuzminrobin Feb 11, 2022
bd06167
Enabling sparse simulator argument in driver (#928)
bettinaheim Feb 16, 2022
5172f83
Merge remote-tracking branch 'origin/main' into feature/sparse-simulator
kuzminrobin Feb 16, 2022
78145b7
Minor clean up (#940)
bettinaheim Feb 16, 2022
00979a4
Merge branch 'main' into feature/sparse-simulator
kuzminrobin Feb 16, 2022
9780a06
getting updates from main
Feb 16, 2022
477a136
Getting updates from main (#942)
bettinaheim Feb 16, 2022
391e1f4
updating package version numbers (#944)
bettinaheim Feb 17, 2022
639717f
Merge branch 'main' into feature/sparse-simulator
bettinaheim Feb 17, 2022
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
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ ClientBin/
*.publishsettings
orleans.codegen.cs

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

Expand Down Expand Up @@ -328,7 +328,7 @@ __pycache__/
# OpenCover UI analysis results
OpenCover/

# Azure Stream Analytics local run output
# Azure Stream Analytics local run output
ASALocalRun/

# MSBuild Binary and Structured Log
Expand All @@ -337,7 +337,7 @@ ASALocalRun/
# NVidia Nsight GPU debugger configuration file
*.nvuser

# MFractors (Xamarin productivity tool) working folder
# MFractors (Xamarin productivity tool) working folder
.mfractor/

/src/Simulation/Simulators.Tests/TestProjects/QSharpExe/built
Expand All @@ -357,6 +357,9 @@ xplat
src/Simulation/Native/win10/Microsoft.Quantum.Simulator.Runtime.dll
src/Simulation/Native/linux/libMicrosoft.Quantum.Simulator.Runtime.so
src/Simulation/Native/osx/libMicrosoft.Quantum.Simulator.Runtime.dylib
src/Simulation/Native/win10/SparseQuantumSimulator.dll
src/Simulation/Native/linux/libSparseQuantumSimulator.so
src/Simulation/Native/osx/libSparseQuantumSimulator.dylib
src/Simulation/Native/win10/Microsoft.Quantum.Experimental.Simulators.Runtime.dll
src/Simulation/Native/linux/Microsoft.Quantum.Experimental.Simulators.Runtime.dll
src/Simulation/Native/osx/Microsoft.Quantum.Experimental.Simulators.Runtime.dll
2 changes: 1 addition & 1 deletion Simulation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ Global
{EB6E3DBD-C884-4241-9BC4-8281191D1F53} = {34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}
{E1A463D7-2E23-4134-BE04-1EFF7A546813} = {93409CC3-8DF9-45FA-AE21-16A19FDEF650}
{789C86D9-CE77-40DA-BDDD-979436952512} = {93409CC3-8DF9-45FA-AE21-16A19FDEF650}
{7E24885B-D86D-477E-A840-06FA53C33FE1} = {34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}
{7E24885B-D86D-477E-A840-06FA53C33FE1} = {93409CC3-8DF9-45FA-AE21-16A19FDEF650}
{7F80466B-A6B5-4EF1-A9E9-22ABAE3C20C1} = {34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}
{7F7BB60A-5DCB-469E-8546-1BE9E3CAC833} = {F6C2D4C0-12DC-40E3-9C86-FA5308D9B567}
{EAC5EAE7-D1B3-4726-AFDB-73000E62176A} = {7F7BB60A-5DCB-469E-8546-1BE9E3CAC833}
Expand Down
6 changes: 5 additions & 1 deletion bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ 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 full state simulator"
Push-Location (Join-Path $PSScriptRoot "src/Simulation/Native")
.\build-native-simulator.ps1
Pop-Location

Write-Host "Build release flavor of the Sparse Simulator"
Invoke-Expression (Join-Path $PSScriptRoot "src" "Simulation" "NativeSparseSimulator" "build.ps1")

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.
Expand Down
2 changes: 2 additions & 0 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ if ($Env:ENABLE_NATIVE -ne "false") {
if ($LastExitCode -ne 0) {
$script:all_ok = $False
}

( & (Join-Path $PSScriptRoot .. src Simulation NativeSparseSimulator build.ps1) ) || ( $script:all_ok = $False )
} else {
Write-Host "Skipping build of native simulator because ENABLE_NATIVE variable is set to: $Env:ENABLE_NATIVE."
}
Expand Down
15 changes: 13 additions & 2 deletions build/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ Push-Location (Join-Path $PSScriptRoot ../src/Simulation/Native)
Copy-Item -Verbose "$DROP/Microsoft.Quantum.Simulator.Runtime.dll" "win10/Microsoft.Quantum.Simulator.Runtime.dll"
}

$DROP = "$Env:DROP_NATIVE/src/Simulation/NativeSparseSimulator/build"
Write-Host "##[info]Copying NativeSparseSimulator files from $DROP...";
If (Test-Path "$DROP/libSparseQuantumSimulator.dylib") {
Copy-Item -Verbose "$DROP/libSparseQuantumSimulator.dylib" "osx/libSparseQuantumSimulator.dylib"
}
If (Test-Path "$DROP/libSparseQuantumSimulator.so") {
Copy-Item -Verbose "$DROP/libSparseQuantumSimulator.so" "linux/libSparseQuantumSimulator.so"
}
If (Test-Path "$DROP/SparseQuantumSimulator.dll") {
Copy-Item -Verbose "$DROP/SparseQuantumSimulator.dll" "win10/SparseQuantumSimulator.dll"
}

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

function Pack-One() {
Param(
$project,
$project,
$option1 = "",
$option2 = "",
$option3 = "",
Expand Down Expand Up @@ -74,7 +85,7 @@ function Pack-One() {

function Pack-Dotnet() {
Param(
$project,
$project,
$option1 = "",
$option2 = "",
$option3 = "",
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 NativeSparseSimulator test.ps1 ) ) || ( $script:all_ok = $False )

$nativeSimulator = (Join-Path $PSScriptRoot "../src/Simulation/Native")
& "$nativeSimulator/test-native-simulator.ps1"
if ($LastExitCode -ne 0) {
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"msbuild-sdks": {
"Microsoft.Quantum.Sdk": "0.22.192799-alpha"
"Microsoft.Quantum.Sdk": "0.22.192949-beta"
}
}
4 changes: 2 additions & 2 deletions src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ namespace Quantum
{
std::cout << "*********************" << std::endl;
this->GetState(
[](size_t idx, double re, double im)
[](const char* idx, double re, double im)
{
if (!Close(re, 0.0) || !Close(im, 0.0))
{
std::cout << "|" << std::bitset<8>(idx) << ">: " << re << "+" << im << "i" << std::endl;
std::cout << "|" << idx << ">: " << re << "+" << im << "i" << std::endl;
}
return true;
});
Expand Down
3 changes: 2 additions & 1 deletion src/Qir/Runtime/public/QSharpSimApi_I.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace Quantum

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

// Deprecated, use `DumpMachine()` and `DumpRegister()` instead.
virtual void GetState(TGetStateCallback callback) = 0;
Expand Down
15 changes: 13 additions & 2 deletions src/Qir/Tests/FullstateSimulator/FullstateSimulatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <complex>
#include <memory>
#include <string>
#include <vector>

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

dynamic_cast<IDiagnostics*>(sim.get())->GetState(
[](size_t idx, double re, double im)
[](const char* idxStr, double re, double im)
{
norm += re * re + im * im;
size_t idx = 0;
for (size_t i = 0; idxStr[i] != '\0'; ++i)
{
idx |= (idxStr[i] == '1' ? 1u : 0u) << i;
}
REQUIRE(idx < 4);
switch (idx)
{
Expand All @@ -372,9 +378,14 @@ TEST_CASE("Fullstate simulator: get qubit state of Bell state", "[fullstate_simu
// 1/sqrt(2)(|00> + |11>)xi|1>

dynamic_cast<IDiagnostics*>(sim.get())->GetState(
[](size_t idx, double re, double im)
[](const char* idxStr, double re, double im)
{
norm += re * re + im * im;
size_t idx = 0;
for (size_t i = 0; idxStr[i] != '\0'; ++i)
{
idx |= (idxStr[i] == '1' ? 1u : 0u) << i;
}
switch (idx)
{
case 4:
Expand Down
2 changes: 1 addition & 1 deletion src/Qir/Tools/Microsoft.Quantum.Qir.Runtime.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.22.192799-alpha" />
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.22.192949-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.22.192799-alpha" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.22.192949-beta" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.6.0" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions src/Simulation/Common/Simulators.Dev.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<NativeRootPath>$([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/Native))</NativeRootPath>
<NativeBuildPath>$([MSBuild]::NormalizePath($(NativeRootPath)/build/drop))</NativeBuildPath>
<ExperimentalSimBuildPath>$([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/qdk_sim_rs/drop))</ExperimentalSimBuildPath>
<NativeSparseSimBuildPath>$([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/NativeSparseSimulator/build))</NativeSparseSimBuildPath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -26,6 +27,11 @@
<NativeDll Include="$([MSBuild]::NormalizePath($(ExperimentalSimBuildPath)/libqdk_sim.dylib))" Dest="osx/Microsoft.Quantum.Experimental.Simulators.Runtime.dll" />
<NativeDll Include="$([MSBuild]::NormalizePath($(ExperimentalSimBuildPath)/libqdk_sim.so))" Dest="linux/Microsoft.Quantum.Experimental.Simulators.Runtime.dll" />
<NativeDll Include="$([MSBuild]::NormalizePath($(ExperimentalSimBuildPath)/qdk_sim.dll))" Dest="win10/Microsoft.Quantum.Experimental.Simulators.Runtime.dll" />

<!-- Native Sparse Simulator: -->
<NativeDll Include="$([MSBuild]::NormalizePath($(NativeSparseSimBuildPath)/libSparseQuantumSimulator.dylib))" Dest="osx/libSparseQuantumSimulator.dylib" />
<NativeDll Include="$([MSBuild]::NormalizePath($(NativeSparseSimBuildPath)/libSparseQuantumSimulator.so))" Dest="linux/libSparseQuantumSimulator.so" />
<NativeDll Include="$([MSBuild]::NormalizePath($(NativeSparseSimBuildPath)/SparseQuantumSimulator.dll))" Dest="win10/SparseQuantumSimulator.dll" />
</ItemGroup>

<Copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Microsoft.Quantum.CSharpGeneration" Version="0.22.192799-alpha" />
<PackageReference Include="Microsoft.Quantum.CSharpGeneration" Version="0.22.192949-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Simulation/EntryPointDriver/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public Driver(DriverSettings settings, IReadOnlyCollection<IEntryPoint> entryPoi
suggestions: new[]
{
this.settings.QuantumSimulatorName,
// this.settings.SparseSimulatorName, // uncomment to enable listing the sparse simulator in the command line help
this.settings.ToffoliSimulatorName,
this.settings.ResourcesEstimatorName,
this.settings.DefaultSimulatorName
Expand Down
8 changes: 8 additions & 0 deletions src/Simulation/EntryPointDriver/DriverSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public sealed class DriverSettings
/// </summary>
internal string QuantumSimulatorName { get; }

/// <summary>
/// The name of the sparse simulator.
/// </summary>
internal string SparseSimulatorName { get; }

/// <summary>
/// The name of the Toffoli simulator.
/// </summary>
Expand Down Expand Up @@ -53,6 +58,7 @@ public sealed class DriverSettings
/// </summary>
/// <param name="simulatorOptionAliases">The aliases for the simulator command-line option.</param>
/// <param name="quantumSimulatorName">The name of the quantum simulator.</param>
/// <param name="sparseSimulatorName">The name of the sparse simulator.</param>
/// <param name="toffoliSimulatorName">The name of the Toffoli simulator.</param>
/// <param name="resourcesEstimatorName">The name of the resources estimator.</param>
/// <param name="defaultSimulatorName">The name of the default simulator to use.</param>
Expand All @@ -61,6 +67,7 @@ public sealed class DriverSettings
public DriverSettings(
ImmutableList<string> simulatorOptionAliases,
string quantumSimulatorName,
string sparseSimulatorName,
string toffoliSimulatorName,
string resourcesEstimatorName,
string defaultSimulatorName,
Expand All @@ -69,6 +76,7 @@ public DriverSettings(
{
SimulatorOptionAliases = simulatorOptionAliases;
QuantumSimulatorName = quantumSimulatorName;
SparseSimulatorName = sparseSimulatorName;
ToffoliSimulatorName = toffoliSimulatorName;
ResourcesEstimatorName = resourcesEstimatorName;
DefaultSimulatorName = defaultSimulatorName;
Expand Down
2 changes: 2 additions & 0 deletions src/Simulation/EntryPointDriver/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static async Task<int> Simulate(
var (isCustom, createSimulator) =
simulator == settings.QuantumSimulatorName
? (false, () => new QuantumSimulator())
: simulator == settings.SparseSimulatorName
? (false, () => new SparseSimulator())
: simulator == settings.ToffoliSimulatorName
? (false, new Func<IOperationFactory>(() => new ToffoliSimulator()))
: (true, settings.CreateDefaultCustomSimulator);
Expand Down
4 changes: 2 additions & 2 deletions src/Simulation/Native/src/simulator/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ extern "C"
}

// dump wavefunction to given callback until callback returns false
MICROSOFT_QUANTUM_DECL void Dump(_In_ unsigned id, _In_ bool (*callback)(size_t, double, double))
MICROSOFT_QUANTUM_DECL void Dump(_In_ unsigned id, _In_ bool (*callback)(const char*, double, double))
{
Microsoft::Quantum::Simulator::get(id)->dump(callback);
}
Expand All @@ -217,7 +217,7 @@ extern "C"
_In_ unsigned id,
_In_ unsigned n,
_In_reads_(n) unsigned* q,
_In_ bool (*callback)(size_t, double, double))
_In_ bool (*callback)(const char*, double, double))
{
std::vector<unsigned> qs(q, q + n);
return Microsoft::Quantum::Simulator::get(id)->dumpQubits(qs, callback);
Expand Down
4 changes: 2 additions & 2 deletions src/Simulation/Native/src/simulator/capi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ extern "C"
MICROSOFT_QUANTUM_DECL unsigned init(); // NOLINT
MICROSOFT_QUANTUM_DECL void destroy(_In_ unsigned sid); // NOLINT
MICROSOFT_QUANTUM_DECL void seed(_In_ unsigned sid, _In_ unsigned s); // NOLINT
MICROSOFT_QUANTUM_DECL void Dump(_In_ unsigned sid, _In_ bool (*callback)(size_t, double, double));
MICROSOFT_QUANTUM_DECL void Dump(_In_ unsigned sid, _In_ bool (*callback)(const char*, double, double));
MICROSOFT_QUANTUM_DECL bool DumpQubits(
_In_ unsigned sid,
_In_ unsigned n,
_In_reads_(n) unsigned* q,
_In_ bool (*callback)(size_t, double, double));
_In_ bool (*callback)(const char*, double, double));

typedef void* TDumpLocation;
typedef bool (*TDumpToLocationCallback)(size_t, double, double, TDumpLocation);
Expand Down
2 changes: 1 addition & 1 deletion src/Simulation/Native/src/simulator/capi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void CRx(unsigned sim_id, double phi, unsigned c, unsigned q)

void dump(unsigned sim_id, const char* label)
{
auto dump_callback = [](size_t idx, double r, double i) {
auto dump_callback = [](const char* idx, double r, double i) {
std::cout << idx << ":\t" << r << '\t' << i << '\n';
return true;
};
Expand Down
2 changes: 1 addition & 1 deletion src/Simulation/Native/src/simulator/dbw_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void CRx(unsigned sim_id, double phi, unsigned c, unsigned q)

void dump(unsigned sim_id, const char* label)
{
auto dump_callback = [](size_t idx, double r, double i) {
auto dump_callback = [](char const* idx, double r, double i) {
std::cout << idx << ":\t" << r << '\t' << i << '\n';
return true;
};
Expand Down
17 changes: 12 additions & 5 deletions src/Simulation/Native/src/simulator/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,19 @@ class Simulator : public Microsoft::Quantum::Simulator::SimulatorInterface
return psi.data().data();
}

void dump(bool (*callback)(size_t, double, double))
void dump(bool (*callback)(const char*, double, double))
{
recursive_lock_type l(getmutex());
flush();

auto wfn = psi.data();
auto nq = num_qubits();
std::string label_str(nq, '0');
for (std::size_t i = 0; i < wfn.size(); i++)
{
if (!callback(i, wfn[i].real(), wfn[i].imag())) return;
for (std::size_t j = 0; j < nq; ++j)
label_str[j] = ((i >> j)&1) ? '1' : '0';
if (!callback(label_str.c_str(), wfn[i].real(), wfn[i].imag())) return;
}
}

Expand Down Expand Up @@ -345,17 +349,20 @@ class Simulator : public Microsoft::Quantum::Simulator::SimulatorInterface
}
}

bool dumpQubits(std::vector<logical_qubit_id> const& qs, bool (*callback)(size_t, double, double))
bool dumpQubits(std::vector<logical_qubit_id> const& qs, bool (*callback)(const char*, double, double))
{
assert(qs.size() <= num_qubits());

WavefunctionStorage wfn(1ull << qs.size());

auto nq = num_qubits();
std::string label_str(nq, '0');
if (subsytemwavefunction(qs, wfn, 1e-10))
{
for (std::size_t i = 0; i < wfn.size(); i++)
{
if (!callback(i, wfn[i].real(), wfn[i].imag())) break;
for (std::size_t j = 0; j < nq; ++j)
label_str[j] = ((i >> j)&1) ? '1' : '0';
if (!callback(label_str.c_str(), wfn[i].real(), wfn[i].imag())) break;
}
return true;
}
Expand Down
Loading