Maestro 0.2.5
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Simulators/Factory.h
Go to the documentation of this file.
1
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"
27
28#include "Simulator.h"
29
30namespace Simulators {
31
39 public:
46 static std::shared_ptr<ISimulator> CreateSimulator(
49
56 static std::unique_ptr<ISimulator> CreateSimulatorUnique(
59
60#ifdef __linux__
61 static bool InitGpuLibrary();
62 static bool InitGpuLibraryWithMute();
63
64 static bool IsGpuLibraryAvailable() {
65 return gpuLibrary && gpuLibrary->IsValid();
66 }
67
68 static std::shared_ptr<GpuLibrary> GetGpuLibrary() {
69 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
70 return gpuLibrary;
71 }
72
73 static std::unique_ptr<GpuLibStateVectorSim> CreateGpuLibStateVectorSim() {
74 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
75
76 return std::make_unique<GpuLibStateVectorSim>(gpuLibrary);
77 }
78
79 static std::unique_ptr<GpuLibMPSSim> CreateGpuLibMPSSim() {
80 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
81
82 return std::make_unique<GpuLibMPSSim>(gpuLibrary);
83 }
84
85 static std::unique_ptr<GpuLibTNSim> CreateGpuLibTensorNetSim() {
86 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
87
88 return std::make_unique<GpuLibTNSim>(gpuLibrary);
89 }
90
91 static std::shared_ptr<GpuStabilizer> CreateGpuStabilizerSimulator() {
92 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
93 return std::make_shared<GpuStabilizer>(gpuLibrary);
94 }
95
96 static std::shared_ptr<GpuPauliPropagator>
97 CreateGpuPauliPropagatorSimulator() {
98 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
99 return std::make_shared<GpuPauliPropagator>(gpuLibrary);
100 }
101
102 static std::unique_ptr<GpuPauliPropagator>
103 CreateGpuPauliPropagatorSimulatorUnique() {
104 if (!gpuLibrary || !gpuLibrary->IsValid()) return nullptr;
105 return std::make_unique<GpuPauliPropagator>(gpuLibrary);
106 }
107
108 private:
109 static std::shared_ptr<GpuLibrary> gpuLibrary;
110 static std::atomic_bool firstTime;
111
112 public:
113#else
114 static bool IsGpuLibraryAvailable() { return false; }
115
116 static bool InitGpuLibrary() { return false; }
117#endif
118 static bool InitQuestLibrary();
120 return questLibrary && questLibrary->IsValid();
121 }
122
123 static std::shared_ptr<QuestLibSim> GetQuestLibrary() {
124 if (!questLibrary || !questLibrary->IsValid()) return nullptr;
125 return questLibrary;
126 }
127
128 private:
129 static std::shared_ptr<QuestLibSim> questLibrary;
130 static std::atomic_bool firstTimeQuest;
131};
132
133} // namespace Simulators
134
135#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:184
static std::shared_ptr< QuestLibSim > GetQuestLibrary()
SimulationType
The type of simulation.
Definition State.h:85
@ kMatrixProductState
matrix product state simulation type
SimulatorType
The type of simulator.
Definition State.h:68
@ kQCSim
qcsim simulator type