Commit 99920c0a authored by Nguyen, Thien's avatar Nguyen, Thien
Browse files

getNativeCode qasm gen to handle if statement


Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent 27a79414
......@@ -1267,22 +1267,41 @@ IBMAccelerator::getNativeCode(std::shared_ptr<CompositeInstruction> program,
const auto gateSet = (xacc::container::contains(basis_gates, "u3"))
? QObjectExperimentVisitor::GateSet::U_CX
: QObjectExperimentVisitor::GateSet::RZ_SX_CX;
auto visitor = std::make_shared<QObjectExperimentVisitor>(
program->name(), program->nLogicalBits(), gateSet);
std::stringstream ss;
InstructionIterator it(program);
int memSlots = 0;
while (it.hasNext()) {
auto nextInst = it.next();
if (nextInst->isEnabled()) {
if (nextInst->isEnabled() && !nextInst->isComposite()) {
auto visitor = std::make_shared<QObjectExperimentVisitor>(
program->name(), program->nLogicalBits(), gateSet);
nextInst->accept(visitor);
auto experiment = visitor->getExperiment();
for (auto &inst : experiment.get_instructions()) {
// std::cout << "HOWDY: " << inst.toString() << "\n";
ss << inst.toString() << "\n";
}
} else if (nextInst->name() == "ifstmt") {
auto ifStmt =
std::dynamic_pointer_cast<xacc::CompositeInstruction>(nextInst);
ss << "if (c[" << nextInst->bits()[0] << "] == 1){\n";
if (ifStmt) {
for (auto &i : ifStmt->getInstructions()) {
auto visitor = std::make_shared<QObjectExperimentVisitor>(
program->name(), program->nLogicalBits(), gateSet);
i->accept(visitor);
auto experiment = visitor->getExperiment();
for (auto &inst : experiment.get_instructions()) {
// std::cout << "HOWDY: " << inst.toString() << "\n";
ss << inst.toString() << "\n";
}
}
}
ss << "}\n";
}
}
auto experiment = visitor->getExperiment();
std::stringstream ss;
for (auto &inst : experiment.get_instructions()) {
// std::cout << "HOWDY: " << inst.toString() << "\n";
ss << inst.toString() << "\n";
}
return ss.str();
}
xacc::error("Unknown native code format '" + format + "'");
......
......@@ -413,8 +413,15 @@ public:
}
ss << ")";
}
for (const auto &qb : qubits) {
ss << " q[" << qb << "]";
for (int i = 0; i < qubits.size(); ++i) {
ss << " q[" << qubits[i] << "]";
if (i != qubits.size() - 1) {
ss << ", ";
}
}
if (!get_memory().empty()) {
ss << " -> c[" << get_memory()[0] << "]";
}
ss << ";";
return ss.str();
......
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