Commit 2c694386 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Adding AcceleratorDecorator and ROErrorDecorator readout error mitigation



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 025f8e66
......@@ -226,25 +226,27 @@ void PyXACCListener::enterAllbitsOp(PyXACCIRParser::AllbitsOpContext *ctx) {
auto isRotation = [](const std::string &name) {
return name == "Rx" || name == "Ry" || name == "Rz";
};
if (gateName == "CNOT" || gateName == "CZ" || gateName == "Measure" ||
isRotation(gateName)) {
xacc::error(
"Cannot use ellipses '...' for 2 qubit gates, Measure, or rotation gates.");
xacc::error("Cannot use ellipses '...' for 2 qubit gates, Measure, or "
"rotation gates.");
}
auto buff = accelerator->getBuffer(bufferName);
auto nQubits = buff->size();
int start = 0, end = nQubits-1;
int start = 0, end = nQubits - 1;
if (ctx->INT().size() == 1) {
xacc::error("You cannot specify GATE(INT ...) or GATE(...INT). Only "
"GATE(...) or GATE(INT...INT).");
} else if (ctx->INT().size() == 2) {
start = std::stoi(ctx->INT(0)->getText());
end = std::stoi(ctx->INT(1)->getText());
if (end >= nQubits) xacc::error("Invalid qubit indices for ellipses. Must be [start,end] (end inclusive)");
if (end >= nQubits)
xacc::error("Invalid qubit indices for ellipses. Must be [start,end] "
"(end inclusive)");
} else if (!ctx->INT().empty()) {
xacc::error("Invalid use of ellipses: " + ctx->getText());
xacc::error("Invalid use of ellipses: " + ctx->getText());
}
std::cout << "HELLO: " << start << ", " << end << ", " << nQubits << "\n";
......
......@@ -57,7 +57,6 @@ public:
virtual void enterUop(PyXACCIRParser::UopContext * /*ctx*/) override;
virtual void
enterAllbitsOp(PyXACCIRParser::AllbitsOpContext * /*ctx*/) override;
};
} // namespace quantum
......
// Generated from PyXACCIR.g4 by ANTLR 4.7.1
#include "PyXACCIRBaseListener.h"
using namespace pyxacc;
......@@ -3,84 +3,95 @@
#pragma once
#include "antlr4-runtime.h"
#include "PyXACCIRListener.h"
namespace pyxacc {
/**
* This class provides an empty implementation of PyXACCIRListener,
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
* which can be extended to create a listener which only needs to handle a
* subset of the available methods.
*/
class PyXACCIRBaseListener : public PyXACCIRListener {
class PyXACCIRBaseListener : public PyXACCIRListener {
public:
virtual void enterXaccsrc(PyXACCIRParser::XaccsrcContext * /*ctx*/) override {
}
virtual void exitXaccsrc(PyXACCIRParser::XaccsrcContext * /*ctx*/) override {}
virtual void enterXaccsrc(PyXACCIRParser::XaccsrcContext * /*ctx*/) override { }
virtual void exitXaccsrc(PyXACCIRParser::XaccsrcContext * /*ctx*/) override { }
virtual void enterXacckernel(PyXACCIRParser::XacckernelContext * /*ctx*/) override { }
virtual void exitXacckernel(PyXACCIRParser::XacckernelContext * /*ctx*/) override { }
virtual void enterMainprog(PyXACCIRParser::MainprogContext * /*ctx*/) override { }
virtual void exitMainprog(PyXACCIRParser::MainprogContext * /*ctx*/) override { }
virtual void enterProgram(PyXACCIRParser::ProgramContext * /*ctx*/) override { }
virtual void exitProgram(PyXACCIRParser::ProgramContext * /*ctx*/) override { }
virtual void
enterXacckernel(PyXACCIRParser::XacckernelContext * /*ctx*/) override {}
virtual void
exitXacckernel(PyXACCIRParser::XacckernelContext * /*ctx*/) override {}
virtual void enterLine(PyXACCIRParser::LineContext * /*ctx*/) override { }
virtual void exitLine(PyXACCIRParser::LineContext * /*ctx*/) override { }
virtual void
enterMainprog(PyXACCIRParser::MainprogContext * /*ctx*/) override {}
virtual void
exitMainprog(PyXACCIRParser::MainprogContext * /*ctx*/) override {}
virtual void enterStatement(PyXACCIRParser::StatementContext * /*ctx*/) override { }
virtual void exitStatement(PyXACCIRParser::StatementContext * /*ctx*/) override { }
virtual void enterProgram(PyXACCIRParser::ProgramContext * /*ctx*/) override {
}
virtual void exitProgram(PyXACCIRParser::ProgramContext * /*ctx*/) override {}
virtual void enterComment(PyXACCIRParser::CommentContext * /*ctx*/) override { }
virtual void exitComment(PyXACCIRParser::CommentContext * /*ctx*/) override { }
virtual void enterLine(PyXACCIRParser::LineContext * /*ctx*/) override {}
virtual void exitLine(PyXACCIRParser::LineContext * /*ctx*/) override {}
virtual void enterParamlist(PyXACCIRParser::ParamlistContext * /*ctx*/) override { }
virtual void exitParamlist(PyXACCIRParser::ParamlistContext * /*ctx*/) override { }
virtual void
enterStatement(PyXACCIRParser::StatementContext * /*ctx*/) override {}
virtual void
exitStatement(PyXACCIRParser::StatementContext * /*ctx*/) override {}
virtual void enterParam(PyXACCIRParser::ParamContext * /*ctx*/) override { }
virtual void exitParam(PyXACCIRParser::ParamContext * /*ctx*/) override { }
virtual void enterComment(PyXACCIRParser::CommentContext * /*ctx*/) override {
}
virtual void exitComment(PyXACCIRParser::CommentContext * /*ctx*/) override {}
virtual void enterUop(PyXACCIRParser::UopContext * /*ctx*/) override { }
virtual void exitUop(PyXACCIRParser::UopContext * /*ctx*/) override { }
virtual void
enterParamlist(PyXACCIRParser::ParamlistContext * /*ctx*/) override {}
virtual void
exitParamlist(PyXACCIRParser::ParamlistContext * /*ctx*/) override {}
virtual void enterAllbitsOp(PyXACCIRParser::AllbitsOpContext * /*ctx*/) override { }
virtual void exitAllbitsOp(PyXACCIRParser::AllbitsOpContext * /*ctx*/) override { }
virtual void enterParam(PyXACCIRParser::ParamContext * /*ctx*/) override {}
virtual void exitParam(PyXACCIRParser::ParamContext * /*ctx*/) override {}
virtual void enterGate(PyXACCIRParser::GateContext * /*ctx*/) override { }
virtual void exitGate(PyXACCIRParser::GateContext * /*ctx*/) override { }
virtual void enterUop(PyXACCIRParser::UopContext * /*ctx*/) override {}
virtual void exitUop(PyXACCIRParser::UopContext * /*ctx*/) override {}
virtual void enterExplist(PyXACCIRParser::ExplistContext * /*ctx*/) override { }
virtual void exitExplist(PyXACCIRParser::ExplistContext * /*ctx*/) override { }
virtual void
enterAllbitsOp(PyXACCIRParser::AllbitsOpContext * /*ctx*/) override {}
virtual void
exitAllbitsOp(PyXACCIRParser::AllbitsOpContext * /*ctx*/) override {}
virtual void enterExp(PyXACCIRParser::ExpContext * /*ctx*/) override { }
virtual void exitExp(PyXACCIRParser::ExpContext * /*ctx*/) override { }
virtual void enterGate(PyXACCIRParser::GateContext * /*ctx*/) override {}
virtual void exitGate(PyXACCIRParser::GateContext * /*ctx*/) override {}
virtual void enterCoupler(PyXACCIRParser::CouplerContext * /*ctx*/) override { }
virtual void exitCoupler(PyXACCIRParser::CouplerContext * /*ctx*/) override { }
virtual void enterExplist(PyXACCIRParser::ExplistContext * /*ctx*/) override {
}
virtual void exitExplist(PyXACCIRParser::ExplistContext * /*ctx*/) override {}
virtual void enterUnaryop(PyXACCIRParser::UnaryopContext * /*ctx*/) override { }
virtual void exitUnaryop(PyXACCIRParser::UnaryopContext * /*ctx*/) override { }
virtual void enterExp(PyXACCIRParser::ExpContext * /*ctx*/) override {}
virtual void exitExp(PyXACCIRParser::ExpContext * /*ctx*/) override {}
virtual void enterId(PyXACCIRParser::IdContext * /*ctx*/) override { }
virtual void exitId(PyXACCIRParser::IdContext * /*ctx*/) override { }
virtual void enterCoupler(PyXACCIRParser::CouplerContext * /*ctx*/) override {
}
virtual void exitCoupler(PyXACCIRParser::CouplerContext * /*ctx*/) override {}
virtual void enterReal(PyXACCIRParser::RealContext * /*ctx*/) override { }
virtual void exitReal(PyXACCIRParser::RealContext * /*ctx*/) override { }
virtual void enterUnaryop(PyXACCIRParser::UnaryopContext * /*ctx*/) override {
}
virtual void exitUnaryop(PyXACCIRParser::UnaryopContext * /*ctx*/) override {}
virtual void enterString(PyXACCIRParser::StringContext * /*ctx*/) override { }
virtual void exitString(PyXACCIRParser::StringContext * /*ctx*/) override { }
virtual void enterId(PyXACCIRParser::IdContext * /*ctx*/) override {}
virtual void exitId(PyXACCIRParser::IdContext * /*ctx*/) override {}
virtual void enterReal(PyXACCIRParser::RealContext * /*ctx*/) override {}
virtual void exitReal(PyXACCIRParser::RealContext * /*ctx*/) override {}
virtual void enterEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { }
virtual void exitEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { }
virtual void visitTerminal(antlr4::tree::TerminalNode * /*node*/) override { }
virtual void visitErrorNode(antlr4::tree::ErrorNode * /*node*/) override { }
virtual void enterString(PyXACCIRParser::StringContext * /*ctx*/) override {}
virtual void exitString(PyXACCIRParser::StringContext * /*ctx*/) override {}
virtual void enterEveryRule(antlr4::ParserRuleContext * /*ctx*/) override {}
virtual void exitEveryRule(antlr4::ParserRuleContext * /*ctx*/) override {}
virtual void visitTerminal(antlr4::tree::TerminalNode * /*node*/) override {}
virtual void visitErrorNode(antlr4::tree::ErrorNode * /*node*/) override {}
};
} // namespace pyxacc
} // namespace pyxacc
This diff is collapsed.
......@@ -3,39 +3,77 @@
#pragma once
#include "antlr4-runtime.h"
namespace pyxacc {
class PyXACCIRLexer : public antlr4::Lexer {
class PyXACCIRLexer : public antlr4::Lexer {
public:
enum {
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7,
T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14,
T__14 = 15, T__15 = 16, T__16 = 17, T__17 = 18, T__18 = 19, T__19 = 20,
T__20 = 21, T__21 = 22, T__22 = 23, T__23 = 24, T__24 = 25, T__25 = 26,
T__26 = 27, T__27 = 28, T__28 = 29, T__29 = 30, T__30 = 31, T__31 = 32,
T__32 = 33, T__33 = 34, T__34 = 35, T__35 = 36, T__36 = 37, T__37 = 38,
T__38 = 39, T__39 = 40, T__40 = 41, COMMENT = 42, ID = 43, REAL = 44,
INT = 45, STRING = 46, WS = 47, EOL = 48
T__0 = 1,
T__1 = 2,
T__2 = 3,
T__3 = 4,
T__4 = 5,
T__5 = 6,
T__6 = 7,
T__7 = 8,
T__8 = 9,
T__9 = 10,
T__10 = 11,
T__11 = 12,
T__12 = 13,
T__13 = 14,
T__14 = 15,
T__15 = 16,
T__16 = 17,
T__17 = 18,
T__18 = 19,
T__19 = 20,
T__20 = 21,
T__21 = 22,
T__22 = 23,
T__23 = 24,
T__24 = 25,
T__25 = 26,
T__26 = 27,
T__27 = 28,
T__28 = 29,
T__29 = 30,
T__30 = 31,
T__31 = 32,
T__32 = 33,
T__33 = 34,
T__34 = 35,
T__35 = 36,
T__36 = 37,
T__37 = 38,
T__38 = 39,
T__39 = 40,
T__40 = 41,
COMMENT = 42,
ID = 43,
REAL = 44,
INT = 45,
STRING = 46,
WS = 47,
EOL = 48
};
PyXACCIRLexer(antlr4::CharStream *input);
~PyXACCIRLexer();
virtual std::string getGrammarFileName() const override;
virtual const std::vector<std::string>& getRuleNames() const override;
virtual const std::vector<std::string> &getRuleNames() const override;
virtual const std::vector<std::string>& getChannelNames() const override;
virtual const std::vector<std::string>& getModeNames() const override;
virtual const std::vector<std::string>& getTokenNames() const override; // deprecated, use vocabulary instead
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;
virtual const std::vector<std::string> &getChannelNames() const override;
virtual const std::vector<std::string> &getModeNames() const override;
virtual const std::vector<std::string> &
getTokenNames() const override; // deprecated, use vocabulary instead
virtual antlr4::dfa::Vocabulary &getVocabulary() const override;
virtual const std::vector<uint16_t> getSerializedATN() const override;
virtual const antlr4::atn::ATN& getATN() const override;
virtual const antlr4::atn::ATN &getATN() const override;
private:
static std::vector<antlr4::dfa::DFA> _decisionToDFA;
......@@ -51,7 +89,6 @@ private:
static antlr4::atn::ATN _atn;
static std::vector<uint16_t> _serializedATN;
// Individual action functions triggered by action() above.
// Individual semantic predicate functions triggered by sempred() above.
......@@ -62,4 +99,4 @@ private:
static Initializer _init;
};
} // namespace pyxacc
} // namespace pyxacc
// Generated from PyXACCIR.g4 by ANTLR 4.7.1
#include "PyXACCIRListener.h"
using namespace pyxacc;
......@@ -3,19 +3,17 @@
#pragma once
#include "antlr4-runtime.h"
#include "PyXACCIRParser.h"
namespace pyxacc {
/**
* This interface defines an abstract listener for a parse tree produced by PyXACCIRParser.
* This interface defines an abstract listener for a parse tree produced by
* PyXACCIRParser.
*/
class PyXACCIRListener : public antlr4::tree::ParseTreeListener {
class PyXACCIRListener : public antlr4::tree::ParseTreeListener {
public:
virtual void enterXaccsrc(PyXACCIRParser::XaccsrcContext *ctx) = 0;
virtual void exitXaccsrc(PyXACCIRParser::XaccsrcContext *ctx) = 0;
......@@ -72,8 +70,6 @@ public:
virtual void enterString(PyXACCIRParser::StringContext *ctx) = 0;
virtual void exitString(PyXACCIRParser::StringContext *ctx) = 0;
};
} // namespace pyxacc
} // namespace pyxacc
......@@ -3,31 +3,82 @@
#pragma once
#include "antlr4-runtime.h"
namespace pyxacc {
class PyXACCIRParser : public antlr4::Parser {
class PyXACCIRParser : public antlr4::Parser {
public:
enum {
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7,
T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14,
T__14 = 15, T__15 = 16, T__16 = 17, T__17 = 18, T__18 = 19, T__19 = 20,
T__20 = 21, T__21 = 22, T__22 = 23, T__23 = 24, T__24 = 25, T__25 = 26,
T__26 = 27, T__27 = 28, T__28 = 29, T__29 = 30, T__30 = 31, T__31 = 32,
T__32 = 33, T__33 = 34, T__34 = 35, T__35 = 36, T__36 = 37, T__37 = 38,
T__38 = 39, T__39 = 40, T__40 = 41, COMMENT = 42, ID = 43, REAL = 44,
INT = 45, STRING = 46, WS = 47, EOL = 48
T__0 = 1,
T__1 = 2,
T__2 = 3,
T__3 = 4,
T__4 = 5,
T__5 = 6,
T__6 = 7,
T__7 = 8,
T__8 = 9,
T__9 = 10,
T__10 = 11,
T__11 = 12,
T__12 = 13,
T__13 = 14,
T__14 = 15,
T__15 = 16,
T__16 = 17,
T__17 = 18,
T__18 = 19,
T__19 = 20,
T__20 = 21,
T__21 = 22,
T__22 = 23,
T__23 = 24,
T__24 = 25,
T__25 = 26,
T__26 = 27,
T__27 = 28,
T__28 = 29,
T__29 = 30,
T__30 = 31,
T__31 = 32,
T__32 = 33,
T__33 = 34,
T__34 = 35,
T__35 = 36,
T__36 = 37,
T__37 = 38,
T__38 = 39,
T__39 = 40,
T__40 = 41,
COMMENT = 42,
ID = 43,
REAL = 44,
INT = 45,
STRING = 46,
WS = 47,
EOL = 48
};
enum {
RuleXaccsrc = 0, RuleXacckernel = 1, RuleMainprog = 2, RuleProgram = 3,
RuleLine = 4, RuleStatement = 5, RuleComment = 6, RuleParamlist = 7,
RuleParam = 8, RuleUop = 9, RuleAllbitsOp = 10, RuleGate = 11, RuleExplist = 12,
RuleExp = 13, RuleCoupler = 14, RuleUnaryop = 15, RuleId = 16, RuleReal = 17,
RuleXaccsrc = 0,
RuleXacckernel = 1,
RuleMainprog = 2,
RuleProgram = 3,
RuleLine = 4,
RuleStatement = 5,
RuleComment = 6,
RuleParamlist = 7,
RuleParam = 8,
RuleUop = 9,
RuleAllbitsOp = 10,
RuleGate = 11,
RuleExplist = 12,
RuleExp = 13,
RuleCoupler = 14,
RuleUnaryop = 15,
RuleId = 16,
RuleReal = 17,
RuleString = 18
};
......@@ -35,11 +86,12 @@ public:
~PyXACCIRParser();
virtual std::string getGrammarFileName() const override;
virtual const antlr4::atn::ATN& getATN() const override { return _atn; };
virtual const std::vector<std::string>& getTokenNames() const override { return _tokenNames; }; // deprecated: use vocabulary instead.
virtual const std::vector<std::string>& getRuleNames() const override;
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;
virtual const antlr4::atn::ATN &getATN() const override { return _atn; };
virtual const std::vector<std::string> &getTokenNames() const override {
return _tokenNames;
}; // deprecated: use vocabulary instead.
virtual const std::vector<std::string> &getRuleNames() const override;
virtual antlr4::dfa::Vocabulary &getVocabulary() const override;
class XaccsrcContext;
class XacckernelContext;
......@@ -59,40 +111,39 @@ public:
class UnaryopContext;
class IdContext;
class RealContext;
class StringContext;
class StringContext;
class XaccsrcContext : public antlr4::ParserRuleContext {
class XaccsrcContext : public antlr4::ParserRuleContext {
public:
XaccsrcContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
std::vector<XacckernelContext *> xacckernel();
XacckernelContext* xacckernel(size_t i);
XacckernelContext *xacckernel(size_t i);
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
};
XaccsrcContext* xaccsrc();
XaccsrcContext *xaccsrc();
class XacckernelContext : public antlr4::ParserRuleContext {
class XacckernelContext : public antlr4::ParserRuleContext {
public:
PyXACCIRParser::IdContext *kernelname = nullptr;;
PyXACCIRParser::IdContext *kernelname = nullptr;
;
XacckernelContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
MainprogContext *mainprog();
IdContext *id();
std::vector<ParamContext *> param();
ParamContext* param(size_t i);
ParamContext *param(size_t i);
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
};
XacckernelContext* xacckernel();
XacckernelContext *xacckernel();
class MainprogContext : public antlr4::ParserRuleContext {
class MainprogContext : public antlr4::ParserRuleContext {
public:
MainprogContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
......@@ -100,41 +151,38 @@ public:
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
};
MainprogContext* mainprog();
MainprogContext *mainprog();
class ProgramContext : public antlr4::ParserRuleContext {
class ProgramContext : public antlr4::ParserRuleContext {
public:
ProgramContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
std::vector<LineContext *> line();
LineContext* line(size_t i);
LineContext *line(size_t i);
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
};
ProgramContext* program();
ProgramContext *program();
class LineContext : public antlr4::ParserRuleContext {
class LineContext : public antlr4::ParserRuleContext {
public:
LineContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
std::vector<StatementContext *> statement();
StatementContext* statement(size_t i);
StatementContext *statement(size_t i);
CommentContext *comment();
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
};
LineContext* line();
LineContext *line();
class StatementContext : public antlr4::ParserRuleContext {
class StatementContext : public antlr4::ParserRuleContext {
public:
StatementContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
......@@ -142,12 +190,11 @@ public:
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
};
StatementContext* statement();
StatementContext *statement();
class CommentContext : public antlr4::ParserRuleContext {
class CommentContext : public antlr4::ParserRuleContext {
public:
CommentContext(antlr4::ParserRuleContext *parent, size_t invokingState);