Commit 7f3f4fb8 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

deleting pointers to error listeners in compilers


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 1da60b21
Pipeline #63209 passed with stages
in 10 minutes and 33 seconds
......@@ -27,16 +27,19 @@ namespace quantum {
std::shared_ptr<IR> PyXACCCompiler::compile(const std::string &src,
std::shared_ptr<Accelerator> acc) {
auto e1 = new PyXACCErrorListener();
auto e2 = new PyXACCErrorListener();
// Setup the Antlr Parser
ANTLRInputStream input(src);
PyXACCIRLexer lexer(&input);
lexer.removeErrorListeners();
lexer.addErrorListener(new PyXACCErrorListener());
lexer.addErrorListener(e1);
CommonTokenStream tokens(&lexer);
PyXACCIRParser parser(&tokens);
parser.removeErrorListeners();
parser.addErrorListener(new PyXACCErrorListener());
parser.addErrorListener(e2);
// Walk the Abstract Syntax Tree
tree::ParseTree *tree = parser.xaccsrc();
......@@ -51,6 +54,9 @@ std::shared_ptr<IR> PyXACCCompiler::compile(const std::string &src,
auto ir = std::make_shared<GateIR>();
ir->addKernel(listener.getKernel());
delete e1;
delete e2;
return ir;
}
......
......@@ -46,29 +46,30 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string &src,
std::shared_ptr<Accelerator> acc) {
auto hardwareconnections = acc->getAcceleratorConnectivity();
std::set<int> nUniqueBits;
for (auto& edge : hardwareconnections) {
nUniqueBits.insert(edge.first);
nUniqueBits.insert(edge.second);
}
int nBits = *std::max_element(nUniqueBits.begin(), nUniqueBits.end()) + 1;
auto hardwareGraph = xacc::getService<Graph>("boost-ugraph");
for (int i = 0; i < nBits; i++) {
std::map<std::string,InstructionParameter> m{{"bias",1.0}};
hardwareGraph->addVertex(m);
}
for (auto& edge : hardwareconnections) {
hardwareGraph->addEdge(edge.first, edge.second);
}
std::set<int> nUniqueBits;
for (auto &edge : hardwareconnections) {
nUniqueBits.insert(edge.first);
nUniqueBits.insert(edge.second);
}
int nBits = *std::max_element(nUniqueBits.begin(), nUniqueBits.end()) + 1;
auto hardwareGraph = xacc::getService<Graph>("boost-ugraph");
for (int i = 0; i < nBits; i++) {
std::map<std::string, InstructionParameter> m{{"bias", 1.0}};
hardwareGraph->addVertex(m);
}
for (auto &edge : hardwareconnections) {
hardwareGraph->addEdge(edge.first, edge.second);
}
auto e = new DWQMIErrorListener();
ANTLRInputStream input(src);
DWQMILexer lexer(&input);
CommonTokenStream tokens(&lexer);
DWQMIParser parser(&tokens);
parser.removeErrorListeners();
parser.addErrorListener(new DWQMIErrorListener());
parser.addErrorListener(e);
auto ir(std::make_shared<DWIR>());
......@@ -76,17 +77,13 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string &src,
// of qubits for the D-Wave -- all of them.
auto bufName = acc->getAllocatedBufferNames()[0];
auto buffer = acc->getBuffer(bufName);
// std::shared_ptr<AQCAcceleratorBuffer> aqcBuffer =
// std::dynamic_pointer_cast<AQCAcceleratorBuffer>(buffer);
// if (!aqcBuffer) {
// xacc::error("Invalid AcceleratorBuffer passed to DW QMI Compiler. Must be "
// "an AQCAcceleratorBuffer.");
// }
tree::ParseTree *tree = parser.xaccsrc();
DWQMIListener listener(ir, hardwareGraph, buffer);
tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
delete e;
return ir;
}
......@@ -117,8 +114,7 @@ const std::string DWQMICompiler::translate(const std::string &bufferVariable,
auto bits = inst->bits();
auto param = inst->getParameter(0);
std::stringstream s;
s << " " << bits[0] << " " << bits[1] << " "
<< param.toString() << ";\n";
s << " " << bits[0] << " " << bits[1] << " " << param.toString() << ";\n";
src += s.str();
}
src += "}";
......
......@@ -101,19 +101,19 @@ public:
*
* @return options Description of command line options.
*/
OptionPairs getOptions() override {
OptionPairs desc{{"dwave-embedding",
"Provide the name of the Embedding Algorithm to use "
"during compilation."},{
"dwave-parameter-setter",
"Provide the name of the "
"ParameterSetter to map logical parameters to physical parameters."},{
"dwave-load-embedding",
"Use the embedding in the given file."},{
"dwave-persist-embedding",
"Persist the computed embedding to the given file name."},{
"dwave-list-embedding-algorithms",
"List all available embedding algorithms."}};
OptionPairs getOptions() override {
OptionPairs desc{
{"dwave-embedding",
"Provide the name of the Embedding Algorithm to use "
"during compilation."},
{"dwave-parameter-setter",
"Provide the name of the "
"ParameterSetter to map logical parameters to physical parameters."},
{"dwave-load-embedding", "Use the embedding in the given file."},
{"dwave-persist-embedding",
"Persist the computed embedding to the given file name."},
{"dwave-list-embedding-algorithms",
"List all available embedding algorithms."}};
return desc;
}
......
......@@ -61,7 +61,8 @@ std::shared_ptr<IR> OQASMCompiler::compile(const std::string &src) {
CommonTokenStream tokens(&lexer);
OQASM2Parser parser(&tokens);
parser.removeErrorListeners();
parser.addErrorListener(new OQASMErrorListener());
auto e = new OQASMErrorListener;
parser.addErrorListener(e);
auto ir = xacc::getService<IRProvider>("gate")->createIR();
......@@ -69,6 +70,7 @@ std::shared_ptr<IR> OQASMCompiler::compile(const std::string &src) {
OQASMToXACCListener listener(ir);
tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
delete e;
return ir;
}
......
......@@ -60,7 +60,8 @@ std::shared_ptr<IR> QuilCompiler::compile(const std::string &src) {
CommonTokenStream tokens(&lexer);
QuilParser parser(&tokens);
parser.removeErrorListeners();
parser.addErrorListener(new QuilErrorListener());
auto e = new QuilErrorListener();
parser.addErrorListener(e);
auto ir = xacc::getService<IRProvider>("gate")->createIR();
......@@ -68,6 +69,7 @@ std::shared_ptr<IR> QuilCompiler::compile(const std::string &src) {
QuilToXACCListener listener(ir);
tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
delete e;
return ir;
}
......
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