Commit 38782d65 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fixed a regression bug due to direct Staq IR translation



I was making sure that we only handle the case whereby there is only one qreg but didn't handle the case where the buffer name is different from the default "q".

Tested by: running qcor tests.

Signed-off-by: Nguyen, Thien Minh's avatarThien Nguyen <nguyentm@ornl.gov>
parent 0d4e36f7
...@@ -250,7 +250,7 @@ std::shared_ptr<IR> StaqCompiler::compile(const std::string &src, ...@@ -250,7 +250,7 @@ std::shared_ptr<IR> StaqCompiler::compile(const std::string &src,
} }
// Direct translation // Direct translation
internal_staq::StaqToIr translate(name); internal_staq::StaqToIr translate(name, countQreq.qregs[0]);
translate.visit(*prog); translate.visit(*prog);
return translate.getIr(); return translate.getIr();
} }
......
...@@ -167,8 +167,8 @@ public: ...@@ -167,8 +167,8 @@ public:
// Staq AST to XACC IR // Staq AST to XACC IR
class StaqToIr : public staq::ast::Visitor { class StaqToIr : public staq::ast::Visitor {
public: public:
StaqToIr(const std::string &in_kernelName) StaqToIr(const std::string &in_kernelName, const std::string &in_regName)
: m_kernelName(in_kernelName), m_provider(xacc::getIRProvider("quantum")) {} : m_kernelName(in_kernelName), m_regName(in_regName), m_provider(xacc::getIRProvider("quantum")) {}
void visit(VarAccess &) override {} void visit(VarAccess &) override {}
// Expressions // Expressions
void visit(BExpr &) override {} void visit(BExpr &) override {}
...@@ -233,6 +233,11 @@ public: ...@@ -233,6 +233,11 @@ public:
std::shared_ptr<IR> getIr() { std::shared_ptr<IR> getIr() {
auto composite = auto composite =
xacc::getService<IRProvider>("quantum")->createComposite(m_kernelName); xacc::getService<IRProvider>("quantum")->createComposite(m_kernelName);
composite->setBufferNames({m_regName});
for (auto &gate: m_runtimeInsts) {
std::vector regNames(gate->bits().size(), m_regName);
gate->setBufferNames(regNames);
}
// Since the instructions were *compiled* by staq (valid AST), // Since the instructions were *compiled* by staq (valid AST),
// hence, we skip all validation. // hence, we skip all validation.
composite->addInstructions(std::move(m_runtimeInsts), false); composite->addInstructions(std::move(m_runtimeInsts), false);
...@@ -245,6 +250,7 @@ private: ...@@ -245,6 +250,7 @@ private:
std::vector<InstPtr> m_runtimeInsts; std::vector<InstPtr> m_runtimeInsts;
std::shared_ptr<IRProvider> m_provider; std::shared_ptr<IRProvider> m_provider;
std::string m_kernelName; std::string m_kernelName;
std::string m_regName;
}; };
using namespace xacc::quantum; using namespace xacc::quantum;
......
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