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

adding decorator for ddcl to install


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent f375f9a5
Pipeline #75946 passed with stage
in 5 minutes and 7 seconds
......@@ -16,5 +16,5 @@ add_subdirectory(vqe-energy)
add_subdirectory(ml)
file(GLOB PYDECORATORS ${CMAKE_CURRENT_SOURCE_DIR}/vqe/python/*.py
${CMAKE_CURRENT_SOURCE_DIR}/vqe-energy/python/*.py
${CMAKE_CURRENT_SOURCE_DIR}/ddcl/python/*.py)
${CMAKE_CURRENT_SOURCE_DIR}/ml/ddcl/python/*.py)
install(FILES ${PYDECORATORS} DESTINATION ${CMAKE_INSTALL_PREFIX}/py-plugins)
......@@ -121,7 +121,12 @@ void DDCL::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
}
// The first child buffer is for the loss function
auto counts = buffers[0]->getMeasurementCounts();
Counts counts;
if (!buffers.empty()) {
counts = buffers[0]->getMeasurementCounts();
} else {
counts = tmpBuffer->getMeasurementCounts();
}
// Compute and return the loss, this gives us the
// distribution of the loss circuit too
......@@ -152,11 +157,14 @@ void DDCL::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
buffer->addExtraInfo("opt-val", ExtraInfo(result.first));
buffer->addExtraInfo("opt-params", ExtraInfo(result.second));
// FIXME write the buffer to file.
return;
}
std::vector<double> DDCL::execute(const std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<double> &x) {
std::vector<double>
DDCL::execute(const std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<double> &x) {
auto provider = xacc::getIRProvider("quantum");
// Evaluate and add measurements to all qubits
......@@ -188,8 +196,12 @@ std::vector<double> DDCL::execute(const std::shared_ptr<AcceleratorBuffer> buffe
auto buffers = tmpBuffer->getChildren();
// The first child buffer is for the loss function
auto counts = buffers[0]->getMeasurementCounts();
Counts counts;
if (!buffers.empty()) {
counts = buffers[0]->getMeasurementCounts();
} else {
counts = tmpBuffer->getMeasurementCounts();
}
// Compute and return the loss, this gives us the
// distribution of the loss circuit too
auto loss_and_qdist = lossStrategy->compute(counts, target_dist);
......
......@@ -314,6 +314,8 @@ void IBMAccelerator::processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
while (!jobCompleted) {
getResponse = handleExceptionRestClientGet(url, getPath);
// auto jj = json::parse(getResponse);
if (getResponse.find("COMPLETED") != std::string::npos) {
jobCompleted = true;
}
......@@ -352,6 +354,7 @@ void IBMAccelerator::processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
std::cout << std::endl;
// std::cout << "JOBRESPONSE:\n" << getResponse << "\n";
jobIsRunning = false;
currentJobId = "";
......@@ -359,7 +362,6 @@ void IBMAccelerator::processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
auto &qobjNode = d["qObject"];
auto &qobjResultNode = d["qObjectResult"];
StringBuffer sb, sb2;
Writer<StringBuffer> jsWriter(sb), jsWriter2(sb2);
qobjResultNode.Accept(jsWriter);
......@@ -373,7 +375,6 @@ void IBMAccelerator::processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
nlohmann::from_json(j, qobjResult);
nlohmann::json j2 = nlohmann::json::parse(qobjAsString);
nlohmann::from_json(j2, qobj);
auto resultsArray = qobjResult.get_results();
auto experiments = qobj.get_experiments();
......@@ -393,17 +394,14 @@ void IBMAccelerator::processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
}
for (int i = 0; i < resultsArray.size(); i++) {
auto currentExperiment = experiments[i];
auto tmpBuffer = std::make_shared<AcceleratorBuffer>(
currentExperiment.get_header().get_name(), buffer->size());
auto counts = resultsArray[i].get_data().get_counts();
for (auto &kv : counts) {
std::string hexStr = kv.first;
int nOccurrences = kv.second;
auto bitStr = hex_string_to_binary_string(hexStr);
if (resultsArray.size() == 1) {
......
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