Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
RandomSeed.h
Go to the documentation of this file.
1// Fresh execution seeds, including one shared seed for an MPI communicator.
2#pragma once
4#ifdef __linux__
6#endif
7#include <charconv>
8
9namespace Simulators
10{
11inline uint64_t GenerateRandomSeed(SimulatorType type, const std::unordered_map<std::string, std::string> &options = {})
12{
14 {
15#ifdef __linux__
16 DistributedMpiGpuLibrary::Communicator descriptor{sizeof(descriptor), 0, 0};
17 const auto found = options.find("mpi_communicator");
18 const auto *communicator = &descriptor;
19 if (found == options.end())
20 {
21 communicator = nullptr;
22 }
23 else
24 {
25 const auto &value = found->second;
26 const auto parsed = std::from_chars(value.data(), value.data() + value.size(), descriptor.fortran_handle);
27 if (parsed.ec != std::errc{} || parsed.ptr != value.data() + value.size())
28 throw std::invalid_argument("Invalid MPI communicator handle");
29 }
30 return DistributedMpiGpuLibrary::GetInstance()->GenerateSeed(communicator);
31#else
32 throw std::runtime_error("MPI GPU execution requires Linux");
33#endif
34 }
35 std::random_device entropy;
36 return std::uniform_int_distribution<uint64_t>{}(entropy);
37}
38} // namespace Simulators
Bounded online routing based on current physical bond dimensions.
uint64_t GenerateRandomSeed(SimulatorType type, const std::unordered_map< std::string, std::string > &options={})
Definition RandomSeed.h:11
SimulatorType
The type of simulator.
Definition State.h:79
@ kDistMpiGpuSim
state distributed across MPI ranks/GPUs
Definition State.h:91