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
8 changes: 8 additions & 0 deletions src/Simulation/Common/Simulators.Dev.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<QSimDll Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(QsimDllMac)</QSimDll>
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(QsimDllLinux)</QSimDll>
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(QsimDllWindows)</QSimDll>
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('OSX'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../osx))</QSimDependencies>
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('Linux'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../linux))</QSimDependencies>
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('Windows'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../win10))</QSimDependencies>
</PropertyGroup>

<ItemGroup>
Expand All @@ -29,6 +32,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(QSimDependencies)/**/*" >
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>

<!-- Copy the experimental simulators from xplat/qdk_sim_rs build to where we can see and use it. -->
Expand Down
3 changes: 3 additions & 0 deletions src/Simulation/Simulators/QuantumSimulator/NativeImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public partial class QuantumSimulator
// Preparation\Arbitrary.cs(23,41): error CS0117: 'QuantumSimulator' does not contain a definition for
// 'QSIM_DLL_NAME' [D:\a\1\s\submodules\QuantumLibraries\Standard\src\Standard.csproj]

[DllImport("libomp", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "omp_get_num_threads")]
private static extern int OmpGetNumberOfThreadsNative();

private delegate void IdsCallback(uint id);
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DumpIds")]
private static extern void sim_QubitsIdsNative(uint id, IdsCallback callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public QuantumSimulator(
randomNumberGeneratorSeed,
disableBorrowing)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// We don't need this value, but explicitly calling an OMP function should trigger the load of libomp
// by .NET from the runtimes folder for the current platform, such that the later library load by the
// simulator does not need to know where to search for it.
var threadCount = OmpGetNumberOfThreadsNative();
}

Id = InitNative();
// Make sure that the same seed used by the built-in System.Random
// instance is also used by the native simulator itself.
Expand Down