Commit cf32a0b5 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding ability to query state from Accelerator



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 2a3229b3
#include "XACC.hpp"
#include <pybind11/pybind11.h>
#include "IRGenerator.hpp"
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/eigen.h>
......@@ -85,6 +87,10 @@ PYBIND11_MODULE(_pyxacc, m) {
py::class_<xacc::IRPreprocessor, std::shared_ptr<xacc::IRPreprocessor>> (m, "IRPreprocesor", "").def("process", &xacc::IRPreprocessor::process, "");
py::class_<xacc::AcceleratorBufferPostprocessor, std::shared_ptr<xacc::AcceleratorBufferPostprocessor>> (m, "AcceleratorBufferPostprocessor", "").def("process", &xacc::AcceleratorBufferPostprocessor::process, "");
py::class_<xacc::IRGenerator, std::shared_ptr<xacc::IRGenerator>>(m, "IRGenerator", "")
.def("generate", (std::shared_ptr<xacc::Function> (xacc::IRGenerator::*)(
std::vector<xacc::InstructionParameter>)) &xacc::IRGenerator::generate, py::return_value_policy::reference, "");
// Expose the Kernel
py::class_<xacc::Kernel<>, std::shared_ptr<xacc::Kernel<>>>(m, "Kernel", "The XACC Kernel is the "
"executable functor that executes XACC IR on the desired Accelerator.")
......@@ -190,7 +196,10 @@ PYBIND11_MODULE(_pyxacc, m) {
"Return the Compiler of given name.");
m.def("getIRPreprocessor", (std::shared_ptr<xacc::IRPreprocessor> (*)(const std::string&))
&xacc::getService<IRPreprocessor>, py::return_value_policy::reference,
"Return the Compiler of given name.");
"Return the IRPreprocessor of given name.");
m.def("getIRGenerator", (std::shared_ptr<xacc::IRGenerator> (*)(const std::string&))
&xacc::getService<IRGenerator>, py::return_value_policy::reference,
"Return the IRGenerator of given name.");
m.def("setOption", &xacc::setOption, "Set an XACC framework option.");
m.def("getOption", &xacc::getOption, "Get an XACC framework option.");
m.def("optionExists", &xacc::optionExists, "Set an XACC framework option.");
......@@ -223,6 +232,15 @@ PYBIND11_MODULE(_pyxacc, m) {
return xacc::getService<IRProvider>("gate")->createIR();
}, "Convenience function for creating a new GateIR.");
gatesub.def("getState",
[](std::shared_ptr<Accelerator> acc, std::shared_ptr<Function> f) -> Eigen::VectorXcd {
auto results = acc->getAcceleratorState(f);
for (auto r : results) {
std::cout << r << "\n";
}
return Eigen::Map<Eigen::VectorXcd>(results.data(), results.size());
}, "Compute and return the state after execution of the given program on the given accelerator.");
}
......@@ -149,7 +149,8 @@ public:
return allocatedBuffers[varid];
} else {
auto tmpBuffer = createBuffer(varid, 100);
XACCLogger::instance()->info("Could not find AcceleratorBuffer with id " + varid + ", creating one with 100 bits.");
XACCLogger::instance()->info("Could not find AcceleratorBuffer with id " +
varid + ", creating one with 100 bits.");
storeBuffer(varid, tmpBuffer);
return tmpBuffer;
}
......@@ -196,6 +197,19 @@ public:
return 0.0;
}
/**
* Return a representation of the state of the Accelerator after execution of
* the given program Function instance. For quantum computation this is
* the wave vector.
*
* This is meant to be overrided by subclasses.
*
* @param program The program to execute
* @return wf A list of complex coefficients
*/
virtual const std::vector<std::complex<double>> getAcceleratorState(std::shared_ptr<Function> program)
{ return std::vector<std::complex<double>>{}; }
/**
* Given user-input command line options, perform
* some operation. Returns true if runtime should exit,
......@@ -208,6 +222,11 @@ public:
return false;
}
/**
* Return true if this Accelerator is a remotely hosted resource.
*
* @return remote True if this is a remote Accelerator
*/
virtual bool isRemote() {
return false;
}
......
......@@ -46,6 +46,10 @@ public:
std::vector<InstructionParameter> parameters = std::vector<
InstructionParameter> { }) = 0;
virtual std::shared_ptr<Function> generate(
std::vector<InstructionParameter> parameters = std::vector<
InstructionParameter> { }) {return generate(nullptr,parameters);}
/**
* The destructor
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment