Maestro 0.2.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Simulators/Factory.h
Go to the documentation of this file.
1
15
16#pragma once
17
18#ifndef _SIMULATORS_FACTORY_H_
19#define _SIMULATORS_FACTORY_H_
20
22#include "GpuLibMPSSim.h"
23#include "GpuLibTNSim.h"
24#include "GpuStabilizer.h"
25#include "GpuPauliPropagator.h"
26#include "QuestLibSim.h"
28
29#include "Simulator.h"
30
31namespace Simulators {
32
40 public:
47 static std::shared_ptr<ISimulator> CreateSimulator(
50
57 static std::unique_ptr<ISimulator> CreateSimulatorUnique(
60
61#ifdef __linux__
62 static bool InitGpuLibrary();
63 static bool InitGpuLibraryWithMute();
64
65 static bool IsGpuLibraryAvailable() {
66 return gpuLibrary && gpuLibrary->IsValid();
67 }
68
69 static std::shared_ptr<GpuLibrary> GetGpuLibrary() {
70 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
71 return gpuLibrary;
72 }
73
74 static std::unique_ptr<GpuLibStateVectorSim> CreateGpuLibStateVectorSim() {
75 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
76
77 return std::make_unique<GpuLibStateVectorSim>(gpuLibrary);
78 }
79
80 static std::unique_ptr<GpuLibMPSSim> CreateGpuLibMPSSim() {
81 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
82
83 return std::make_unique<GpuLibMPSSim>(gpuLibrary);
84 }
85
86 static std::unique_ptr<GpuLibTNSim> CreateGpuLibTensorNetSim() {
87 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
88
89 return std::make_unique<GpuLibTNSim>(gpuLibrary);
90 }
91
92 static std::shared_ptr<GpuStabilizer> CreateGpuStabilizerSimulator() {
93 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
94 return std::make_shared<GpuStabilizer>(gpuLibrary);
95 }
96
97 static std::shared_ptr<GpuPauliPropagator>
98 CreateGpuPauliPropagatorSimulator() {
99 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
100 return std::make_shared<GpuPauliPropagator>(gpuLibrary);
101 }
102
103 static std::unique_ptr<GpuPauliPropagator>
104 CreateGpuPauliPropagatorSimulatorUnique() {
105 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
106 return std::make_unique<GpuPauliPropagator>(gpuLibrary);
107 }
108
109 private:
110 static std::shared_ptr<GpuLibrary> gpuLibrary;
111 static std::atomic_bool firstTime;
112
113 public:
114#else
115 static bool IsGpuLibraryAvailable() { return false; }
116
117 static bool InitGpuLibrary() { return false; }
118#endif
119 static bool InitQuestLibrary();
121 return questLibrary && questLibrary->IsValid();
122 }
123
124 static std::shared_ptr<QuestLibSim> GetQuestLibrary() {
125 if (!questLibrary || !questLibrary->IsValid()) return nullptr;
126 return questLibrary;
127 }
128
129 static std::shared_ptr<PathIntegralSimulator> CreatePathIntegralSimulator() {
130 return std::make_shared<PathIntegralSimulator>();
131 }
132
133 private:
134 static std::shared_ptr<QuestLibSim> questLibrary;
135 static std::atomic_bool firstTimeQuest;
136};
137
138} // namespace Simulators
139
140#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:101
static bool InitQuestLibrary()
Definition Factory.cpp:81
static std::unique_ptr< ISimulator > CreateSimulatorUnique(SimulatorType t=SimulatorType::kQCSim, SimulationType method=SimulationType::kMatrixProductState)
Create a quantum computing simulator.
Definition Factory.cpp:186
static std::shared_ptr< PathIntegralSimulator > CreatePathIntegralSimulator()
static std::shared_ptr< QuestLibSim > GetQuestLibrary()
SimulationType
The type of simulation.
Definition State.h:85
@ kMatrixProductState
matrix product state simulation type
Definition State.h:87
SimulatorType
The type of simulator.
Definition State.h:68
@ kQCSim
qcsim simulator type
Definition State.h:72