Maestro 0.3.11
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{
20
32template <typename Time = Types::time_type> class SimulatorsEstimatorInterface
33{
34 public:
35 virtual ~SimulatorsEstimatorInterface() = default;
36
37 virtual bool IsInitialized() const = 0;
38
39 virtual std::shared_ptr<Simulators::ISimulator> ChooseBestSimulator(
40 const std::vector<std::pair<Simulators::SimulatorType, Simulators::SimulationType>> &simulatorTypes, std::shared_ptr<Circuits::Circuit<Time>> &dcirc,
41 size_t &counts, size_t nrQubits, size_t nrCbits, size_t nrResultCbits, Simulators::SimulatorType &simType, Simulators::SimulationType &method,
42 std::vector<bool> &executed, const long long int maxBondDim, const double singularValueThreshold, const std::string &truncationMode,
43 const std::string &mpsSample, size_t maxSimulators, const std::vector<std::string> *paulis, bool multithreading = false) const = 0;
44
45 static void ExecuteUpToMeasurements(const std::shared_ptr<Circuits::Circuit<Time>> &dcirc, size_t nrQubits, size_t nrCbits, size_t nrResultCbits,
46 const std::shared_ptr<Simulators::ISimulator> &sim, std::vector<bool> &executed, size_t *curMaxBondDim = nullptr)
47 {
49 state.AllocateBits(nrCbits);
50
51 const bool hasMeasurementsOnlyAtEnd = !dcirc->HasOpsAfterMeasurements();
52
53 executed = dcirc->ExecuteNonMeasurements(sim, state, curMaxBondDim);
54
55 if (!hasMeasurementsOnlyAtEnd)
56 {
57 // Workers continue from this suffix, including when they receive a
58 // clone of the estimator's simulator and its saved routing context.
59 // RemoveExecutedOperations rewrites its mask. Preserve the caller's
60 // mask, whose indices still describe dcirc, for the execution workers.
61 auto suffixMask = executed;
62 if (suffixMask.empty())
63 sim->SetUpcomingGates({}); // The whole prefix was executed.
64 else
65 sim->SetUpcomingGates(dcirc->RemoveExecutedOperations(suffixMask)->GetOperations());
66 sim->SaveState();
67 }
68 }
69};
70
71} // namespace Estimators
72
73#endif // !__SIMULATORS_ESTIMATOR_INTERFACE_H_
Circuit class for holding the sequence of operations.
Definition Circuit.h:51
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:68
void AllocateBits(size_t numBits)
Allocate more bits.
Definition Operations.h:179
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, size_t *curMaxBondDim=nullptr)
virtual std::shared_ptr< Simulators::ISimulator > ChooseBestSimulator(const std::vector< std::pair< Simulators::SimulatorType, Simulators::SimulationType > > &simulatorTypes, 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 long long int maxBondDim, const double singularValueThreshold, const std::string &truncationMode, const std::string &mpsSample, size_t maxSimulators, const std::vector< std::string > *paulis, bool multithreading=false) const =0
virtual bool IsInitialized() const =0
SimulationType
The type of simulation.
Definition State.h:109
SimulatorType
The type of simulator.
Definition State.h:79