Loading examples/hwe_for_loop_xasm_deuteron.cpp 0 → 100644 +37 −0 Original line number Diff line number Diff line #include "qcor.hpp" #include <heterogeneous.hpp> int main(int argc, char **argv) { qcor::Initialize(argc, argv); auto ansatz = [&](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]); } }; auto optimizer = qcor::getOptimizer("nlopt", {std::make_pair("nlopt-optimizer", "cobyla"), std::make_pair("nlopt-maxeval", 100)}); auto observable = qcor::getObservable("pauli", std::string("5.907 - 2.1433 X0X1 " "- 2.1433 Y0Y1" "+ .21829 Z0 - 6.125 Z1")); int nq = observable->nBits(); auto handle = qcor::submit([&](qcor::qpu_handler &qh) { qh.vqe(ansatz, observable, optimizer, std::vector<double>{}); }); auto results = qcor::sync(handle); } runtime/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories(${LIBRARY_NAME} PUBLIC .) target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc PRIVATE xacc::pauli xacc::fermion) target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc PRIVATE xacc::quantum_gate) xacc_configure_library_rpath(${LIBRARY_NAME}) Loading runtime/qcor.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ #include "xacc_service.hpp" #include "xacc_observable.hpp" // #include "PauliOperator.hpp" #include "CountGatesOfTypeVisitor.hpp" #include "CommonGates.hpp" Loading runtime/qcor.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -99,7 +99,11 @@ protected: std::shared_ptr<Accelerator> backend; std::shared_ptr<AcceleratorBuffer> buffer; std::vector<double> _gradient; public: // Evaluate this ObjectiveFunction at the given params. Optionally // compute the gradient as well and set _gradient virtual double operator()(const std::vector<double> ¶ms) = 0; void initialize(std::shared_ptr<Observable> obs, std::shared_ptr<CompositeInstruction> k, Loading Loading @@ -360,6 +364,9 @@ public: OptFunction optF( [&, objFunction](const std::vector<double> &x) { // FIXME For gradient evaluation, just set // _gradient vector here. Something like // _gradient = objFunction->gradient(); return objFunction->operator()(x); }, function->nVariables()); Loading runtime/tests/test_simple_kernel.cpp +2 −0 Original line number Diff line number Diff line #include <gtest/gtest.h> #include "qcor.hpp" TEST(test_task_initiate, checkVariations) { auto bell = [&](qbit q) { Loading Loading
examples/hwe_for_loop_xasm_deuteron.cpp 0 → 100644 +37 −0 Original line number Diff line number Diff line #include "qcor.hpp" #include <heterogeneous.hpp> int main(int argc, char **argv) { qcor::Initialize(argc, argv); auto ansatz = [&](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]); } }; auto optimizer = qcor::getOptimizer("nlopt", {std::make_pair("nlopt-optimizer", "cobyla"), std::make_pair("nlopt-maxeval", 100)}); auto observable = qcor::getObservable("pauli", std::string("5.907 - 2.1433 X0X1 " "- 2.1433 Y0Y1" "+ .21829 Z0 - 6.125 Z1")); int nq = observable->nBits(); auto handle = qcor::submit([&](qcor::qpu_handler &qh) { qh.vqe(ansatz, observable, optimizer, std::vector<double>{}); }); auto results = qcor::sync(handle); }
runtime/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories(${LIBRARY_NAME} PUBLIC .) target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc PRIVATE xacc::pauli xacc::fermion) target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc PRIVATE xacc::quantum_gate) xacc_configure_library_rpath(${LIBRARY_NAME}) Loading
runtime/qcor.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ #include "xacc_service.hpp" #include "xacc_observable.hpp" // #include "PauliOperator.hpp" #include "CountGatesOfTypeVisitor.hpp" #include "CommonGates.hpp" Loading
runtime/qcor.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -99,7 +99,11 @@ protected: std::shared_ptr<Accelerator> backend; std::shared_ptr<AcceleratorBuffer> buffer; std::vector<double> _gradient; public: // Evaluate this ObjectiveFunction at the given params. Optionally // compute the gradient as well and set _gradient virtual double operator()(const std::vector<double> ¶ms) = 0; void initialize(std::shared_ptr<Observable> obs, std::shared_ptr<CompositeInstruction> k, Loading Loading @@ -360,6 +364,9 @@ public: OptFunction optF( [&, objFunction](const std::vector<double> &x) { // FIXME For gradient evaluation, just set // _gradient vector here. Something like // _gradient = objFunction->gradient(); return objFunction->operator()(x); }, function->nVariables()); Loading
runtime/tests/test_simple_kernel.cpp +2 −0 Original line number Diff line number Diff line #include <gtest/gtest.h> #include "qcor.hpp" TEST(test_task_initiate, checkVariations) { auto bell = [&](qbit q) { Loading