Commit 9b0b5710 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added unit test for exp qrt



To check the new qrt construction

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 9374de14
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -56,3 +56,7 @@ if (QCOR_BUILD_TESTS)
endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)

if (QCOR_BUILD_TESTS)
  add_subdirectory(tests)
endif()
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -179,7 +179,9 @@ class NISQ : public ::quantum::QuantumRuntime {
    auto q_name = q.name();
    for (auto inst : terms) {
      auto spinInst = inst.second;

      if (spinInst.isIdentity()) {
        continue;
      }
      // Get the individual pauli terms
      auto termsMap = std::get<2>(spinInst);

+9 −0
Original line number Diff line number Diff line
link_directories(${XACC_ROOT}/lib)
if (NOT XACC_ROOT STREQUAL CMAKE_INSTALL_PREFIX)
  add_definitions(-D__internal__qcor__compile__plugin__path="${CMAKE_INSTALL_PREFIX}/plugins")
endif()

add_executable(NisqQrtTester NisqQrtTester.cpp)
add_test(NAME qcor_NisqQrtTester COMMAND NisqQrtTester)
target_include_directories(NisqQrtTester PRIVATE ${XACC_ROOT}/include/gtest)
target_link_libraries(NisqQrtTester ${XACC_TEST_LIBRARIES} qcor)
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
#include "qcor.hpp"
#include <gtest/gtest.h>
#include "xacc_service.hpp"

TEST(NisqQrtTester, checkExpInst) {
  ::quantum::initialize("qpp", "empty");
  const std::string obs_str =
      "5.907 - 2.1433 X0X1 - 2.1433 Y0Y1 + .21829 Z0 - 6.125 Z1";
  auto observable = qcor::createObservable(obs_str);
  auto qreg = qalloc(2);
  qreg.setName("q");
  ::quantum::exp(qreg, 1.0, observable);
  std::cout << "HOWDY\n"
            << ::quantum::qrt_impl->get_current_program()->toString() << "\n";
  // Get the XACC reference implementation
  auto exp = std::dynamic_pointer_cast<xacc::quantum::Circuit>(
      xacc::getService<xacc::Instruction>("exp_i_theta"));
  EXPECT_TRUE(exp->expand({{ "pauli", obs_str}}));
  auto evaled = exp->operator()({0.5});
  std::cout << "HELLO\n" << evaled->toString() << "\n";
  EXPECT_EQ(evaled->toString(), ::quantum::qrt_impl->get_current_program()->toString());
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  auto ret = RUN_ALL_TESTS();
  return ret;
}