Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Simulators/Factory.h
Go to the documentation of this file.
1
15#pragma once
16
17#ifndef _SIMULATORS_FACTORY_H_
18#define _SIMULATORS_FACTORY_H_
19
21#include "GpuLibMPSSim.h"
22#include "GpuLibTNSim.h"
23#include "GpuStabilizer.h"
24#include "GpuPauliPropagator.h"
25
26#include "Simulator.h"
27
28namespace Simulators {
29
37 public:
44 static std::shared_ptr<ISimulator> CreateSimulator(
47
54 static std::unique_ptr<ISimulator> CreateSimulatorUnique(
57
58#ifdef __linux__
59 static bool InitGpuLibrary();
60 static bool InitGpuLibraryWithMute();
61
62 static bool IsGpuLibraryAvailable() {
63 return gpuLibrary && gpuLibrary->IsValid();
64 }
65
66 static std::shared_ptr<GpuLibrary> GetGpuLibrary() {
67 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
68 return gpuLibrary;
69 }
70
71 static std::unique_ptr<GpuLibStateVectorSim> CreateGpuLibStateVectorSim() {
72 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
73
74 return std::make_unique<GpuLibStateVectorSim>(gpuLibrary);
75 }
76
77 static std::unique_ptr<GpuLibMPSSim> CreateGpuLibMPSSim() {
78 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
79
80 return std::make_unique<GpuLibMPSSim>(gpuLibrary);
81 }
82
83 static std::unique_ptr<GpuLibTNSim> CreateGpuLibTensorNetSim() {
84 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
85
86 return std::make_unique<GpuLibTNSim>(gpuLibrary);
87 }
88
89 static std::shared_ptr<GpuStabilizer> CreateGpuStabilizerSimulator() {
90 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
91 return std::make_shared<GpuStabilizer>(gpuLibrary);
92 }
93
94 static std::shared_ptr<GpuPauliPropagator> CreateGpuPauliPropagatorSimulator() {
95 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
96 return std::make_shared<GpuPauliPropagator>(gpuLibrary);
97 }
98
99 static std::unique_ptr<GpuPauliPropagator> CreateGpuPauliPropagatorSimulatorUnique() {
100 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
101 return std::make_unique<GpuPauliPropagator>(gpuLibrary);
102 }
103
104 private:
105 static std::shared_ptr<GpuLibrary> gpuLibrary;
106 static std::atomic_bool firstTime;
107#else
108 static bool IsGpuLibraryAvailable() { return false; }
109
110 static bool InitGpuLibrary() { return false; }
111#endif
112};
113
114} // namespace Simulators
115
116#endif // !_SIMULATORS_FACTORY_H_
static std::shared_ptr< ISimulator > CreateSimulator(SimulatorType t=SimulatorType::kQCSim, SimulationType method=SimulationType::kMatrixProductState)
Create a quantum computing simulator.
Definition Factory.cpp:77
static std::unique_ptr< ISimulator > CreateSimulatorUnique(SimulatorType t=SimulatorType::kQCSim, SimulationType method=SimulationType::kMatrixProductState)
Create a quantum computing simulator.
Definition Factory.cpp:145
SimulationType
The type of simulation.
Definition State.h:79
@ kMatrixProductState
matrix product state simulation type
SimulatorType
The type of simulator.
Definition State.h:63
@ kQCSim
qcsim simulator type