Commit 17ee51c4 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding Compiler to contributable services


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent c56c10fd
Pipeline #66119 passed with stage
in 6 minutes and 23 seconds
......@@ -25,7 +25,7 @@ buffer = xacc.qalloc(2)
irg2 = xacc.getIRGenerator('bell')
@xacc.qpu( accelerator=qpu)
@xacc.qpu(accelerator=qpu)
def function(buffer):
bell()
......
......@@ -133,6 +133,31 @@ public:
std::vector<InstructionParameter>{}) override { return nullptr;}
};
class PyCompiler : public xacc::Compiler {
public:
/* Inherit the constructors */
using Compiler::Compiler;
const std::string name() const override {
PYBIND11_OVERLOAD_PURE(const std::string, xacc::Compiler, name);
}
const std::string description() const override { return ""; }
std::shared_ptr<IR>
compile(const std::string& src, std::shared_ptr<Accelerator> acc) {
PYBIND11_OVERLOAD_PURE(std::shared_ptr<IR>, xacc::Compiler, compile, src, acc);
}
std::shared_ptr<IR> compile(const std::string &src) override {
return compile(src, nullptr);
}
const std::string translate(const std::string &bufferVariable,
std::shared_ptr<Function> function) override {
return "";
}
};
PYBIND11_MODULE(_pyxacc, m) {
m.doc() =
"Python bindings for XACC. XACC provides a plugin infrastructure for "
......@@ -353,10 +378,11 @@ PYBIND11_MODULE(_pyxacc, m) {
"");
// Expose the Compiler
py::class_<xacc::Compiler, std::shared_ptr<xacc::Compiler>>(
py::class_<xacc::Compiler, std::shared_ptr<xacc::Compiler>, PyCompiler>(
m, "Compiler",
"The XACC Compiler takes as input quantum kernel source code, "
"and compiles it to the XACC intermediate representation.")
.def(py::init<>(), "")
.def("name", &xacc::Compiler::name, "Return the name of this Compiler.")
.def("compile",
(std::shared_ptr<xacc::IR>(xacc::Compiler::*)(
......
......@@ -269,9 +269,13 @@ std::shared_ptr<Compiler> getCompiler(const std::string &name) {
error("XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
auto c = xacc::getService<Compiler>(name);
auto c = xacc::getService<Compiler>(name, false);
if (!c) {
error("Invalid Compiler. Could not find " + name + " in Service Registry.");
if (xacc::hasContributedService<Compiler>(name)) {
c = xacc::getContributedService<Compiler>(name);
} else {
error("Invalid Compiler. Could not find " + name + " in Service Registry.");
}
}
return c;
}
......
......@@ -40,8 +40,7 @@ using namespace cppmicroservices;
namespace xacc {
using ContributableService =
Variant<std::shared_ptr<IRGenerator>, std::shared_ptr<Accelerator>>;//,
// std::shared_ptr<Compiler>, std::shared_ptr<Algorithm>,
Variant<std::shared_ptr<IRGenerator>, std::shared_ptr<Accelerator>,std::shared_ptr<Compiler>>;//, std::shared_ptr<Algorithm>,
// std::shared_ptr<Optimizer>, std::shared_ptr<IRProvider>>;
/**
* The ServiceRegistry provides the plugin infrastructure for XACC.
......
Markdown is supported
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