Commit bf5a1646 authored by Nguyen, Thien's avatar Nguyen, Thien

Added unit test

Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent e9949e08
......@@ -750,12 +750,13 @@ double QLanczos::calcQlanczosEnergy(const std::vector<double>& normVec) const
const double s = 0.75;
const double epsilon = 1e-12;
auto [Hreg, Sreg] = regularizeMatrices(s, epsilon);
// TODO: solving the *generalized* eigenvalues: Hx = ESx
// to compute the Lanczos energy E
arma::cx_vec eigval;
arma::cx_mat eigvec;
arma::eig_pair(eigval, eigvec, Hreg, Sreg);
std::cout << "Eigen values:\n" << eigval << "\n";
// TODO: returns the smallest eigenvalue from the previous step.
return 0.0;
return eigval(0).real();
}
} // namespace algorithm
......
......@@ -14,10 +14,35 @@
#include <gtest/gtest.h>
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "PauliOperator.hpp"
TEST(QLanczosTester, checkSimple)
{
// TODO
auto qLanczos = xacc::getService<xacc::Algorithm>("QLanczos");
std::shared_ptr<xacc::Observable> observable = std::make_shared<xacc::quantum::PauliOperator>();
observable->fromString("0.7071067811865475 X0 + 0.7071067811865475 Z0");
auto acc = xacc::getAccelerator("qpp");
const int nbSteps = 25;
const double stepSize = 0.1;
const bool initOk = qLanczos->initialize({
std::make_pair("accelerator", acc),
std::make_pair("steps", nbSteps),
std::make_pair("observable", observable),
std::make_pair("step-size", stepSize)
});
EXPECT_TRUE(initOk);
auto buffer = xacc::qalloc(1);
qLanczos->execute(buffer);
const double finalEnergy = (*buffer)["opt-val"].as<double>();
std::cout << "Final Energy: " << finalEnergy << "\n";
// Fig (2.e) of https://www.nature.com/articles/s41567-019-0704-4
// Minimal Energy = -1
// EXPECT_NEAR(finalEnergy, -1.0, 1e-3);
// const std::vector<double> energyValues = (*buffer)["exp-vals"].as<std::vector<double>>();
// EXPECT_EQ(energyValues.size(), nbSteps + 1);
}
int main(int argc, char **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