Skip to content

Commit

Permalink
Merge pull request #11 from wongey/bugfix/ionq
Browse files Browse the repository at this point in the history
Update IonQ plugin
  • Loading branch information
danclaudino authored Jun 25, 2024
2 parents 7b1cac0 + b240b76 commit c746af6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
5 changes: 4 additions & 1 deletion quantum/examples/base_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ add_executable(optimal_control_goat optimal_control_goat.cpp)
target_link_libraries(optimal_control_goat PRIVATE xacc)

add_executable(bell_azure bell_azure.cpp)
target_link_libraries(bell_azure PRIVATE xacc)
target_link_libraries(bell_azure PRIVATE xacc)

add_executable(bell_ionq bell_ionq.cpp)
target_link_libraries(bell_ionq PRIVATE xacc)
29 changes: 29 additions & 0 deletions quantum/examples/base_api/bell_ionq.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#include "xacc.hpp"

int main(int argc, char **argv) {
xacc::Initialize(argc, argv);

// Get reference to the Accelerator
auto accelerator = xacc::getAccelerator("ionq", {{"shots", 1024}});

// Allocate some qubits
auto buffer = xacc::qalloc(2);

xacc::qasm(R"(
.compiler xasm
.circuit ansatz
.qbit q
H(q[0]);
CX(q[0],q[1]);
Measure(q[0]);
Measure(q[1]);
)");
auto ansatz = xacc::getCompiled("ansatz");

accelerator->execute(buffer, ansatz);

xacc::Finalize();

return 0;
}
2 changes: 1 addition & 1 deletion quantum/plugins/honeywell/honeywell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class HoneywellAccelerator : public Accelerator {
int shots = 1024;
std::string backend = "";
bool initialized = false;
static inline const std::string url = "https://qapi.honeywell.com/v1/";
static inline const std::string url = "https://qapi.quantinuum.com/v1/";
// List of backend names:
std::vector<std::string> available_backends;
std::string post(const std::string &_url, const std::string &path,
Expand Down
14 changes: 9 additions & 5 deletions quantum/plugins/ionq/ionq_accelerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <regex>
#include <thread>

#include <iostream>

namespace xacc {
namespace quantum {

Expand All @@ -41,9 +43,10 @@ void IonQAccelerator::initialize(const HeterogeneousMap &params) {
headers.insert({"Authorization", "apiKey " + apiKey});
headers.insert({"Content-Type", "application/json"});

auto calibrations = restClient->get(url, "/calibrations", headers);
auto j = nlohmann::json::parse(calibrations);
m_connectivity = j["calibrations"][0]["connectivity"].get<std::vector<std::pair<int,int>>>();
auto characterizations = restClient->get(url, "/jobs", headers);
auto j = nlohmann::json::parse(characterizations);
// std::cout << j.dump(1) << std::endl;
// m_connectivity = j["characterizations"][0]["connectivity"].get<std::vector<std::pair<int,int>>>();

remoteUrl = url;
postPath = "/jobs";
Expand Down Expand Up @@ -144,8 +147,8 @@ void IonQAccelerator::processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
// End the color log
std::cout << "\033[0m" << "\n";

std::map<std::string, double> histogram =
j["data"]["histogram"].get<std::map<std::string, double>>();
auto results = handleExceptionRestClientGet(url, "/jobs/" + jobId + "/results", headers);
std::map<std::string, double> histogram = json::parse(results);

int n = buffer->size();
auto getBitStrForInt = [&](std::uint64_t i) {
Expand Down Expand Up @@ -217,3 +220,4 @@ void IonQAccelerator::findApiKeyInFile(std::string &apiKey, std::string &url,
}
} // namespace quantum
} // namespace xacc

5 changes: 3 additions & 2 deletions quantum/plugins/ionq/json/ionq_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ namespace nlohmann {
x.set_lang(j.at("lang").get<std::string>());
x.set_target(j.at("target").get<std::string>());
x.set_shots(j.at("shots").get<std::int64_t>());
x.set_body(j.at("body").get<xacc::ionq::Body>());
x.set_body(j.at("input").get<xacc::ionq::Body>());
}

inline void to_json(json & j, const xacc::ionq::IonQProgram & x) {
j = json::object();
j["lang"] = x.get_lang();
j["target"] = x.get_target();
j["shots"] = x.get_shots();
j["body"] = x.get_body();
j["input"] = x.get_body();
}
}

2 changes: 1 addition & 1 deletion quantum/plugins/ionq/tests/IonQProgramTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(IonQProgramTester, checkFromJson) {
"lang": "json",
"target": "qpu",
"shots": 1000,
"body": {
"input": {
"qubits": 2,
"circuit": [
{
Expand Down

0 comments on commit c746af6

Please sign in to comment.