Commit c55ac2e7 authored by Mccaskey, Alex's avatar Mccaskey, Alex

updating vqe tester to demonstrate new heterogenous map construction

Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 17a2fa40
Pipeline #111514 passed with stage
in 14 minutes and 25 seconds
......@@ -41,34 +41,42 @@ const std::string rucc = R"rucc(__qpu__ void f(qbit q, double t0) {
})rucc";
TEST(VQETester, checkSimple) {
// if (xacc::hasAccelerator("qpp")) {
auto acc = xacc::getAccelerator("qpp", {std::make_pair("vqe-mode",true)});
auto buffer = xacc::qalloc(4);//->createBuffer("q", 4);
// if (xacc::hasAccelerator("qpp")) {
auto acc = xacc::getAccelerator("qpp", {std::make_pair("vqe-mode", true)});
auto buffer = xacc::qalloc(4); //->createBuffer("q", 4);
auto compiler = xacc::getCompiler("xasm");
auto compiler = xacc::getCompiler("xasm");
auto ir = compiler->compile(rucc, nullptr);
auto ruccsd = ir->getComposite("f");
auto ir = compiler->compile(rucc, nullptr);
auto ruccsd = ir->getComposite("f");
auto optimizer = xacc::getOptimizer("nlopt");
std::shared_ptr<Observable> observable = std::make_shared<xacc::quantum::PauliOperator>();//= std::make_shared<xacc::quantum::PauliOperator>();
observable->fromString(
"(0.174073,0) Z2 Z3 + (0.1202,0) Z1 Z3 + (0.165607,0) Z1 Z2 + "
"(0.165607,0) Z0 Z3 + (0.1202,0) Z0 Z2 + (-0.0454063,0) Y0 Y1 X2 X3 + "
"(-0.220041,0) Z3 + (-0.106477,0) + (0.17028,0) Z0 + (-0.220041,0) Z2 "
"+ (0.17028,0) Z1 + (-0.0454063,0) X0 X1 Y2 Y3 + (0.0454063,0) X0 Y1 "
"Y2 X3 + (0.168336,0) Z0 Z1 + (0.0454063,0) Y0 X1 X2 Y3");
auto optimizer = xacc::getOptimizer("nlopt");
std::shared_ptr<Observable> observable = std::make_shared<
xacc::quantum::
PauliOperator>(); //=
// std::make_shared<xacc::quantum::PauliOperator>();
observable->fromString(
"(0.174073,0) Z2 Z3 + (0.1202,0) Z1 Z3 + (0.165607,0) Z1 Z2 + "
"(0.165607,0) Z0 Z3 + (0.1202,0) Z0 Z2 + (-0.0454063,0) Y0 Y1 X2 X3 + "
"(-0.220041,0) Z3 + (-0.106477,0) + (0.17028,0) Z0 + (-0.220041,0) Z2 "
"+ (0.17028,0) Z1 + (-0.0454063,0) X0 X1 Y2 Y3 + (0.0454063,0) X0 Y1 "
"Y2 X3 + (0.168336,0) Z0 Z1 + (0.0454063,0) Y0 X1 X2 Y3");
auto vqe = xacc::getService<Algorithm>("vqe");
EXPECT_TRUE(vqe->initialize({std::make_pair("ansatz",ruccsd),
std::make_pair("accelerator",acc),
std::make_pair("observable", observable),
std::make_pair("optimizer",optimizer)}));
vqe->execute(buffer);
EXPECT_NEAR(-1.13717, mpark::get<double>(buffer->getInformation("opt-val")), 1e-4);
EXPECT_NEAR(-1.13717,vqe->execute(buffer, (*buffer)["opt-params"].as<std::vector<double>>())[0], 1e-4);
// std::cout << "EVALED: " << vqe->execute(buffer, (*buffer)["opt-params"].as<std::vector<double>>()) << "\n";
// }
auto vqe = xacc::getService<Algorithm>("vqe");
EXPECT_TRUE(vqe->initialize({{"ansatz", ruccsd},
{"accelerator", acc},
{"observable", observable},
{"optimizer", optimizer}}));
vqe->execute(buffer);
EXPECT_NEAR(-1.13717, mpark::get<double>(buffer->getInformation("opt-val")),
1e-4);
EXPECT_NEAR(-1.13717,
vqe->execute(
buffer, (*buffer)["opt-params"].as<std::vector<double>>())[0],
1e-4);
// std::cout << "EVALED: " << vqe->execute(buffer,
// (*buffer)["opt-params"].as<std::vector<double>>()) << "\n";
// }
}
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