Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
SimulatorsEstimatorInterface.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#ifndef __SIMULATORS_ESTIMATOR_INTERFACE_H_
13#define __SIMULATORS_ESTIMATOR_INTERFACE_H_
14
15#include "../Circuit/Circuit.h"
17
18namespace Estimators {
19
31template <typename Time = Types::time_type> class SimulatorsEstimatorInterface {
32public:
33 virtual ~SimulatorsEstimatorInterface() = default;
34
35 virtual std::shared_ptr<Simulators::ISimulator> ChooseBestSimulator(
36 const std::vector<std::pair<Simulators::SimulatorType,
37 Simulators::SimulationType>> &simulatorTypes,
38 const std::shared_ptr<Circuits::Circuit<Time>> &dcirc, size_t &counts,
39 size_t nrQubits, size_t nrCbits, size_t nrResultCbits,
41 std::vector<bool> &executed, const std::string &maxBondDim,
42 const std::string &singularValueThreshold, const std::string &mpsSample,
43 size_t maxSimulators, const std::vector<std::string> *paulis,
44 bool multithreading = false, bool dontRunCircuitStart = false) const = 0;
45
46 static void
47 ExecuteUpToMeasurements(const std::shared_ptr<Circuits::Circuit<Time>> &dcirc,
48 size_t nrQubits, size_t nrCbits, size_t nrResultCbits,
49 const std::shared_ptr<Simulators::ISimulator> &sim,
50 std::vector<bool> &executed, bool multithreading) {
52 state.AllocateBits(nrCbits);
53
54 const bool hasMeasurementsOnlyAtEnd = !dcirc->HasOpsAfterMeasurements();
55 const bool specialOptimizationForStatevector =
56 sim->GetSimulationType() == Simulators::SimulationType::kStatevector &&
57 hasMeasurementsOnlyAtEnd;
58 const bool specialOptimizationForMPS =
59 sim->GetSimulationType() ==
61 hasMeasurementsOnlyAtEnd;
62
63 sim->AllocateQubits(nrQubits);
64 sim->Initialize();
65
66 executed = dcirc->ExecuteNonMeasurements(sim, state);
67
68 if (!specialOptimizationForStatevector && !specialOptimizationForMPS)
69 sim->SaveState();
70 }
71};
72
73} // namespace Estimators
74
75#endif // !__SIMULATORS_ESTIMATOR_INTERFACE_H_
Circuit class for holding the sequence of operations.
Definition Circuit.h:45
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:62
void AllocateBits(size_t numBits)
Allocate more bits.
Definition Operations.h:159
static void ExecuteUpToMeasurements(const std::shared_ptr< Circuits::Circuit< Time > > &dcirc, size_t nrQubits, size_t nrCbits, size_t nrResultCbits, const std::shared_ptr< Simulators::ISimulator > &sim, std::vector< bool > &executed, bool multithreading)
virtual std::shared_ptr< Simulators::ISimulator > ChooseBestSimulator(const std::vector< std::pair< Simulators::SimulatorType, Simulators::SimulationType > > &simulatorTypes, const std::shared_ptr< Circuits::Circuit< Time > > &dcirc, size_t &counts, size_t nrQubits, size_t nrCbits, size_t nrResultCbits, Simulators::SimulatorType &simType, Simulators::SimulationType &method, std::vector< bool > &executed, const std::string &maxBondDim, const std::string &singularValueThreshold, const std::string &mpsSample, size_t maxSimulators, const std::vector< std::string > *paulis, bool multithreading=false, bool dontRunCircuitStart=false) const =0
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
SimulatorType
The type of simulator.
Definition State.h:63