Skip to content

Commit

Permalink
Merge pull request #33 from sethrj/fix-json
Browse files Browse the repository at this point in the history
Update JSON version and add code to diagnose Honeywell failure
  • Loading branch information
sethrj authored Aug 8, 2024
2 parents d252ce2 + 8303746 commit ef919eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ endif()

set(NLOHMANN_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/tpls/nlohmann/single_include)
if (XACC_DEPS_EXTERNAL)
find_package(nlohmann_json 3.1)
find_package(nlohmann_json)
if (nlohmann_json_FOUND)
get_target_property(NLOHMANN_TARGET_INC_DIR nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)
list(GET NLOHMANN_TARGET_INC_DIR 0 NLOHMANN_TARGET_INC_DIR)
Expand Down
25 changes: 22 additions & 3 deletions quantum/plugins/honeywell/honeywell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,25 @@ void HoneywellAccelerator::execute(
if (!retrieve_job_id.empty()) {

get_job_status = get(url, "job/" + retrieve_job_id, headers);
get_job_status_json = nlohmann::json::parse(get_job_status);
try {
get_job_status_json = nlohmann::json::parse(get_job_status);
} catch (nlohmann::json::exception const &) {
std::cout << "Failed to parse response '" << get_job_status
<< "' from job status " << retrieve_job_id << std::endl;
throw;
}

} else {

auto response = post(url, "job", j.dump(), headers);
auto response_json = nlohmann::json::parse(response);
nlohmann::json response_json;
try {
response_json = nlohmann::json::parse(response);
} catch (nlohmann::json::exception const &) {
std::cout << "Failed to parse response '" << response << "' from job"
<< std::endl;
throw;
}
auto job_id = response_json["job"].get<std::string>();

xacc::info("Honeywell job-id: " + job_id);
Expand All @@ -237,7 +250,13 @@ void HoneywellAccelerator::execute(
int dots = 1;
while (true) {
get_job_status = get(url, "job/" + job_id, headers);
get_job_status_json = nlohmann::json::parse(get_job_status);
try {
get_job_status_json = nlohmann::json::parse(get_job_status);
} catch (nlohmann::json::exception const &) {
std::cout << "Failed to parse response '" << get_job_status
<< "' from job status " << job_id << std::endl;
throw;
}

if (get_job_status_json["status"].get<std::string>().find("failed") !=
std::string::npos) {
Expand Down

0 comments on commit ef919eb

Please sign in to comment.