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) ...@@ -92,6 +92,12 @@ result = str(np)
return; 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( void QCSAccelerator::execute(
std::shared_ptr<AcceleratorBuffer> buffer, std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<std::shared_ptr<CompositeInstruction>> functions) { const std::vector<std::shared_ptr<CompositeInstruction>> functions) {
...@@ -151,8 +157,6 @@ void QCSAccelerator::initialize(const HeterogeneousMap &params) { ...@@ -151,8 +157,6 @@ void QCSAccelerator::initialize(const HeterogeneousMap &params) {
if (!guard && !Py_IsInitialized()) { if (!guard && !Py_IsInitialized()) {
guard = std::make_shared<py::scoped_interpreter>(); guard = std::make_shared<py::scoped_interpreter>();
// libpython_handle = dlopen("@PYTHON_LIB_NAME@", RTLD_LAZY |
// RTLD_GLOBAL);
initialized = true; initialized = true;
} }
...@@ -184,22 +188,6 @@ void QCSAccelerator::_internal_init() { ...@@ -184,22 +188,6 @@ void QCSAccelerator::_internal_init() {
endpoint = backend; endpoint = backend;
} }
std::string json_data = "{\"endpointId\": \"" + endpoint + "\"}";
std::map<std::string, std::string> headers{
{"Content-Type", "application/json"},
{"Connection", "keep-alive"},
{"Content-Length", std::to_string(json_data.length())},
{"Authorization", "Bearer " + auth_token}};
auto resp = this->post(engagement_url, "/engagements", json_data, headers);
auto resp_json = json::parse(resp);
client_public = resp_json["credentials"]["clientPublic"].get<std::string>();
client_secret = resp_json["credentials"]["clientSecret"].get<std::string>();
server_public = resp_json["credentials"]["serverPublic"].get<std::string>();
qpu_endpoint = resp_json["address"];
qpu_compiler_endpoint = qpu_compiler_url;
user_id = resp_json["userId"].get<std::string>();
} }
void QCSAccelerator::execute( void QCSAccelerator::execute(
...@@ -208,6 +196,28 @@ void QCSAccelerator::execute( ...@@ -208,6 +196,28 @@ void QCSAccelerator::execute(
using json = nlohmann::json; 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"},
{"Connection", "keep-alive"},
{"Content-Length", std::to_string(json_data.length())},
{"Authorization", "Bearer " + auth_token}};
auto resp = this->post(engagement_url, "/engagements", json_data, headers);
auto resp_json = json::parse(resp);
client_public = resp_json["credentials"]["clientPublic"].get<std::string>();
client_secret = resp_json["credentials"]["clientSecret"].get<std::string>();
server_public = resp_json["credentials"]["serverPublic"].get<std::string>();
qpu_endpoint = resp_json["address"];
qpu_compiler_endpoint = qpu_compiler_url;
user_id = resp_json["userId"].get<std::string>();
engaged = true;
}
// Map IR to Native Quil string // Map IR to Native Quil string
auto visitor = std::make_shared<QuilVisitor>(true); auto visitor = std::make_shared<QuilVisitor>(true);
InstructionIterator it(function); InstructionIterator it(function);
......
...@@ -108,6 +108,7 @@ protected: ...@@ -108,6 +108,7 @@ protected:
bool use_rpcq_auth_config = true; bool use_rpcq_auth_config = true;
bool initialized = false; bool initialized = false;
bool engaged = false;
std::shared_ptr<py::scoped_interpreter> guard; std::shared_ptr<py::scoped_interpreter> guard;
void _internal_init(); void _internal_init();
...@@ -122,6 +123,9 @@ public: ...@@ -122,6 +123,9 @@ public:
const std::vector<std::shared_ptr<CompositeInstruction>> const std::vector<std::shared_ptr<CompositeInstruction>>
functions) override; functions) override;
std::string getNativeCode(std::shared_ptr<CompositeInstruction> program,
const HeterogeneousMap &config) override;
void initialize(const HeterogeneousMap &params = {}) override; void initialize(const HeterogeneousMap &params = {}) override;
void updateConfiguration(const HeterogeneousMap &config) 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