Commit 8113b3c9 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

updating test with coupling map example for hwe


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent dd437f8f
Pipeline #46619 passed with stages
in 2 minutes and 15 seconds
......@@ -113,6 +113,25 @@ bool LambdaVisitor::ScanInitListExpr::VisitDeclRefExpr(DeclRefExpr *expr) {
value = InstructionParameter(expr->getNameInfo().getAsString());
return true;
}
// bool LambdaVisitor::ScanInitListExpr::VisitInitListExpr(InitListExpr *expr) {
// ScanInitListExpr visitor(true);
// visitor.TraverseStmt(expr);
// if (!visitor.intsFound.empty()) {
// // for (int i = 0; i < )
// } else if (!visitor.realsFound.empty()) {
// } else {
// xacc::error("Invalid pair type.");
// }
// return true;
// }
bool LambdaVisitor::ScanInitListExpr::VisitStringLiteral(
StringLiteral *literal) {
......@@ -193,7 +212,7 @@ bool LambdaVisitor::VisitLambdaExpr(LambdaExpr *LE) {
// If it is, then map it to XACC IR
if (isqk.isQuantumKernel()) {
// LE->dumpColor();
LE->dumpColor();
auto cb = LE->capture_begin(); // implicit_capture_begin();
auto ce = LE->capture_end();
......
......@@ -90,14 +90,18 @@ protected:
class ScanInitListExpr : public RecursiveASTVisitor<ScanInitListExpr> {
protected:
bool isFirstStringLiteral = true;
// bool isSubInit;
public:
// std::vector<int> intsFound;
// std::vector<double> realsFound;
std::string key;
InstructionParameter value;
// ScanInitListExpr(bool isSubInitList = false) :isSubInit(isSubInitList) {}
bool VisitDeclRefExpr(DeclRefExpr *expr);
bool VisitStringLiteral(StringLiteral *literal);
bool VisitFloatingLiteral(FloatingLiteral *literal);
bool VisitIntegerLiteral(IntegerLiteral *literal);
// bool VisitInitListExpr(InitListExpr *initList);
};
public:
......
......@@ -111,7 +111,15 @@ int main(int argc, char** argv){
};
return 0;
})hwe2";
const std::string hwe3 = R"hwe3(#include <vector>
int main(int argc, char** argv){
int nq = argc;
std::vector<std::pair<int,int>> c{{1,0}};
auto l = [&](std::vector<double> x) {
hwe(x, {{"n-qubits", nq},{"layers",1},{"coupling", c} });
};
return 0;
})hwe3";
TEST(LambdaVisitorTester, checkSimple) {
Rewriter rewriter1, rewriter2;
auto action1 = new TestQCORFrontendAction(rewriter1);
......@@ -229,6 +237,38 @@ return "lambda_visitor_tester";
EXPECT_EQ(exp1,src2);
}
TEST(LambdaVisitorTester, checkRuntimeGeneratorWithVectorPair) {
Rewriter rewriter1, rewriter2;
auto action1 = new TestQCORFrontendAction(rewriter1);
xacc::setOption("qcor-compiled-filename", "lambda_visitor_tester");
std::vector<std::string> args{"-std=c++11"};
std::cout << "Source Code:\n" << hwe3 << "\n";
// first case, I know compile time values, so ahead-of-time compilation
EXPECT_TRUE(tooling::runToolOnCodeWithArgs(action1, hwe3, args));
std::ifstream t1(".output.cpp");
std::string src2((std::istreambuf_iterator<char>(t1)),
std::istreambuf_iterator<char>());
std::remove(".output.cpp");
std::cout << "HELLO:\n" << src2 <<"\n";
const std::string exp1 = R"exp1(#include <vector>
int main(int argc, char** argv){
int nq = argc;
auto l = [&]() {
qcor::storeRuntimeVariable("n-qubits", nq);
return "lambda_visitor_tester";
};
return 0;
})exp1";
// EXPECT_EQ(exp1,src2);
}
int main(int argc, char **argv) {
qcor::Initialize(argc, argv);
::testing::InitGoogleTest(&argc, argv);
......
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