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

updating the way readout errors are computed



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 2c694386
......@@ -294,8 +294,7 @@ PYBIND11_MODULE(_pyxacc, m) {
py::class_<xacc::AcceleratorDecorator, xacc::Accelerator,
std::shared_ptr<xacc::AcceleratorDecorator>>
accd(m, "AcceleratorDecorator", "");
accd
.def("setDecorated", &xacc::AcceleratorDecorator::setDecorated, "");
accd.def("setDecorated", &xacc::AcceleratorDecorator::setDecorated, "");
// Expose the AcceleratorBuffer
py::class_<xacc::AcceleratorBuffer, std::shared_ptr<xacc::AcceleratorBuffer>>(
......@@ -326,6 +325,11 @@ PYBIND11_MODULE(_pyxacc, m) {
xacc::AcceleratorBuffer::*)(const std::string)) &
xacc::AcceleratorBuffer::getChildren,
"")
.def("getChildren",
(std::vector<std::shared_ptr<AcceleratorBuffer>>(
xacc::AcceleratorBuffer::*)()) &
xacc::AcceleratorBuffer::getChildren,
"")
.def("getChildrenNames", &xacc::AcceleratorBuffer::getChildrenNames, "")
.def("listExtraInfoKeys", &xacc::AcceleratorBuffer::listExtraInfoKeys, "")
.def("getInformation",
......@@ -463,11 +467,12 @@ PYBIND11_MODULE(_pyxacc, m) {
xacc::setOption(kv.first, kv.second);
},
"Set a number of options at once.");
m.def("getAcceleratorDecorator", [](const std::string name, std::shared_ptr<Accelerator> acc) {
auto accd = xacc::getService<AcceleratorDecorator>(name);
accd->setDecorated(acc);
return accd;
});
m.def("getAcceleratorDecorator",
[](const std::string name, std::shared_ptr<Accelerator> acc) {
auto accd = xacc::getService<AcceleratorDecorator>(name);
accd->setDecorated(acc);
return accd;
});
m.def("setOptions",
[](std::map<std::string, InstructionParameter> options) {
for (auto &kv : options)
......
......@@ -13,7 +13,7 @@ namespace quantum {
void ROErrorDecorator::execute(std::shared_ptr<AcceleratorBuffer> buffer,
const std::shared_ptr<Function> function) {
decoratedAccelerator->execute(buffer, function);
if (decoratedAccelerator) decoratedAccelerator->execute(buffer, function);
if (!xacc::optionExists("ro-error-file")) {
xacc::info("Cannot find ro-error-file. Skipping ReadoutError "
......@@ -88,15 +88,22 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> ROErrorDecorator::execute(
std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<std::shared_ptr<Function>> functions) {
auto buffers = decoratedAccelerator->execute(buffer, functions);
// Goal here is take the resultant buffers and add a new
// ExtraInfo key, 'ro-fixed-exp-val-z'.
// To do this, we need to get the readout error fidelities
// from the user provided characterization file
// This will give us p(+-)_i and we can use that to shift the
// current exp-val-z values on the buffers.
std::vector<std::shared_ptr<AcceleratorBuffer>> buffers;
std::map<std::string,std::shared_ptr<Function>> nameToFunction;
std::map<std::string, std::set<int>> supportSets;
if (decoratedAccelerator) {
buffers = decoratedAccelerator->execute(buffer, functions);
} else {
buffers = buffer->getChildren();
}
if (!xacc::optionExists("ro-error-file")) {
xacc::info("Cannot find ro-error-file. Skipping ReadoutError "
"correction.");
return buffers;
}
auto supports = [](std::shared_ptr<Function> f) {
std::set<int> supportSet;
InstructionIterator it(f);
......@@ -111,12 +118,11 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> ROErrorDecorator::execute(
return supportSet;
};
if (!xacc::optionExists("ro-error-file")) {
xacc::info("Cannot find ro-error-file. Skipping ReadoutError "
"correction.");
return buffers;
for (auto& f : functions) {
nameToFunction.insert({f->name(), f});
supportSets.insert({f->name(), supports(f)});
}
// Get RO error probs
auto roeStr = xacc::getOption("ro-error-file");
buffer->addExtraInfo("ro-error-file", ExtraInfo(roeStr));
......@@ -149,13 +155,16 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> ROErrorDecorator::execute(
int counter = 0;
for (auto &b : buffers) {
auto counts = b->getMeasurementCounts();
auto functionName = b->name();
auto f = nameToFunction[functionName];
auto fSupports = supportSets[functionName];
auto fixedExp = 0.0;
for (auto &kv : counts) {
auto prod = 1.0;
std::string bitString = kv.first;
auto count = kv.second;
for (auto j : supports(functions[counter])) {
for (auto& j : fSupports) {
std::stringstream s;
auto denom = (1.0 - piplus[j]);
auto numerator =
......
......@@ -147,7 +147,15 @@ AcceleratorBuffer::getChildren(const std::string name) {
return childrenWithName;
}
std::vector<std::shared_ptr<AcceleratorBuffer>>
AcceleratorBuffer::getChildren() {
std::vector<std::shared_ptr<AcceleratorBuffer>> childrenReturn;
for (auto &child : children) {
childrenReturn.push_back(child.second);
}
return childrenReturn;
}
std::vector<std::string> AcceleratorBuffer::getChildrenNames() {
std::vector<std::string> names;
for (auto &child : children)
......
......@@ -120,6 +120,7 @@ public:
std::shared_ptr<AcceleratorBuffer> buffer);
std::vector<std::shared_ptr<AcceleratorBuffer>>
getChildren(const std::string name);
std::vector<std::shared_ptr<AcceleratorBuffer>> getChildren();
std::vector<std::string> getChildrenNames();
void addExtraInfo(const std::string infoName, ExtraInfo i);
......
Supports Markdown
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