Added user provided seed to CFullStateSinulator (#780)
This commit is contained in:
Родитель
497a2f58d2
Коммит
1f4f5f5f4d
|
@ -10,6 +10,8 @@
|
|||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <climits>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
|
||||
#pragma clang diagnostic push
|
||||
// Ignore warnings for reserved macro names `_In_`, `_In_reads_(n)`:
|
||||
|
@ -159,7 +161,7 @@ namespace Quantum
|
|||
}
|
||||
|
||||
public:
|
||||
CFullstateSimulator()
|
||||
CFullstateSimulator(uint32_t userProvidedSeed = 0)
|
||||
: handle(LoadQuantumSimulator())
|
||||
{
|
||||
typedef unsigned (*TInit)();
|
||||
|
@ -167,6 +169,13 @@ namespace Quantum
|
|||
|
||||
qubitManager = std::make_unique<CQubitManager>();
|
||||
this->simulatorId = initSimulatorInstance();
|
||||
|
||||
typedef void (*TSeed)(unsigned, unsigned);
|
||||
static TSeed setSimulatorSeed = reinterpret_cast<TSeed>(this->GetProc("seed"));
|
||||
setSimulatorSeed(this->simulatorId,
|
||||
(userProvidedSeed == 0)
|
||||
? (unsigned)std::chrono::system_clock::now().time_since_epoch().count()
|
||||
: (unsigned)userProvidedSeed);
|
||||
}
|
||||
~CFullstateSimulator() override
|
||||
{
|
||||
|
@ -540,9 +549,9 @@ namespace Quantum
|
|||
DumpRegisterImpl(outStream, qubits);
|
||||
}
|
||||
|
||||
std::unique_ptr<IRuntimeDriver> CreateFullstateSimulator()
|
||||
std::unique_ptr<IRuntimeDriver> CreateFullstateSimulator(uint32_t userProvidedSeed /*= 0*/)
|
||||
{
|
||||
return std::make_unique<CFullstateSimulator>();
|
||||
return std::make_unique<CFullstateSimulator>(userProvidedSeed);
|
||||
}
|
||||
} // namespace Quantum
|
||||
} // namespace Microsoft
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
#include "QirRuntimeApi_I.hpp"
|
||||
|
||||
|
@ -16,7 +17,7 @@ namespace Quantum
|
|||
QIR_SHARED_API std::unique_ptr<IRuntimeDriver> CreateToffoliSimulator();
|
||||
|
||||
// Full State Simulator
|
||||
QIR_SHARED_API std::unique_ptr<IRuntimeDriver> CreateFullstateSimulator();
|
||||
QIR_SHARED_API std::unique_ptr<IRuntimeDriver> CreateFullstateSimulator(uint32_t userProvidedSeed = 0);
|
||||
|
||||
} // namespace Quantum
|
||||
} // namespace Microsoft
|
||||
|
|
Загрузка…
Ссылка в новой задаче