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

fixing xasm fail when int or double literal is passed to quantum kernel


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 351f6f8b
......@@ -22,6 +22,19 @@
#include "Circuit.hpp"
TEST (XASMCompilerTester, checkQcorIssue23) {
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(R"(__qpu__ void rotate(qbit q, double x) {
Rx(q[0], x);
})");
auto IR2 = compiler->compile(R"(__qpu__ void check(qbit q) {
rotate(q, 2.2);
})");
std::cout << IR2->getComposite("check")->toString() << "\n";
}
TEST(XASMCompilerTester, checkU1) {
auto compiler = xacc::getCompiler("xasm");
......
......@@ -39,13 +39,14 @@ bool XASMCompiler::canParse(const std::string &src) {
std::stringstream ss;
ss << "XASM Cannot parse this source: " << msg << "\n";
ss << line << ": " << charPositionInLine << ", offending symbol = " << offendingSymbol->getText() << "\n";
xacc::info(ss.str());
// xacc::info(ss.str());
throw std::runtime_error("Cannot parse this XASM source string.");
}
};
ANTLRInputStream input(src);
xasmLexer lexer(&input);
lexer.removeErrorListeners();
CommonTokenStream tokens(&lexer);
xasmParser parser(&tokens);
parser.removeErrorListeners();
......@@ -63,6 +64,7 @@ std::shared_ptr<IR> XASMCompiler::compile(const std::string &src,
std::shared_ptr<Accelerator> acc) {
ANTLRInputStream input(src);
xasmLexer lexer(&input);
lexer.removeErrorListeners();
CommonTokenStream tokens(&lexer);
xasmParser parser(&tokens);
parser.removeErrorListeners();
......
......@@ -484,7 +484,7 @@ void XASMListener::enterParamList(xasmParser::ParamListContext *ctx) {
}
}
void XASMListener::exitInstruction(xasmParser::InstructionContext *ctx) {
void XASMListener::exitInstruction(xasmParser::InstructionContext *ctx) {
auto inst = irProvider->createInstruction(currentInstructionName, currentBits,
currentParameters);
......@@ -591,7 +591,7 @@ void XASMListener::enterOptionsType(xasmParser::OptionsTypeContext *ctx) {
if (isConstChar) {
currentOptions.insert(key, valStr.c_str());
} else {
currentOptions.insert(key,valStr);
currentOptions.insert(key, valStr);
}
} else {
......@@ -633,6 +633,7 @@ void XASMListener::exitComposite_generator(
auto composite = std::dynamic_pointer_cast<CompositeInstruction>(tmp);
for (int i = 0; i < currentParameters.size(); i++) {
auto p = currentParameters[i];
auto arg = function->getArgument(p.toString());
int vector_mapping = 0;
......@@ -648,6 +649,43 @@ void XASMListener::exitComposite_generator(
// give the instruction a mapping from i to vector idx
vector_mapping = new_var_to_vector_idx[currentParameters[i].toString()];
} else if (p.isNumeric()) {
if (!composite->getArguments().empty()) {
std::cout << "xasm debug: " << composite->getArguments().size()
<< "\n";
// This is a literal. Create an argument and add it
auto tmp_arg = composite->getArguments()[1];
if (tmp_arg->type == "double") {
tmp_arg->runtimeValue.insert(INTERNAL_ARGUMENT_VALUE_KEY,
p.as<double>());
} else if (tmp_arg->type == "int") {
tmp_arg->runtimeValue.insert(INTERNAL_ARGUMENT_VALUE_KEY,
p.as<int>());
} else {
xacc::error(
"xasm only support double and int literals in kernel calls.\n");
}
composite->applyRuntimeArguments();
} else {
// add an arg for this
// this is probably coming from QCOR
if (p.which() == 0) {
// integer
composite->addArgument("__xacc__literal_", "int");
auto tmp = composite->getArgument("__xacc__literal_");
tmp->runtimeValue.insert(INTERNAL_ARGUMENT_VALUE_KEY,
p.as<int>());
} else {
// double
composite->addArgument("__xacc__literal_", "double");
auto tmp = composite->getArgument("__xacc__literal_");
tmp->runtimeValue.insert(INTERNAL_ARGUMENT_VALUE_KEY,
p.as<double>());
}
}
continue;
} else {
// throw an error
xacc::error(
......
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