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

add getNativeCode to the qcs accelerator, move engagement to first time execute is called


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 4f161635
Pipeline #167181 passed with stage
in 12 minutes and 45 seconds
......@@ -92,6 +92,12 @@ result = str(np)
return;
}
std::string QCSAccelerator::getNativeCode(std::shared_ptr<CompositeInstruction> program,
const HeterogeneousMap &config) {
auto irt = xacc::getIRTransformation("qcs-quilc");
irt->apply(program, nullptr);
return program->toString();
}
void QCSAccelerator::execute(
std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<std::shared_ptr<CompositeInstruction>> functions) {
......@@ -151,8 +157,6 @@ void QCSAccelerator::initialize(const HeterogeneousMap &params) {
if (!guard && !Py_IsInitialized()) {
guard = std::make_shared<py::scoped_interpreter>();
// libpython_handle = dlopen("@PYTHON_LIB_NAME@", RTLD_LAZY |
// RTLD_GLOBAL);
initialized = true;
}
......@@ -184,6 +188,16 @@ void QCSAccelerator::_internal_init() {
endpoint = backend;
}
}
void QCSAccelerator::execute(
std::shared_ptr<AcceleratorBuffer> buffer,
const std::shared_ptr<CompositeInstruction> function) {
using json = nlohmann::json;
if (!engaged) {
// Do this one time if we want to execute
std::string json_data = "{\"endpointId\": \"" + endpoint + "\"}";
std::map<std::string, std::string> headers{
{"Content-Type", "application/json"},
......@@ -200,13 +214,9 @@ void QCSAccelerator::_internal_init() {
qpu_endpoint = resp_json["address"];
qpu_compiler_endpoint = qpu_compiler_url;
user_id = resp_json["userId"].get<std::string>();
}
void QCSAccelerator::execute(
std::shared_ptr<AcceleratorBuffer> buffer,
const std::shared_ptr<CompositeInstruction> function) {
engaged = true;
}
using json = nlohmann::json;
// Map IR to Native Quil string
auto visitor = std::make_shared<QuilVisitor>(true);
......
......@@ -108,6 +108,7 @@ protected:
bool use_rpcq_auth_config = true;
bool initialized = false;
bool engaged = false;
std::shared_ptr<py::scoped_interpreter> guard;
void _internal_init();
......@@ -122,6 +123,9 @@ public:
const std::vector<std::shared_ptr<CompositeInstruction>>
functions) override;
std::string getNativeCode(std::shared_ptr<CompositeInstruction> program,
const HeterogeneousMap &config) override;
void initialize(const HeterogeneousMap &params = {}) override;
void updateConfiguration(const HeterogeneousMap &config) override {
......
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