Commit 81c5f7d4 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixing bug where Gate buffer_names was empty, but getBufferName was called - just return 'q'


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 645a8b5b
Pipeline #86908 passed with stage
in 4 minutes and 13 seconds
......@@ -13,6 +13,7 @@
#include "py_ir.hpp"
#include "CompositeInstruction.hpp"
#include "IRTransformation.hpp"
#include "heterogeneous.hpp"
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "InstructionIterator.hpp"
......@@ -91,6 +92,17 @@ void bind_ir(py::module &m) {
"")
.def("getVariables", &xacc::CompositeInstruction::getVariables, "")
.def("expand", &xacc::CompositeInstruction::expand, "")
.def(
"expand",
[](xacc::CompositeInstruction &c, PyHeterogeneousMap &options) {
xacc::HeterogeneousMap m;
for (auto &item : options) {
PyHeterogeneousMap2HeterogeneousMap vis(m, item.first);
mpark::visit(vis, item.second);
}
return c.expand(m);
},
"")
.def("eval", &xacc::CompositeInstruction::operator(), "")
.def("name", &xacc::CompositeInstruction::name, "")
.def("description", &xacc::CompositeInstruction::description, "")
......@@ -171,14 +183,13 @@ void bind_ir(py::module &m) {
"")
.def(
"createComposite",
[](IRProvider &p, const std::string name, std::vector<std::string> vars, const std::string type) {
[](IRProvider &p, const std::string name,
std::vector<std::string> vars, const std::string type) {
return p.createComposite(name, vars, type);
},
"")
.def("createIR",[](IRProvider &p) {
return p.createIR();
},
"") ;
.def(
"createIR", [](IRProvider &p) { return p.createIR(); }, "");
// Expose the IR interface
py::class_<xacc::IR, std::shared_ptr<xacc::IR>>(
......
......@@ -36,18 +36,16 @@ const std::string Gate::description() const {
}
std::string Gate::getBufferName(const std::size_t bitIdx) {
// if (!xacc::container::contains(bits(), bitIdx)) {
// xacc::error("Invalid bit index for getBufferName: " + name() + ", " + std::to_string(bitIdx));
// }
// auto idx = std::distance(qbits.begin(), std::find(qbits.begin(), qbits.end(), bitIdx));
return buffer_names[bitIdx];
}
void Gate::setBufferNames(const std::vector<std::string> bufferNamesPerIdx) {
if (bufferNamesPerIdx.size() != this->nRequiredBits()) {
xacc::error("Invalid number of buffer names for this instruction: " +name() + ", " + std::to_string(bufferNamesPerIdx.size()));
}
buffer_names = bufferNamesPerIdx;
return bitIdx < buffer_names.size() ? buffer_names[bitIdx] : "q";
}
void Gate::setBufferNames(const std::vector<std::string> bufferNamesPerIdx) {
if (bufferNamesPerIdx.size() != this->nRequiredBits()) {
xacc::error("Invalid number of buffer names for this instruction: " +name() + ", " + std::to_string(bufferNamesPerIdx.size()));
}
buffer_names = bufferNamesPerIdx;
}
const std::vector<std::size_t> Gate::bits() { return qbits; }
void Gate::mapBits(std::vector<std::size_t> bitMap) {
......
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