Unverified Commit 819f0175 authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #94 from tnguyen-ornl/tnguyen/reset-inst

Add Reset instruction
parents 51356e10 e2bfea19
Loading
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ static const std::map<std::string, std::string> gates{
    {"z", "Z"},        {"h", "H"},     {"s", "S"},     {"sdg", "Sdg"},
    {"t", "T"},        {"tdg", "Tdg"}, {"rx", "Rx"},   {"ry", "Ry"},
    {"rz", "Rz"},      {"cz", "CZ"},   {"cy", "CY"},   {"swap", "Swap"},
    {"ccx", "CCX"}, {"ch", "CH"},   {"crz", "CRZ"}, {"measure", "Measure"}};
    {"ccx", "CCX"},    {"ch", "CH"},   {"crz", "CRZ"}, {"measure", "Measure"},
    {"reset", "Reset"}};

void StaqTokenCollector::collect(clang::Preprocessor &PP,
                                 clang::CachedTokens &Toks,
+25 −0
Original line number Diff line number Diff line
@@ -261,6 +261,31 @@ quantum::mz(c[3]);
            ss.str());
}

TEST(StaqTokenCollectorTester, checkReset) {
  LexerHelper helper;

  auto [tokens, PP] = helper.Lex(R"#(
creg c[1];
h q[0];
reset q[0];
reset q[1];
x q[0];
measure q[0] -> c[0];)#");

  clang::CachedTokens cached;
  for (auto &t : tokens) {
    cached.push_back(t);
  }

  std::stringstream ss;
  auto xasm_tc = xacc::getService<qcor::TokenCollector>("staq");
  xasm_tc->collect(*PP.get(), cached, {"q"}, ss);
  std::cout << "heres the test\n";
  std::cout << ss.str() << "\n";
  EXPECT_TRUE(ss.str().find("quantum::reset(q[0]);") != std::string::npos);
  EXPECT_TRUE(ss.str().find("quantum::reset(q[1]);") != std::string::npos);
}

int main(int argc, char **argv) {
  std::string xacc_config_install_dir = std::string(XACC_INSTALL_DIR);
  std::string qcor_root = std::string(QCOR_INSTALL_DIR);
+18 −0
Original line number Diff line number Diff line
@@ -117,6 +117,24 @@ beta_counter ++ ;
            ss.str());
}

TEST(XASMTokenCollectorTester, checkReset) {
  LexerHelper helper;

  auto [tokens, PP] = helper.Lex("H(q[0]);\nReset(q[0]);\nRy(q[3], theta);");

  clang::CachedTokens cached;
  for (auto &t : tokens) {
    cached.push_back(t);
  }

  std::stringstream ss;
  auto xasm_tc = xacc::getService<qcor::TokenCollector>("xasm");
  xasm_tc->collect(*PP.get(), cached, {"q"}, ss);
  std::cout << "heres the test\n";
  std::cout << ss.str() << "\n";
  EXPECT_TRUE(ss.str().find("quantum::reset(q[0]);") != std::string::npos);
}

int main(int argc, char **argv) {
  std::string xacc_config_install_dir = std::string(XACC_INSTALL_DIR);
  std::string qcor_root = std::string(QCOR_INSTALL_DIR);
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ else()
endif()

if (QCOR_BUILD_TESTS) 
  #add_subdirectory(tests)
  add_subdirectory(tests)
endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
+4 −0
Original line number Diff line number Diff line
@@ -55,6 +55,10 @@ public:
    applyGate("U", {qidx.second}, {theta, phi, lambda});
  }

  virtual void reset(const qubit &qidx) override {
    applyGate("Reset", {qidx.second});
  }

  // Measure-Z
  virtual bool mz(const qubit &qidx) override {
    applyGate("Measure", {qidx.second});
Loading