Class QMLExecutor
Defined in File qml.hpp
Class Documentation
-
class QMLExecutor
A class which handles executing and obtaining shots from a parametrised cicuit, as well as gradient calculations.
Public Functions
-
QMLExecutor(ParamCirc inputCirc, std::vector<double> initInputs, std::vector<double> initWeights)
Creates an executor for a defined parametrized circuit with initial specifications for inputs and variational parameters.
- Parameters:
inputCirc – Parametrized circuit to be executed [qb::qml::ParamCirc]
initInputs – Inputs to initialise the execution with [std::vector<double>]
initWeights – Weights/variational gate parameters to initialise the execution with [std::vector<double>]
-
std::vector<double> constructFullParamVector()
Return full parameter vector, constructed from the defined input and weight parameter values.
-
void run()
Execute the circuit.
-
void runGradients()
Execute the circuit for gradient calculation (e.g. execute multiple +/- shifted circuits for the parameter-shift rule).
-
inline std::vector<double> getStats()
Obtain bitstring probabilities from the output buffer after running.
-
std::vector<std::vector<double>> getStatGradients()
Obtain the gradients of output probabilities w.r.t. the variational parameters.
-
inline void setInputParams(std::vector<double> inputs)
Manually set the input parameters for parametrized circuit execution.
-
inline void setWeights(std::vector<double> weights)
Manually set the variational/weight parameters for parametrized circuit execution.
-
inline void setCircuit(ParamCirc newCirc)
Manually set the parametrized circuit (qb::qml::ParamCirc) to be executed.
-
inline void setNumShots(std::size_t numShots)
Manually set the number of shots to run the circuit for during execution.
-
inline void setSeed(int seed)
Manually set the seed for the circuit executor.
-
inline std::vector<double> getInputParams()
Return the currently defined input parameter values.
-
inline std::vector<double> getWeights()
Return the currently defined variational parameter values.
-
inline ParamCirc getCircuit()
Return the currently defined parametrized circuit that is to be executed.
-
inline std::size_t getNumShots()
Return the currently defined number of shots.
-
inline int getSeed()
Return the currently defined seed.
-
inline std::shared_ptr<xacc::AcceleratorBuffer> getGradBuffer()
Return the gradient buffer which stores the gradient executions and shot results.
-
inline std::shared_ptr<xacc::AcceleratorBuffer> getBuffer()
Return the output buffer which stores the shot results from execution.
Public Members
-
std::string acc = "aer"
The currently defined accelerator (defaults to “aer”). Valid settings: “aer” | “tnqvm” | “qpp”.
Private Functions
-
std::vector<double> getStatsFromShots(std::map<std::string, int> shotsDict)
-
std::string gradientTypeToString()
Private Members
-
int seed_ = {-1}
-
bool seeded_ = {false}
-
std::size_t numShots_ = {1024}
-
std::shared_ptr<xacc::Accelerator> accPointer_{xacc::getAccelerator("aer", {{"shots", (int)numShots_}})}
-
std::vector<double> inputParamVals_
-
std::vector<double> weightParamVals_
-
std::shared_ptr<xacc::AcceleratorBuffer> outputBuffer_
-
std::shared_ptr<xacc::AcceleratorBuffer> gradientBuffer_
-
std::shared_ptr<xacc::Observable> observables_
-
GradientTypes gradientType_{GradientTypes::parameter_shift}
-
std::shared_ptr<xacc::AlgorithmGradientStrategy> gradientMethod_
-
QMLExecutor(ParamCirc inputCirc, std::vector<double> initInputs, std::vector<double> initWeights)