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

Merge pull request #457 from tnguyen-ornl/tnguyen/qalloc-experiment

Moving internal_compiler code to qcor
parents cf45e3c1 aab72a0e
Pipeline #149078 passed with stage
in 11 minutes and 36 seconds
......@@ -2,7 +2,6 @@
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "CommonGates.hpp"
#include "qalloc.hpp"
using namespace xacc;
using namespace xacc::quantum;
......@@ -178,14 +177,8 @@ TEST(ControlledGateTester, checkMultipleControlQregs)
auto ccx = std::dynamic_pointer_cast<CompositeInstruction>(
xacc::getService<Instruction>("C-U"));
auto ctrlReg1 = ::qalloc(1);
auto ctrl1 = ctrlReg1[0];
ctrl1.first = "control1";
auto ctrlReg2 = ::qalloc(1);
auto ctrl2 = ctrlReg2[0];
ctrl2.first = "control2";
const std::vector<std::pair<std::string, size_t>> ctrl_qubits{
{ctrl1.first, ctrl1.second}, {ctrl2.first, ctrl2.second}};
{"control1", 0}, {"control2", 0}};
ccx->expand({{"U", comp}, {"control-idx", ctrl_qubits}});
auto new_circ_str = ccx->toString();
......
......@@ -14,8 +14,8 @@ include_directories(${CMAKE_SOURCE_DIR}/quantum/plugins/rigetti)
#add_xacc_test(QVMAccelerator)
#target_link_libraries(QVMAcceleratorTester xacc-quantum-gate CppMicroServices)
add_xacc_test(QuilCompiler)
target_link_libraries(QuilCompilerTester xacc-quantum-gate CppMicroServices)
# add_xacc_test(QuilCompiler)
# target_link_libraries(QuilCompilerTester xacc-quantum-gate CppMicroServices)
add_xacc_test(QuilVisitor)
target_link_libraries(QuilVisitorTester xacc-quantum-gate)
......@@ -16,10 +16,6 @@
#include "xacc_quantum_gate_api.hpp"
#include "xacc_service.hpp"
#include "Utils.hpp"
#include "xacc_internal_compiler.hpp"
#include "qalloc.hpp"
#include "Circuit.hpp"
TEST (XASMCompilerTester, checkQcorIssue23) {
......@@ -203,80 +199,6 @@ TEST(XASMCompilerTester, checkVectorArg) {
<< IR->getComposites()[0]->operator()({2.})->toString() << "\n";
}
TEST(XASMCompilerTester, checkSimpleFor) {
auto compiler = xacc::getCompiler("xasm");
auto IR =
compiler->compile(R"(__qpu__ void testFor(qbit q, std::vector<double> x) {
for (int i = 0; i < 5; i++) {
H(q[i]);
}
for (int i = 0; i < 2; i++) {
Rz(q[i], x[i]);
}
})");
std::cout << "KERNEL\n" << IR->getComposites()[0]->toString() << "\n";
xacc::internal_compiler::qreg q(5);
auto tt = IR->getComposites()[0];
tt->updateRuntimeArguments(q, std::vector<double>{1.2, 3.4});
std::cout << "EVALED NEW WAY:\n" << tt->toString() << "\n";
IR = compiler->compile(
R"(__qpu__ void testFor2(qbit q, std::vector<double> x) {
for (int i = 0; i < 5; i++) {
H(q[i]);
Rx(q[i], x[i]);
CX(q[0], q[i]);
}
for (int i = 0; i < 3; i++) {
CX(q[i], q[i+1]);
}
Rz(q[3], 0.22);
for (int i = 3; i > 0; i--) {
CX(q[i-1],q[i]);
}
})");
EXPECT_EQ(1, IR->getComposites().size());
std::cout << "KERNEL\n" << IR->getComposites()[0]->toString() << "\n";
for (auto ii : IR->getComposites()[0]->getVariables())
std::cout << ii << "\n";
EXPECT_EQ(22, IR->getComposites()[0]->nInstructions());
IR->getComposites()[0]->updateRuntimeArguments(
q, std::vector<double>{1, 2, 3, 4, 5});
std::cout << "KERNEL\n" << IR->getComposites()[0]->toString() << "\n";
}
TEST(XASMCompilerTester, checkHWEFor) {
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(R"([&](qbit q, std::vector<double> x) {
for (int i = 0; i < 2; i++) {
Rx(q[i],x[i]);
Rz(q[i],x[2+i]);
}
CX(q[1],q[0]);
for (int i = 0; i < 2; i++) {
Rx(q[i], x[i+4]);
Rz(q[i], x[i+4+2]);
Rx(q[i], x[i+4+4]);
}
})");
EXPECT_EQ(1, IR->getComposites().size());
std::cout << "KERNEL\n" << IR->getComposites()[0]->toString() << "\n";
for (auto ii : IR->getComposites()[0]->getVariables())
std::cout << ii << "\n";
EXPECT_EQ(11, IR->getComposites()[0]->nInstructions());
xacc::internal_compiler::qreg q(2);
IR->getComposites()[0]->updateRuntimeArguments(
q, std::vector<double>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
std::cout << "KERNEL\n" << IR->getComposites()[0]->toString() << "\n";
}
TEST(XASMCompilerTester, checkIfStmt) {
auto q = xacc::qalloc(2);
......@@ -419,161 +341,6 @@ TEST(XASMCompilerTester, checkCallingPreviousKernel) {
std::cout << bell->toString() << "\n";
}
TEST(XASMCompilerTester, checkIRV3) {
// auto v = xacc::qalloc(1);
// v->setName("v");
// xacc::storeBuffer(v);
// auto v = xacc::internal_compiler::qalloc(1);
xacc::internal_compiler::qreg v(1);
auto H = xacc::quantum::getObservable("pauli", std::string("X0 Y1 + Y0 X1"));
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(
R"(
__qpu__ void foo_test (qbit v, double x, double y, double z, std::shared_ptr<Observable> H) {
Rx(v[0], x);
U(v[0], x, y, z);
exp_i_theta(v, x, H);
}
)");
auto foo_test = IR->getComposite("foo_test");
std::cout << foo_test->toString() << "\n";
for (auto &val : {2.2, 2.3, 2.4, 2.5}) {
foo_test->updateRuntimeArguments(v, val, 3.3, 4.4, H);
std::cout << foo_test->toString() << "\n\n";
}
}
TEST(XASMCompilerTester, checkIRV3Vector) {
// auto v = xacc::qalloc(1);
// v->setName("v");
// xacc::storeBuffer(v);
// auto v = xacc::internal_compiler::qalloc(1);
xacc::internal_compiler::qreg v(1);
auto H = xacc::quantum::getObservable("pauli", std::string("X0 Y1 + Y0 X1"));
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(
R"(
__qpu__ void foo_test2 (qbit v, std::vector<double> x, std::shared_ptr<Observable> H) {
Rx(v[0], x[0]);
U(v[0], x[0], x[1], x[2]);
exp_i_theta(v, x[1], H);
}
)");
auto foo_test = IR->getComposite("foo_test2");
std::cout << foo_test->toString() << "\n";
for (auto &val : {2.2, 2.3, 2.4, 2.5}) {
foo_test->updateRuntimeArguments(v, std::vector<double>{val, 3.3, 4.4}, H);
std::cout << foo_test->toString() << "\n\n";
}
IR = compiler->compile(
R"(
__qpu__ void ansatz2(qreg q, std::vector<double> theta) {
X(q[0]);
Ry(q[1], theta[0]);
CX(q[1],q[0]);
}
)");
auto test = IR->getComposites()[0];
std::cout << " HELLO: " << test->toString() << "\n";
test->updateRuntimeArguments(v, std::vector<double>{.48});
std::cout << " HELLO: " << test->toString() << "\n";
}
TEST(XASMCompilerTester, checkIRV3Expression) {
// auto v = xacc::qalloc(1);
// v->setName("v");
// xacc::storeBuffer(v);
// auto v = xacc::internal_compiler::qalloc(1);
xacc::internal_compiler::qreg v(1);
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(
R"(
__qpu__ void foo_test3 (qbit v, double x) {
Rx(v[0], 2.2*x+pi);
}
)");
auto foo_test = IR->getComposite("foo_test3");
std::cout << foo_test->toString() << "\n";
for (auto &val : {2.2, 2.3, 2.4, 2.5}) {
foo_test->updateRuntimeArguments(v, val);
std::cout << foo_test->toString() << "\n\n";
}
}
TEST(XASMCompilerTester, checkAnnealInstructions) {
xacc::internal_compiler::qreg v(1);
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(
R"(
__qpu__ void anneal_test (qbit v, double x, double y) {
QMI(v[0], x);
QMI(v[1], y);
QMI(v[0], v[1], .2345);
}
)");
auto foo_test = IR->getComposite("anneal_test");
std::cout << foo_test->toString() << "\n";
for (auto &val : {2.2, 2.3, 2.4, 2.5}) {
foo_test->updateRuntimeArguments(v, val, 3.3);
std::cout << foo_test->toString() << "\n\n";
}
IR = compiler->compile(
R"(
__qpu__ void ansatz222(qreg v, std::vector<double> x) {
QMI(v[0], x[0]);
QMI(v[1], x[1]);
QMI(v[0], v[1], x[2]);
}
)");
auto test = IR->getComposites()[0];
std::cout << " HELLO: " << test->toString() << "\n";
test->updateRuntimeArguments(v, std::vector<double>{.48, .58, .68});
std::cout << " HELLO: " << test->toString() << "\n";
IR = compiler->compile(
R"(
__qpu__ void rbm_test(qreg v, std::vector<double> x, int nv, int nh) {
rbm(v, x, nv, nh);
}
)");
test = IR->getComposites()[0];
for (int i = 1; i < 4; i++) {
// std::cout << " HELLO: " << test->toString() << "\n";
test->updateRuntimeArguments(v, std::vector<double>(i * i + i + i), i, i);
std::cout << " HELLO:\n" << test->toString() << "\n";
}
}
int main(int argc, char **argv) {
xacc::Initialize(argc, argv);
xacc::set_verbose(true);
......
......@@ -28,8 +28,7 @@ file(GLOB
HEADERS
xacc.hpp
ir/*.hpp
compiler/*.hpp
compiler/qalloc
compiler/Compiler.hpp
accelerator/*.hpp
accelerator/remote/*.hpp
utils/*.hpp
......@@ -42,8 +41,6 @@ add_library(xacc SHARED
accelerator/AcceleratorBuffer.cpp
utils/Utils.cpp
utils/CLIParser.cpp
compiler/xacc_internal_compiler.cpp
compiler/qalloc.cpp
service/ServiceRegistry.cpp
service/xacc_service.cpp
accelerator/remote/RemoteAccelerator.cpp)
......
......@@ -18,13 +18,13 @@ add_xacc_test(Algorithm xacc)
add_xacc_test(Heterogeneous xacc)
target_compile_features(HeterogeneousTester PRIVATE cxx_std_14)
configure_file(InternalCompilerTester.in.cpp
${CMAKE_BINARY_DIR}/xacc/tests/InternalCompilerTester.cpp)
# configure_file(InternalCompilerTester.in.cpp
# ${CMAKE_BINARY_DIR}/xacc/tests/InternalCompilerTester.cpp)
add_executable(InternalCompilerTester ${CMAKE_BINARY_DIR}/xacc/tests/InternalCompilerTester.cpp)
target_include_directories(InternalCompilerTester PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(InternalCompilerTester PRIVATE xacc ${GTEST_LIBRARIES})
add_test(NAME xacc_InternalCompilerTester COMMAND InternalCompilerTester)
target_compile_features(InternalCompilerTester PRIVATE cxx_std_14)
# add_executable(InternalCompilerTester ${CMAKE_BINARY_DIR}/xacc/tests/InternalCompilerTester.cpp)
# target_include_directories(InternalCompilerTester PRIVATE ${GTEST_INCLUDE_DIRS})
# target_link_libraries(InternalCompilerTester PRIVATE xacc ${GTEST_LIBRARIES})
# add_test(NAME xacc_InternalCompilerTester COMMAND InternalCompilerTester)
# target_compile_features(InternalCompilerTester PRIVATE cxx_std_14)
#add_xacc_test(InternalCompiler xacc)
\ No newline at end of file
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