11#ifdef MAESTRO_ENABLE_COMPOSER
12#include <composer/Estimators/ExecutionEstimator.h>
40#ifdef MAESTRO_ENABLE_COMPOSER
41 Estimators::ExecutionEstimator<>::InitializeRegressors();
53 if (!config.is_object())
55 const auto *value = config.as_object().if_contains(
"seed");
59 if (value->is_uint64())
60 seed = value->as_uint64();
61 else if (value->is_int64() && value->as_int64() >= 0)
62 seed =
static_cast<uint64_t
>(value->as_int64());
65 network.
Configure(
"seed", std::to_string(seed).c_str());
72 const char *setting =
"auto";
73 if (config.is_object())
75 if (
const auto *value = config.as_object().if_contains(
"gate_fusion"))
77 if (!value->is_bool())
79 setting = value->as_bool() ?
"true" :
"false";
82 network.
Configure(
"gate_fusion", setting);
89 std::string strategy =
"legacy";
90 bool enabled =
false, legacy =
false;
92 if (config.is_object())
94 if (
const auto *value = config.as_object().if_contains(
kStrategy))
96 if (!value->is_string())
98 strategy.assign(value->as_string().data(), value->as_string().size());
103 catch (
const std::invalid_argument &)
109 if (
const auto *value = config.as_object().if_contains(key))
111 if (!value->is_bool())
113 *target = value->as_bool();
117 if (!value->is_number())
119 weight = value->to_number<
double>();
120 if (!std::isfinite(weight) || weight < 0.)
137 std::string policy =
"shot_v1";
138 uint64_t workers = 0;
139 uint64_t memoryMb = 1024;
140 if (config.is_object())
142 if (
const auto *value = config.as_object().if_contains(
"trajectory_policy"))
144 if (!value->is_string())
146 policy = std::string(value->as_string());
147 if (policy !=
"block_v1" && policy !=
"shot_v1")
150 if (
const auto *value = config.as_object().if_contains(
"max_simulators"))
152 if (value->is_uint64())
153 workers = value->as_uint64();
154 else if (value->is_int64() && value->as_int64() > 0)
155 workers =
static_cast<uint64_t
>(value->as_int64());
158 if (!workers || workers > 1024)
161 if (
const auto *value = config.as_object().if_contains(
"trajectory_max_memory_mb"))
164 if (value->is_uint64())
165 mb = value->as_uint64();
166 else if (value->is_int64() && value->as_int64() > 0)
167 mb =
static_cast<uint64_t
>(value->as_int64());
170 if (!mb || mb > (std::numeric_limits<size_t>::max() >> 20))
177 network.
Configure(
"trajectory_max_memory_mb", std::to_string(memoryMb).c_str());
178 network.
Configure(
"trajectory_policy", policy.c_str());
181 catch (
const std::exception &)
187template <
int Dimension>
static Eigen::Matrix<std::complex<double>, Dimension, Dimension>
ReadGateMatrix(
const double *buffer)
190 throw std::invalid_argument(
"Null generic gate matrix");
191 Eigen::Matrix<std::complex<double>, Dimension, Dimension> matrix;
192 for (
int row = 0; row < Dimension; ++row)
193 for (
int col = 0; col < Dimension; ++col)
195 const auto index = 2 * (row * Dimension + col);
196 matrix(row, col) = {buffer[index], buffer[index + 1]};
212 if (capacity < count || (count && !interleaved))
214 const auto values = state.GetStateVector();
215 if (values.size() != count)
217 for (
size_t i = 0; i < count; ++i)
219 interleaved[2 * i] = values[i].real();
220 interleaved[2 * i + 1] = values[i].imag();
232 if (!sim || !real || !imag || (count && (!qubits || !matrices)))
237 if (count > std::numeric_limits<size_t>::max() / 8)
240 std::vector<Eigen::MatrixXcd> operators;
241 targets.reserve(count);
242 operators.reserve(count);
243 for (
size_t i = 0; i < count; ++i)
245 targets.push_back(qubits[i]);
248 const auto value =
static_cast<Simulators::ISimulator *
>(sim)->ExpectationValueOperators(targets, operators);
249 *real = value.real();
250 *imag = value.imag();
261 if (!sim || capacity < count || (count && (!paulis || !values)))
265 std::vector<std::string> observables;
266 observables.reserve(count);
267 for (
size_t i = 0; i < count; ++i)
271 observables.emplace_back(paulis[i]);
274 if (result.size() != count)
277 std::copy(result.begin(), result.end(), values);
288 if (!sim || capacity < count || (count && (!paulis || !real || !imag)))
292 std::vector<std::string> observables;
293 observables.reserve(count);
294 for (
size_t i = 0; i < count; ++i)
298 observables.emplace_back(paulis[i]);
300 const auto result =
static_cast<Simulators::ISimulator *
>(sim)->ExpectationValuesComplex(observables, normalized != 0);
301 if (result.size() != count)
303 for (
size_t i = 0; i < count; ++i)
305 real[i] = result[i].real();
306 imag[i] = result[i].imag();
323 if (!bits || !result || width != state.GetNumberOfQubits())
325 *result = state.
ProbabilityBits(std::vector<bool>(bits, bits + width));
341 if (!row || !col || !real || !imag || width != state.GetNumberOfQubits())
343 const auto value = state.
DensityMatrixElementBits(std::vector<bool>(row, row + width), std::vector<bool>(col, col + width));
344 *real = value.real();
345 *imag = value.imag();
364 *real = value.real();
365 *imag = value.imag();
381 if (!pauli || !real || !imag)
384 *real = value.real();
385 *imag = value.imag();
404 if (n > 13 || capacity < (
size_t{2} << (2 * n)))
406 const auto matrix = state.GetDensityMatrix(normalized != 0);
407 for (Eigen::Index i = 0; i < matrix.size(); ++i)
409 interleaved[2 * i] = matrix.data()[i].real();
410 interleaved[2 * i + 1] = matrix.data()[i].imag();
420 int MaestroApplyOperator(
void *sim,
const unsigned long int *qubits,
size_t count,
const double *interleaved,
int normalize)
427 if (!qubits || !interleaved || count < 1 || count > 2)
429 const size_t dim =
size_t{1} << count;
430 Eigen::MatrixXcd matrix(dim, dim);
431 for (
size_t i = 0; i < dim * dim; ++i)
432 matrix.data()[i] = {interleaved[2 * i], interleaved[2 * i + 1]};
449 if (count && !qubits)
453 targets.assign(qubits, qubits + count);
454 state.MoveAtBeginningOfChain(targets);
463 int MaestroSampleCountsBits(
void *sim,
const unsigned long int *qubits,
size_t width,
size_t shots,
unsigned char *outcomes,
unsigned long long *counts,
464 size_t capacity,
size_t *written)
474 if (!shots || !width)
476 if (!qubits || !outcomes || !counts || width > std::numeric_limits<size_t>::max() / shots || capacity < shots)
479 for (
const auto &entry : result)
481 for (
size_t i = 0; i < width; ++i)
482 outcomes[*written * width + i] = entry.first[i];
483 counts[*written] = entry.second;
494 int MaestroMeasureBits(
void *sim,
const unsigned long int *qubits,
size_t width,
unsigned char *outcomes)
501 if (!qubits || !outcomes || !width)
504 for (
size_t i = 0; i < width; ++i)
505 outcomes[i] = result[i];
544 if (!sim || !statistics)
549 *statistics = {value.submittedGates, value.backendGates, value.fusedBlocks};
567 simulator.ApplyGenericOneQubitGate(q0, matrix);
585 simulator.ApplyGenericTwoQubitGate(q0, q1, matrix);
603 simulator.ApplyGenericThreeQubitGate(q0, q1, q2, matrix);
613 __declspec(dllexport)
621 __declspec(dllexport)
629 __declspec(dllexport)
640 __declspec(dllexport)
651 __declspec(dllexport)
663 __declspec(dllexport)
675 __declspec(dllexport)
677 char *
SimpleExecute(
unsigned long int simpleSim,
const char *circuitStr,
const char *jsonConfig)
703 std::shared_ptr<Circuits::Circuit<>> circuit;
705 if (circuitStr[0] ==
'{' || circuitStr[0] ==
'[')
715 std::string qasmInput(circuitStr);
734 if (configJson.is_object())
736 const auto configObject = configJson.as_object();
741 if (configObject.contains(
"shots") && configObject.at(
"shots").is_number())
743 auto number = configObject.at(
"shots");
744 nrShots = number.is_int64() ? (size_t)number.as_int64() : (size_t)number.as_uint64();
748 bool configured =
false;
750 if (!gpuDevice.empty())
754 if (network->GetSimulator())
755 network->GetSimulator()->Clear();
756 network->Configure(
"gpu_device", gpuDevice.c_str());
760 if (!maxBondDim.empty())
763 if (network->GetSimulator())
764 network->GetSimulator()->Clear();
765 network->Configure(
"matrix_product_state_max_bond_dimension", maxBondDim.c_str());
769 if (!singularValueThreshold.empty())
772 if (network->GetSimulator())
773 network->GetSimulator()->Clear();
774 network->Configure(
"matrix_product_state_truncation_threshold", singularValueThreshold.c_str());
778 if (!truncationMode.empty())
781 if (network->GetSimulator())
782 network->GetSimulator()->Clear();
783 network->Configure(
"matrix_product_state_truncation_mode", truncationMode.c_str());
787 if (!mpsSample.empty())
790 if (network->GetSimulator())
791 network->GetSimulator()->Clear();
792 network->Configure(
"mps_sample_measure_algorithm", mpsSample.c_str());
795 if (configured || !network->GetSimulator())
796 network->CreateSimulator();
799 auto start = std::chrono::high_resolution_clock::now();
800 auto results = network->RepeatedExecuteOnHost(circuit, 0, nrShots);
801 auto end = std::chrono::high_resolution_clock::now();
803 std::chrono::duration<double> duration = end - start;
804 double time_taken = duration.count();
805 std::string timeStr = std::to_string(time_taken);
811 boost::json::object jsonResult;
812 jsonResult.reserve(results.size());
814 for (
auto &result : results)
816 boost::json::string bits;
817 bits.reserve(result.first.size());
818 for (
const auto bit : result.first)
819 bits.append(bit ?
"1" :
"0");
821 jsonResult.emplace(std::move(bits), std::move(result.second));
824 boost::json::object response;
827 response.emplace(
"counts", std::move(jsonResult));
828 const auto trajectory = network->GetSimulator() ? network->GetSimulator()->GetConfiguration(
"trajectory_policy") : std::string();
829 response.emplace(
"trajectory_policy", trajectory.empty() ?
"shot_v1" : trajectory);
830 response.emplace(
"time_taken", timeStr);
831 response.emplace(
"gate_fusion",
832 boost::json::object{{
"enabled", network->WasGateFusionEnabled()}, {
"max_qubits", network->GetLastGateFusionMaxQubits()}});
834 auto simulatorType = network->GetLastSimulatorType();
836 switch (simulatorType)
840 response.emplace(
"simulator",
"aer");
844 response.emplace(
"simulator",
"qcsim");
848 response.emplace(
"simulator",
"composite_aer");
852 response.emplace(
"simulator",
"composite_qcsim");
855 response.emplace(
"simulator",
"quest");
859 response.emplace(
"simulator",
"distributed_gpu_simulator");
862 response.emplace(
"simulator",
"distributed_mpi_gpu_simulator");
865 response.emplace(
"simulator",
"gpu_simulator");
866 response.emplace(
"gpu_device", network->GetLastGpuDevice());
870 response.emplace(
"simulator",
"unknown");
874 auto simulationType = network->GetLastSimulationType();
875 switch (simulationType)
878 response.emplace(
"method",
"statevector");
881 response.emplace(
"method",
"matrix_product_state");
884 response.emplace(
"method",
"stabilizer");
887 response.emplace(
"method",
"tensor_network");
890 response.emplace(
"method",
"pauli_propagation");
893 response.emplace(
"method",
"extended_stabilizer");
896 response.emplace(
"method",
"path_integral");
899 response.emplace(
"method",
"density_matrix");
902 response.emplace(
"method",
"unknown");
906 const std::string responseStr = boost::json::serialize(response);
907 const size_t responseSize = responseStr.length();
908 char *result =
new char[responseSize + 1];
910 const char *responseData = responseStr.c_str();
911 std::copy(responseData, responseData + responseSize, result);
913 result[responseSize] = 0;
919 __declspec(dllexport)
921 char *
SimpleEstimate(
unsigned long int simpleSim,
const char *circuitStr,
const char *observableStr,
const char *jsonConfig)
923 if (simpleSim == 0 || !circuitStr || !observableStr || !jsonConfig || !
maestroInstance)
928 std::shared_ptr<Circuits::Circuit<>> circuit;
930 if (circuitStr[0] ==
'{' || circuitStr[0] ==
'[')
938 std::string qasmInput(circuitStr);
952 bool configured =
false;
954 if (!gpuDevice.empty())
958 if (network->GetSimulator())
959 network->GetSimulator()->Clear();
960 network->Configure(
"gpu_device", gpuDevice.c_str());
964 if (!maxBondDim.empty())
967 if (network->GetSimulator())
968 network->GetSimulator()->Clear();
969 network->Configure(
"matrix_product_state_max_bond_dimension", maxBondDim.c_str());
973 if (!singularValueThreshold.empty())
976 if (network->GetSimulator())
977 network->GetSimulator()->Clear();
978 network->Configure(
"matrix_product_state_truncation_threshold", singularValueThreshold.c_str());
982 if (!truncationMode.empty())
985 if (network->GetSimulator())
986 network->GetSimulator()->Clear();
987 network->Configure(
"matrix_product_state_truncation_mode", truncationMode.c_str());
991 if (!mpsSample.empty())
994 if (network->GetSimulator())
995 network->GetSimulator()->Clear();
996 network->Configure(
"mps_sample_measure_algorithm", mpsSample.c_str());
999 if (configured || !network->GetSimulator())
1000 network->CreateSimulator();
1003 std::vector<std::string> paulis;
1004 std::string obsStr(observableStr);
1005 std::stringstream ss(obsStr);
1007 while (std::getline(ss, item,
';'))
1010 paulis.push_back(item);
1013 auto start = std::chrono::high_resolution_clock::now();
1014 auto expectations = network->ExecuteOnHostExpectations(circuit, 0, paulis);
1015 auto end = std::chrono::high_resolution_clock::now();
1017 std::chrono::duration<double> duration = end - start;
1018 double time_taken = duration.count();
1019 std::string timeStr = std::to_string(time_taken);
1021 boost::json::object response;
1022 response.reserve(4);
1024 boost::json::array jsonExpectations;
1025 jsonExpectations.reserve(expectations.size());
1026 for (
double val : expectations)
1028 jsonExpectations.push_back(val);
1031 response.emplace(
"expectation_values", std::move(jsonExpectations));
1032 response.emplace(
"time_taken", timeStr);
1033 response.emplace(
"gate_fusion",
1034 boost::json::object{{
"enabled", network->WasGateFusionEnabled()}, {
"max_qubits", network->GetLastGateFusionMaxQubits()}});
1036 auto simulatorType = network->GetLastSimulatorType();
1038 switch (simulatorType)
1040#ifndef NO_QISKIT_AER
1042 response.emplace(
"simulator",
"aer");
1046 response.emplace(
"simulator",
"qcsim");
1049 response.emplace(
"simulator",
"quest");
1051#ifndef NO_QISKIT_AER
1053 response.emplace(
"simulator",
"composite_aer");
1057 response.emplace(
"simulator",
"composite_qcsim");
1061 response.emplace(
"simulator",
"distributed_gpu_simulator");
1064 response.emplace(
"simulator",
"distributed_mpi_gpu_simulator");
1067 response.emplace(
"simulator",
"gpu_simulator");
1068 response.emplace(
"gpu_device", network->GetLastGpuDevice());
1072 response.emplace(
"simulator",
"unknown");
1076 auto simulationType = network->GetLastSimulationType();
1077 switch (simulationType)
1080 response.emplace(
"method",
"statevector");
1083 response.emplace(
"method",
"matrix_product_state");
1086 response.emplace(
"method",
"stabilizer");
1089 response.emplace(
"method",
"tensor_network");
1092 response.emplace(
"method",
"pauli_propagation");
1095 response.emplace(
"method",
"extended_stabilizer");
1098 response.emplace(
"method",
"path_integral");
1101 response.emplace(
"method",
"density_matrix");
1104 response.emplace(
"method",
"unknown");
1108 const std::string responseStr = boost::json::serialize(response);
1109 const size_t responseSize = responseStr.length();
1110 char *result =
new char[responseSize + 1];
1112 const char *responseData = responseStr.c_str();
1113 std::copy(responseData, responseData + responseSize, result);
1115 result[responseSize] = 0;
1121 __declspec(dllexport)
1130 __declspec(dllexport)
1141 __declspec(dllexport)
1151 __declspec(dllexport)
1161 __declspec(dllexport)
1169 simulator->
ApplyX(qubit);
1175 __declspec(dllexport)
1182 simulator->
ApplyY(qubit);
1188 __declspec(dllexport)
1196 simulator->
ApplyZ(qubit);
1201 __declspec(dllexport)
1208 simulator->
ApplyH(qubit);
1214 __declspec(dllexport)
1221 simulator->
ApplyS(qubit);
1227 __declspec(dllexport)
1240 __declspec(dllexport)
1247 simulator->
ApplyT(qubit);
1253 __declspec(dllexport)
1266 __declspec(dllexport)
1279 __declspec(dllexport)
1292 __declspec(dllexport)
1299 simulator->
ApplyK(qubit);
1305 __declspec(dllexport)
1307 int ApplyP(
void *sim,
int qubit,
double theta)
1312 simulator->
ApplyP(qubit, theta);
1318 __declspec(dllexport)
1325 simulator->
ApplyRx(qubit, theta);
1331 __declspec(dllexport)
1338 simulator->
ApplyRy(qubit, theta);
1344 __declspec(dllexport)
1351 simulator->
ApplyRz(qubit, theta);
1357 __declspec(dllexport)
1359 int ApplyU(
void *sim,
int qubit,
double theta,
double phi,
double lambda,
double gamma)
1364 simulator->
ApplyU(qubit, theta, phi, lambda, gamma);
1370 __declspec(dllexport)
1372 int ApplyCX(
void *sim,
int controlQubit,
int targetQubit)
1377 simulator->
ApplyCX(controlQubit, targetQubit);
1383 __declspec(dllexport)
1385 int ApplyCY(
void *sim,
int controlQubit,
int targetQubit)
1390 simulator->
ApplyCY(controlQubit, targetQubit);
1396 __declspec(dllexport)
1398 int ApplyCZ(
void *sim,
int controlQubit,
int targetQubit)
1403 simulator->
ApplyCZ(controlQubit, targetQubit);
1409 __declspec(dllexport)
1411 int ApplyCH(
void *sim,
int controlQubit,
int targetQubit)
1416 simulator->
ApplyCH(controlQubit, targetQubit);
1422 __declspec(dllexport)
1424 int ApplyCSX(
void *sim,
int controlQubit,
int targetQubit)
1429 simulator->
ApplyCSx(controlQubit, targetQubit);
1435 __declspec(dllexport)
1442 simulator->
ApplyCSxDAG(controlQubit, targetQubit);
1448 __declspec(dllexport)
1450 int ApplyCP(
void *sim,
int controlQubit,
int targetQubit,
double theta)
1455 simulator->
ApplyCP(controlQubit, targetQubit, theta);
1461 __declspec(dllexport)
1463 int ApplyCRx(
void *sim,
int controlQubit,
int targetQubit,
double theta)
1468 simulator->
ApplyCRx(controlQubit, targetQubit, theta);
1474 __declspec(dllexport)
1476 int ApplyCRy(
void *sim,
int controlQubit,
int targetQubit,
double theta)
1481 simulator->
ApplyCRy(controlQubit, targetQubit, theta);
1487 __declspec(dllexport)
1489 int ApplyCRz(
void *sim,
int controlQubit,
int targetQubit,
double theta)
1494 simulator->
ApplyCRz(controlQubit, targetQubit, theta);
1500 __declspec(dllexport)
1502 int ApplyCCX(
void *sim,
int controlQubit1,
int controlQubit2,
int targetQubit)
1507 simulator->
ApplyCCX(controlQubit1, controlQubit2, targetQubit);
1513 __declspec(dllexport)
1526 __declspec(dllexport)
1528 int ApplyCSwap(
void *sim,
int controlQubit,
int qubit1,
int qubit2)
1533 simulator->
ApplyCSwap(controlQubit, qubit1, qubit2);
1539 __declspec(dllexport)
1541 int ApplyCU(
void *sim,
int controlQubit,
int targetQubit,
double theta,
double phi,
double lambda,
double gamma)
1546 simulator->
ApplyCU(controlQubit, targetQubit, theta, phi, lambda, gamma);
1552 __declspec(dllexport)
1564 __declspec(dllexport)
1576 __declspec(dllexport)
1580 if (!sim || !key || !value)
1595 __declspec(dllexport)
1607 const size_t valueSize = value.length();
1608 char *result =
new char[valueSize + 1];
1609 std::copy(value.c_str(), value.c_str() + valueSize, result);
1610 result[valueSize] = 0;
1615 __declspec(dllexport)
1619 if (!sim || nrQubits == 0)
1624 return static_cast<unsigned long int>(res);
1628 __declspec(dllexport)
1636 return static_cast<unsigned long int>(res);
1640 __declspec(dllexport)
1652 __declspec(dllexport)
1654 unsigned long long int Measure(
void *sim,
const unsigned long int *qubits,
unsigned long int nrQubits)
1656 if (!sim || !qubits || nrQubits == 0)
1660 const size_t res = simulator->Measure(qubitVector);
1661 return static_cast<unsigned long long int>(res);
1665 __declspec(dllexport)
1667 int ApplyReset(
void *sim,
const unsigned long int *qubits,
unsigned long int nrQubits)
1669 if (!sim || !qubits || nrQubits == 0)
1673 simulator->ApplyReset(qubitVector);
1678 __declspec(dllexport)
1687 const double res = simulator->
Probability(outcome);
1692 return std::numeric_limits<double>::quiet_NaN();
1697 __declspec(dllexport)
1706 __declspec(dllexport)
1715 __declspec(dllexport)
1717 double *
Amplitude(
void *sim,
unsigned long long int outcome)
1724 const std::complex<double> amp = simulator->
Amplitude(outcome);
1726 double *result =
new double[2];
1727 result[0] = amp.real();
1728 result[1] = amp.imag();
1738 __declspec(dllexport)
1749 double *result =
new double[probabilities.size()];
1750 std::copy(probabilities.begin(), probabilities.end(), result);
1760 __declspec(dllexport)
1762 double *
Probabilities(
void *sim,
const unsigned long long int *qubits,
unsigned long int nrQubits)
1766 if (!sim || !qubits || nrQubits == 0)
1770 const auto probabilities = simulator->Probabilities(qubitVector);
1772 double *result =
new double[probabilities.size()];
1773 std::copy(probabilities.begin(), probabilities.end(), result);
1783 __declspec(dllexport)
1785 unsigned long long int *
SampleCounts(
void *sim,
const unsigned long long int *qubits,
unsigned long int nrQubits,
unsigned long int shots)
1789 if (!sim || !qubits || nrQubits == 0 || shots == 0)
1794 const auto counts = simulator->SampleCounts(qubitVector, shots);
1796 unsigned long long int *result =
new unsigned long long int[counts.size() * 2];
1798 for (
const auto &count : counts)
1800 result[index] = count.first;
1802 result[index] = count.second;
1814 __declspec(dllexport)
1821 return static_cast<int>(simulator->GetType());
1825 __declspec(dllexport)
1832 return static_cast<int>(simulator->GetSimulationType());
1836 __declspec(dllexport)
1848 __declspec(dllexport)
1860 __declspec(dllexport)
1872 __declspec(dllexport)
1891 __declspec(dllexport)
1910 __declspec(dllexport)
1922 __declspec(dllexport)
1933 __declspec(dllexport)
1940 return simulator->
IsQcsim() ? 1 : 0;
1944 __declspec(dllexport)
1951 return static_cast<unsigned long long int>(simulator->MeasureNoCollapse());
int MaestroGetStateVector(void *sim, double *interleaved, size_t capacity)
int ApplyK(void *sim, int qubit)
static std::once_flag initFlag
double Probability(void *sim, unsigned long long int outcome)
char * GetConfiguration(void *sim, const char *key)
int GetGateFusionStatistics(void *sim, MaestroGateFusionStatistics *statistics)
int MaestroMoveAtBeginningOfChain(void *sim, const unsigned long int *qubits, size_t count)
int MaestroMeasureBits(void *sim, const unsigned long int *qubits, size_t width, unsigned char *outcomes)
int InitializeSimulator(void *sim)
int RestoreState(void *sim)
void FreeDoubleVector(double *vec)
int ApplyRx(void *sim, int qubit, double theta)
int ApplyReset(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
int ApplyX(void *sim, int qubit)
int ApplyU(void *sim, int qubit, double theta, double phi, double lambda, double gamma)
int MaestroExpectationValues(void *sim, const char *const *paulis, size_t count, double *values, size_t capacity)
int AddOptimizationSimulator(unsigned long int simHandle, int simType, int simExecType)
unsigned long int CreateSimulator(int simType, int simExecType)
int ApplyCRy(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyTDG(void *sim, int qubit)
int ApplyCSXDG(void *sim, int controlQubit, int targetQubit)
int MaestroProbabilityBits(void *sim, const unsigned char *bits, size_t width, double *result)
static Eigen::Matrix< std::complex< double >, Dimension, Dimension > ReadGateMatrix(const double *buffer)
void FreeResult(char *result)
int ApplyS(void *sim, int qubit)
int MaestroDensityMatrixElementBits(void *sim, const unsigned char *row, const unsigned char *col, size_t width, double *real, double *imag)
int ApplyCX(void *sim, int controlQubit, int targetQubit)
unsigned long int AllocateQubits(void *sim, unsigned long int nrQubits)
char * SimpleExecute(unsigned long int simpleSim, const char *circuitStr, const char *jsonConfig)
int ApplyCRz(void *sim, int controlQubit, int targetQubit, double theta)
unsigned long int GetNumberOfQubits(void *sim)
double * AllProbabilities(void *sim)
void * GetMaestroObjectWithMute()
static bool ConfigureLegacyRouting(Network::INetwork<> &network, const boost::json::value &config)
unsigned long long int MeasureNoCollapse(void *sim)
int MaestroGetDensityMatrix(void *sim, int normalized, double *interleaved, size_t capacity)
int ApplyCP(void *sim, int controlQubit, int targetQubit, double theta)
int ApplySXDG(void *sim, int qubit)
void * GetMaestroObject()
static bool ConfigureLegacyFusion(Network::INetwork<> &network, const boost::json::value &config)
int GetMultithreading(void *sim)
int ApplySDG(void *sim, int qubit)
unsigned long long int Measure(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
int ApplyCSwap(void *sim, int controlQubit, int qubit1, int qubit2)
void DestroySimpleSimulator(unsigned long int simHandle)
int ApplyCCX(void *sim, int controlQubit1, int controlQubit2, int targetQubit)
int MaestroExpectationValueOperators(void *sim, const unsigned long int *qubits, size_t count, const double *matrices, double *real, double *imag)
int ApplyY(void *sim, int qubit)
double * Amplitude(void *sim, unsigned long long int outcome)
int ApplyZ(void *sim, int qubit)
int ApplyH(void *sim, int qubit)
int ApplyGenericThreeQubitGate(void *sim, unsigned long q0, unsigned long q1, unsigned long q2, const double *buffer)
int ApplyCY(void *sim, int controlQubit, int targetQubit)
static void * InitializeMaestro(bool mute)
char * SimpleEstimate(unsigned long int simpleSim, const char *circuitStr, const char *observableStr, const char *jsonConfig)
double * Probabilities(void *sim, const unsigned long long int *qubits, unsigned long int nrQubits)
int SetMultithreading(void *sim, int multithreading)
int ApplyCU(void *sim, int controlQubit, int targetQubit, double theta, double phi, double lambda, double gamma)
void DestroySimulator(unsigned long int simHandle)
int ApplySwap(void *sim, int qubit1, int qubit2)
int IsGateFusionEnabled(void *sim)
void * GetSimulator(unsigned long int simHandle)
static std::unique_ptr< Maestro > maestroInstance
int ApplyRy(void *sim, int qubit, double theta)
int ApplyP(void *sim, int qubit, double theta)
int SaveStateToInternalDestructive(void *sim)
int ApplyCH(void *sim, int controlQubit, int targetQubit)
int MaestroExpectationValuesComplex(void *sim, const char *const *paulis, size_t count, int normalized, double *real, double *imag, size_t capacity)
int FlushSimulator(void *sim)
unsigned long int CreateSimpleSimulator(int nrQubits)
int GetSimulationType(void *sim)
int ResetSimulator(void *sim)
unsigned long long int * SampleCounts(void *sim, const unsigned long long int *qubits, unsigned long int nrQubits, unsigned long int shots)
int ApplySX(void *sim, int qubit)
int ApplyCZ(void *sim, int controlQubit, int targetQubit)
int ApplyRz(void *sim, int qubit, double theta)
int GetSimulatorType(void *sim)
int RestoreInternalDestructiveSavedState(void *sim)
int MaestroExpectationValueComplex(void *sim, const char *pauli, int normalized, double *real, double *imag)
int ApplyT(void *sim, int qubit)
int MaestroSampleCountsBits(void *sim, const unsigned long int *qubits, size_t width, size_t shots, unsigned char *outcomes, unsigned long long *counts, size_t capacity, size_t *written)
int ApplyCRx(void *sim, int controlQubit, int targetQubit, double theta)
int MaestroDensityMatrixTrace(void *sim, double *real, double *imag)
int ConfigureSimulator(void *sim, const char *key, const char *value)
int ApplyGenericOneQubitGate(void *sim, unsigned long q0, const double *buffer)
int ApplyCSX(void *sim, int controlQubit, int targetQubit)
int ApplyGenericTwoQubitGate(void *sim, unsigned long q0, unsigned long q1, const double *buffer)
int ClearSimulator(void *sim)
unsigned GetGateFusionMaxQubits(void *sim)
int RemoveAllOptimizationSimulatorsAndAdd(unsigned long int simHandle, int simType, int simExecType)
void FreeULLIVector(unsigned long long int *vec)
int MaestroApplyOperator(void *sim, const unsigned long int *qubits, size_t count, const double *interleaved, int normalize)
static bool ConfigureLegacyTrajectories(Network::INetwork<> &network, const boost::json::value &config)
static bool ConfigureLegacySeed(Network::INetwork<> &network, const boost::json::value &config)
static boost::json::value ParseString(const char *str)
Parses a string containing json.
std::shared_ptr< Circuits::Circuit< Time > > ParseCircuit(const char *str) const
static std::string GetConfigString(const std::string &config, const boost::json::value &jsonConfig)
virtual void SetMaxSimulators(size_t maxSimulators)=0
Set the maximum number of simulators that can be used in the network.
virtual void Configure(const char *key, const char *value)=0
Configures the network.
static int ParseGpuDevice(const std::string &value)
Set a configuration value.
Interface class for a quantum computing simulator.
virtual void ApplyCRz(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
Applies a CRz gate to the qubits.
virtual void ApplySDG(Types::qubit_t qubit)=0
Applies a S dagger gate to the qubit.
virtual void ApplyCCX(Types::qubit_t qubit0, Types::qubit_t qubit1, Types::qubit_t qubit2)=0
Applies a controlled controlled not gate to the qubits.
virtual void ApplyX(Types::qubit_t qubit)=0
Applies a not gate to the qubit.
virtual void ApplyCSxDAG(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CSx dagger gate to the qubits.
virtual void ApplyU(Types::qubit_t qubit, double theta, double phi, double lambda, double gamma)=0
Applies a U gate to the qubit.
virtual void ApplyP(Types::qubit_t qubit, double lambda)=0
Applies a phase shift gate to the qubit.
virtual void ApplySx(Types::qubit_t qubit)=0
Applies a Sx gate to the qubit.
virtual void ApplyTDG(Types::qubit_t qubit)=0
Applies a T dagger gate to the qubit.
virtual void ApplyCU(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta, double phi, double lambda, double gamma)=0
Applies a controlled U gate to the qubits.
virtual void ApplyCRy(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
Applies a CRy gate to the qubits.
virtual void ApplyCX(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CX gate to the qubits.
virtual void ApplyRy(Types::qubit_t qubit, double theta)=0
Applies a Ry gate to the qubit.
virtual void ApplyCH(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CH gate to the qubits.
virtual void ApplySwap(Types::qubit_t qubit0, Types::qubit_t qubit1)=0
Applies a swap gate to the qubits.
virtual void ApplyCSx(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CSx gate to the qubits.
virtual void ApplyK(Types::qubit_t qubit)=0
Applies a K gate to the qubit.
virtual void ApplyY(Types::qubit_t qubit)=0
Applies a Y gate to the qubit.
virtual void ApplyT(Types::qubit_t qubit)=0
Applies a T gate to the qubit.
virtual void ApplyS(Types::qubit_t qubit)=0
Applies a S gate to the qubit.
virtual void ApplyCSwap(Types::qubit_t ctrl_qubit, Types::qubit_t qubit0, Types::qubit_t qubit1)=0
Applies a controlled swap gate to the qubits.
virtual void ApplyZ(Types::qubit_t qubit)=0
Applies a Z gate to the qubit.
virtual void ApplyRz(Types::qubit_t qubit, double theta)=0
Applies a Rz gate to the qubit.
virtual void ApplyCRx(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
Applies a CRx gate to the qubits.
virtual void ApplyCY(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CY gate to the qubits.
virtual void ApplyCZ(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CZ gate to the qubits.
virtual void ApplyH(Types::qubit_t qubit)=0
Applies a Hadamard gate to the qubit.
virtual void ApplyRx(Types::qubit_t qubit, double theta)=0
Applies a Rx gate to the qubit.
virtual void ApplySxDAG(Types::qubit_t qubit)=0
Applies a Sx dagger gate to the qubit.
virtual void ApplyCP(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double lambda)=0
Applies a CP gate to the qubits.
virtual bool IsQcsim() const =0
Returns if the simulator is a qcsim simulator.
virtual double ProbabilityBits(const std::vector< bool > &)
MPO extensions: bit vectors are q0-first; matrices use logical basis order.
virtual std::complex< double > ExpectationValueComplex(const std::string &, bool=true) const
virtual void SaveStateToInternalDestructive()=0
Saves the state to internal storage.
virtual void RestoreState()=0
Restores the state from the internally saved state.
virtual void SaveState()=0
Saves the state to internal storage.
virtual double Probability(Types::qubit_t outcome)=0
Returns the probability of the specified outcome.
virtual void Initialize()=0
Initializes the state.
virtual size_t AllocateQubits(size_t num_qubits)=0
Allocates qubits.
virtual std::vector< double > AllProbabilities()=0
Returns the probabilities of all possible outcomes.
virtual std::vector< bool > MeasureMany(const Types::qubits_vector &qubits)=0
Performs a measurement on the specified qubits.
virtual void RestoreInternalDestructiveSavedState()=0
Restores the state from the internally saved state.
virtual void SetMultithreading(bool multithreading=true)=0
Enable/disable multithreading.
virtual std::complex< double > Amplitude(Types::qubit_t outcome)=0
Returns the amplitude of the specified state.
virtual size_t GetNumberOfQubits() const =0
Returns the number of qubits.
virtual void Flush()=0
Flushes the applied operations.
virtual std::unordered_map< std::vector< bool >, Types::qubit_t > SampleCountsMany(const Types::qubits_vector &qubits, size_t shots=1000)=0
Returns the counts of the outcomes of measurement of the specified qubits, for repeated measurements.
virtual void Configure(const char *key, const char *value)=0
Configures the state.
virtual void Clear()=0
Clears the state.
virtual bool GetMultithreading() const =0
Get the multithreading flag.
virtual std::complex< double > DensityMatrixTrace() const
Mixed-state diagnostics.
virtual std::complex< double > DensityMatrixElementBits(const std::vector< bool > &, const std::vector< bool > &) const
virtual void Reset()=0
Just resets the state to 0.
virtual std::string GetConfiguration(const char *key) const =0
Returns configuration value.
static MAESTRO_FACTORY_EXPORT bool InitQuestLibrary()
static MAESTRO_FACTORY_EXPORT bool InitQuestLibraryWithMute()
std::shared_ptr< Circuits::Circuit< Time > > ParseAndTranslate(const std::string &qasmInputStr)
constexpr const char * kLegacyCap
constexpr const char * kTruncationWeight
constexpr const char * kVirtualBonds
constexpr const char * kStrategy
Strategy ParseStrategy(const std::string &value)
size_t DenseSize(size_t qubits)
SimulationType
The type of simulation.
@ kExtendedStabilizer
Extended stabilizer simulation type.
@ kStatevector
statevector simulation type
@ kMatrixProductState
matrix product state simulation type
@ kDensityMatrix
Density matrix simulation type.
@ kStabilizer
Clifford gates simulation type.
@ kPauliPropagator
Pauli propagator simulation type.
@ kTensorNetwork
Tensor network simulation type.
@ kPathIntegral
Path integral simulation type.
void ValidateGenericGate(const ISimulator &simulator, std::initializer_list< Types::qubit_t > targets, const Matrix &matrix)
SimulatorType
The type of simulator.
@ kCompositeQCSim
composite qcsim simulator type
@ kQCSim
qcsim simulator type
@ kQiskitAer
qiskit aer simulator type
@ kQuestSim
quest simulator type
@ kDistMpiGpuSim
state distributed across MPI ranks/GPUs
@ kCompositeQiskitAer
composite qiskit aer simulator type
@ kDistGpuSim
state distributed across local GPUs
@ kGpuSim
gpu simulator type
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.