Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Factory.cpp
Go to the documentation of this file.
1
15
16#define _CRT_SECURE_NO_WARNINGS 1
17
18#ifndef NO_QISKIT_AER
19#ifndef __APPLE__
20#ifndef _QV_AVX2_IMPL
21#define _QV_AVX2_IMPL
22#pragma warning(push)
23#pragma warning(disable : 4789)
24#include "simulators/statevector/qv_avx2.cpp"
25#pragma warning(pop)
26#endif
27#endif
28#endif
29
30#include "Factory.h"
31
32#define INCLUDED_BY_FACTORY
33#include "AerSimulator.h"
34#include "QCSimSimulator.h"
35#include "Composite.h"
36#include "GpuSimulator.h"
37
38
39namespace Simulators {
40
41#ifdef __linux__
42std::shared_ptr<GpuLibrary> SimulatorsFactory::gpuLibrary = nullptr;
43std::atomic_bool SimulatorsFactory::firstTime = true;
44
46 if (!gpuLibrary) {
47 gpuLibrary = std::make_shared<GpuLibrary>();
48 if (!firstTime.exchange(false))
49 gpuLibrary->SetMute(true);
50
51 if (gpuLibrary->Init("libcomposer_gpu_simulators.so"))
52 return true;
53 else
54 gpuLibrary = nullptr;
55 }
56
57 return false;
58}
59
60bool SimulatorsFactory::InitGpuLibraryWithMute() {
61 if (!gpuLibrary) {
62 gpuLibrary = std::make_shared<GpuLibrary>();
63 firstTime = false;
64 gpuLibrary->SetMute(true);
65
66 if (gpuLibrary->Init("libcomposer_gpu_simulators.so"))
67 return true;
68 else
69 gpuLibrary = nullptr;
70 }
71
72 return false;
73}
74
75#endif
76
77std::shared_ptr<ISimulator>
79 switch (t) {
81 auto sim = std::make_shared<Private::QCSimSimulator>();
83 sim->Configure("method", "matrix_product_state");
84 else if (m == SimulationType::kStabilizer)
85 sim->Configure("method", "stabilizer");
87 sim->Configure("method", "tensor_network");
88
89 return sim;
90 }
91#ifndef NO_QISKIT_AER
93 auto sim = std::make_shared<Private::AerSimulator>();
95 sim->Configure("method", "matrix_product_state");
96 else if (m == SimulationType::kStabilizer)
97 sim->Configure("method", "stabilizer");
99 sim->Configure("method", "tensor_network");
100 else
101 sim->Configure("method", "statevector");
102
103 return sim;
104 }
106 return std::make_shared<Private::CompositeSimulator>(
108#endif
110 return std::make_shared<Private::CompositeSimulator>(SimulatorType::kQCSim);
111#ifdef __linux__
112 case SimulatorType::kGpuSim:
113 if (gpuLibrary && gpuLibrary->IsValid() &&
116 auto sim = std::make_shared<Private::GpuSimulator>();
118 sim->Configure("method", "matrix_product_state");
119
120 return sim;
121 }
122
123 return nullptr;
124#endif
125 default:
126 break;
127 }
128
129 throw std::invalid_argument("Simulator Type not supported");
130
131 return nullptr; // keep compillers happy
132}
133
134std::unique_ptr<ISimulator>
136 switch (t) {
138 auto sim = std::make_unique<Private::QCSimSimulator>();
140 sim->Configure("method", "matrix_product_state");
141 else if (m == SimulationType::kStabilizer)
142 sim->Configure("method", "stabilizer");
143 else if (m == SimulationType::kTensorNetwork)
144 sim->Configure("method", "tensor_network");
145
146 return sim;
147 }
148#ifndef NO_QISKIT_AER
150 auto sim = std::make_unique<Private::AerSimulator>();
152 sim->Configure("method", "matrix_product_state");
153 else if (m == SimulationType::kStabilizer)
154 sim->Configure("method", "stabilizer");
155 else if (m == SimulationType::kTensorNetwork)
156 sim->Configure("method", "tensor_network");
157 else
158 sim->Configure("method", "statevector");
159
160 return sim;
161 }
163 return std::make_unique<Private::CompositeSimulator>(
165#endif
167 return std::make_unique<Private::CompositeSimulator>(SimulatorType::kQCSim);
168#ifdef __linux__
169 case SimulatorType::kGpuSim:
170 if (gpuLibrary && gpuLibrary->IsValid() &&
173 auto sim = std::make_unique<Private::GpuSimulator>();
175 sim->Configure("method", "matrix_product_state");
176
177 return sim;
178 }
179
180 return nullptr;
181#endif
182 default:
183 break;
184 }
185
186 throw std::invalid_argument("Simulator Type not supported");
187
188 return nullptr; // keep compillers happy
189}
190} // namespace Simulators
static std::shared_ptr< ISimulator > CreateSimulator(SimulatorType t=SimulatorType::kQCSim, SimulationType method=SimulationType::kMatrixProductState)
Create a quantum computing simulator.
Definition Factory.cpp:78
static std::unique_ptr< ISimulator > CreateSimulatorUnique(SimulatorType t=SimulatorType::kQCSim, SimulationType method=SimulationType::kMatrixProductState)
Create a quantum computing simulator.
Definition Factory.cpp:135
SimulationType
The type of simulation.
Definition State.h:82
@ kStatevector
statevector simulation type
Definition State.h:83
@ kMatrixProductState
matrix product state simulation type
Definition State.h:84
@ kStabilizer
Clifford gates simulation type.
Definition State.h:85
@ kTensorNetwork
Tensor network simulation type.
Definition State.h:86
SimulatorType
The type of simulator.
Definition State.h:63
@ kCompositeQCSim
composite qcsim simulator type
Definition State.h:71
@ kQCSim
qcsim simulator type
Definition State.h:67
@ kQiskitAer
qiskit aer simulator type
Definition State.h:65
@ kCompositeQiskitAer
composite qiskit aer simulator type
Definition State.h:69