Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Factory.cpp
Go to the documentation of this file.
1
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#ifndef NO_QISKIT_AER
34#include "AerSimulator.h"
35#endif
36#include "QCSimSimulator.h"
37#include "Composite.h"
38#include "GpuSimulator.h"
39
40namespace Simulators {
41
42#ifdef __linux__
43std::shared_ptr<GpuLibrary> SimulatorsFactory::gpuLibrary = nullptr;
44std::atomic_bool SimulatorsFactory::firstTime = true;
45
47 if (!gpuLibrary) {
48 gpuLibrary = std::make_shared<GpuLibrary>();
49 if (!firstTime.exchange(false)) 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> SimulatorsFactory::CreateSimulator(
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");
89 sim->Configure("method", "pauli_propagator");
90
91 return sim;
92 }
93#ifndef NO_QISKIT_AER
95 auto sim = std::make_shared<Private::AerSimulator>();
97 sim->Configure("method", "matrix_product_state");
98 else if (m == SimulationType::kStabilizer)
99 sim->Configure("method", "stabilizer");
100 else if (m == SimulationType::kTensorNetwork)
101 sim->Configure("method", "tensor_network");
103 sim->Configure("method", "extended_stabilizer");
104 else
105 sim->Configure("method", "statevector");
106
107 return sim;
108 }
110 return std::make_shared<Private::CompositeSimulator>(
112#endif
114 return std::make_shared<Private::CompositeSimulator>(
116#ifdef __linux__
118 if (gpuLibrary && gpuLibrary->IsValid() &&
123 auto sim = std::make_shared<Private::GpuSimulator>();
125 sim->Configure("method", "matrix_product_state");
126 else if (m == SimulationType::kTensorNetwork)
127 sim->Configure("method", "tensor_network");
129 sim->Configure("method", "pauli_propagator");
130
131 return sim;
132 }
133
134 return nullptr;
135#endif
136 default:
137 break;
138 }
139
140 throw std::invalid_argument("Simulator Type not supported");
141
142 return nullptr; // keep compillers happy
143}
144
147 switch (t) {
149 auto sim = std::make_unique<Private::QCSimSimulator>();
151 sim->Configure("method", "matrix_product_state");
152 else if (m == SimulationType::kStabilizer)
153 sim->Configure("method", "stabilizer");
154 else if (m == SimulationType::kTensorNetwork)
155 sim->Configure("method", "tensor_network");
157 sim->Configure("method", "pauli_propagator");
158
159 return sim;
160 }
161#ifndef NO_QISKIT_AER
163 auto sim = std::make_unique<Private::AerSimulator>();
165 sim->Configure("method", "matrix_product_state");
166 else if (m == SimulationType::kStabilizer)
167 sim->Configure("method", "stabilizer");
168 else if (m == SimulationType::kTensorNetwork)
169 sim->Configure("method", "tensor_network");
171 sim->Configure("method", "extended_stabilizer");
172 else
173 sim->Configure("method", "statevector");
174
175 return sim;
176 }
178 return std::make_unique<Private::CompositeSimulator>(
180#endif
182 return std::make_unique<Private::CompositeSimulator>(
184#ifdef __linux__
186 if (gpuLibrary && gpuLibrary->IsValid() &&
191 auto sim = std::make_unique<Private::GpuSimulator>();
193 sim->Configure("method", "matrix_product_state");
194 else if (m == SimulationType::kTensorNetwork)
195 sim->Configure("method", "tensor_network");
197 sim->Configure("method", "pauli_propagator");
198
199 return sim;
200 }
201
202 return nullptr;
203#endif
204 default:
205 break;
206 }
207
208 throw std::invalid_argument("Simulator Type not supported");
209
210 return nullptr; // keep compillers happy
211}
212} // namespace Simulators
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
@ kExtendedStabilizer
Extended stabilizer simulation type.
@ kStatevector
statevector simulation type
@ kMatrixProductState
matrix product state simulation type
@ kStabilizer
Clifford gates simulation type.
@ kPauliPropagator
Pauli propagator simulation type.
@ kTensorNetwork
Tensor network simulation type.
SimulatorType
The type of simulator.
Definition State.h:63
@ kCompositeQCSim
composite qcsim simulator type
@ kQCSim
qcsim simulator type
@ kQiskitAer
qiskit aer simulator type
@ kCompositeQiskitAer
composite qiskit aer simulator type
@ kGpuSim
gpu simulator type