Loading CMakeLists.txt +3 −3 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12) endif() set(CMAKE_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 14) set(CMAKE_DISABLE_IN_SOURCE_BUILDS ON) set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) Loading @@ -21,7 +21,7 @@ find_package(XACC REQUIRED) configure_file(${CMAKE_SOURCE_DIR}/scripts/qcor.in ${CMAKE_BINARY_DIR}/qcor) include_directories(/home/cades/dev/llvm-project/clang/include) add_subdirectory(runtime) add_subdirectory(compiler) add_subdirectory(ir) Loading README.md +41 −28 Original line number Diff line number Diff line Loading @@ -50,41 +50,54 @@ the following file int main(int argc, char **argv) { // Initialize the QCOR Runtime // Initialize QCOR qcor::Initialize(argc, argv); auto optimizer = qcor::getOptimizer( "nlopt", {{"nlopt-optimizer", "cobyla"}, {"nlopt-maxeval", 20}}); auto op = qcor::getObservable("pauli", "5.907 - 2.1433 X0X1 " // Define your quantum kernel, here as a // standard C++ lambda containing quantum code auto ansatz = [&](qbit q, std::vector<double> t) { X(q[0]); Ry(q[1], t[0]); CNOT(q[1], q[0]); }; // Get a valid Optimizer auto optimizer = qcor::getOptimizer("nlopt", {std::make_pair("nlopt-optimizer", "cobyla"), std::make_pair("nlopt-maxeval", 20)}); // Define the Observable auto observable = qcor::getObservable("pauli", std::string("5.907 - 2.1433 X0X1 " "- 2.1433 Y0Y1" "+ .21829 Z0 - 6.125 Z1"); // Schedule an asynchronous VQE execution // with the given quantum kernel ansatz auto future = qcor::submit([&](qcor::qpu_handler &qh) { qh.vqe( [&](double t0) { X(0); Ry(t0, 1); CX(1, 0); }, op, optimizer); }); // Get and print the results auto results = future.get(); results->print(); "+ .21829 Z0 - 6.125 Z1")); // Call qcor::taskInitiate to kick off asynchronous execution of // VQE with given ansatz, optimizer, and observable, and initial params 0.0 auto handle = qcor::taskInitiate(ansatz, "vqe", optimizer, observable, std::vector<double>{0.0}); // Go do other work, task is running asynchronously // Now request the results, this will wait // until the task finishes. auto results = qcor::sync(handle); // Get the results... std::cout << results->getInformation("opt-val").as<double>() << "\n"; // Finalize the framework. qcor::Finalize(); } ``` To compile this with QCOR, run the following ```bash $ qcor deuteron.cpp -o deuteron $ qcor -o deuteron deuteron.cpp ``` This will create the ```deuteron``` quantum-classical binary executable. Now just run ```bash $ ./deuteron $ ./deuteron --accelerator tnqvm ``` compiler/CMakeLists.txt +20 −33 Original line number Diff line number Diff line add_subdirectory(clang) set(LIBRARY_NAME qcor-compiler) file(GLOB SRC *.cpp) usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC) usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC) add_library(${LIBRARY_NAME} SHARED ${SRC}) set(LIBRARY_NAME qcor-ast-plugin) add_library(${LIBRARY_NAME} SHARED fuzzy_parsing.cpp qcor_ast_visitor.cpp qcor_ast_consumer.cpp qcor_frontend_action.cpp) target_include_directories(${LIBRARY_NAME} PUBLIC . ${XACC_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ) ${LLVM_INCLUDE_DIRS}) target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc qcor-ast-plugin ${CLANG_LIBS} ${LLVM_LIBS}) set(_bundle_name qcor_compiler) set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name} US_BUNDLE_NAME ${_bundle_name}) target_link_libraries(${LIBRARY_NAME} PUBLIC ${CLANG_LIBS} ${LLVM_LIBS} tinfo xacc::xacc) usfunctionembedresources(TARGET ${LIBRARY_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} FILES manifest.json) xacc_configure_library_rpath(${LIBRARY_NAME}) xacc_configure_plugin_rpath(${LIBRARY_NAME}) install(TARGETS ${LIBRARY_NAME} DESTINATION lib) if(QCOR_BUILD_TESTS) #add_subdirectory(tests) add_subdirectory(tests) endif() file(GLOB HEADERS *.hpp) install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins) configure_file(qcor-driver.in.cpp ${CMAKE_BINARY_DIR}/compiler/qcor-driver.cpp) add_executable(qcor-driver ${CMAKE_BINARY_DIR}/compiler/qcor-driver.cpp) target_link_libraries(qcor-driver PRIVATE qcor-ast-plugin qcor) install(PROGRAMS ${CMAKE_BINARY_DIR}/compiler/qcor-driver DESTINATION bin) compiler/QCORCompiler.cppdeleted 100644 → 0 +0 −46 Original line number Diff line number Diff line #include "QCORCompiler.hpp" #include "IRProvider.hpp" #include "xacc_service.hpp" namespace qcor { std::shared_ptr<IR> QCORCompiler::compile(const std::string &src, std::shared_ptr<Accelerator> acc) { return nullptr; } std::shared_ptr<IR> QCORCompiler::compile(const std::string &src) { return compile(src, nullptr); } const std::shared_ptr<Function> QCORCompiler::compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) { auto provider = xacc::getService<xacc::IRProvider>("quantum"); auto ir = provider->createIR(); ir->addKernel(f); // FIXME Hardware Independent Transformation // Hardware Dependent Transformations if (acc) { auto ts = acc->getIRTransformations(); for (auto& t : ts) { ir = t->transform(ir); } } // FIXME Program Verification??? return f; } const std::string QCORCompiler::translate(const std::string &bufferVariable, std::shared_ptr<Function> function) { xacc::error("QCORCompiler::translate() not implemented."); return ""; } } compiler/QCORCompiler.hppdeleted 100644 → 0 +0 −78 Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2019 UT-Battelle, LLC. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompanies this * distribution. The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution *License is available at https://eclipse.org/org/documents/edl-v10.php * * Contributors: * Alexander J. McCaskey - initial API and implementation *******************************************************************************/ #ifndef COMPILER_QCORCOMPILER_HPP_ #define COMPILER_QCORCOMPILER_HPP_ #include "XACC.hpp" using namespace xacc; namespace qcor { /** * The PyXACCCompiler is an XACC Compiler that compiles * python-like gate instruction source code to produce a * XACC IR. */ class QCORCompiler : public xacc::Compiler { public: /** * The Compiler. */ QCORCompiler() {} /** * Compile the given kernel code for the * given Accelerator. * * @param src The source code * @param acc Reference to the D-Wave Accelerator * @return */ virtual std::shared_ptr<xacc::IR> compile(const std::string &src, std::shared_ptr<Accelerator> acc); /** * Compile the given kernel code. * * @param src The source code * @return */ virtual std::shared_ptr<xacc::IR> compile(const std::string &src); const std::shared_ptr<Function> compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) override; /** * We don't allow translations for the PyXACC Compiler. * @param bufferVariable * @param function * @return */ virtual const std::string translate(const std::string &bufferVariable, std::shared_ptr<Function> function); virtual const std::string name() const { return "qcor"; } virtual const std::string description() const { return ""; } /** * The destructor */ virtual ~QCORCompiler() {} }; } // namespace xacc #endif Loading
CMakeLists.txt +3 −3 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12) endif() set(CMAKE_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 14) set(CMAKE_DISABLE_IN_SOURCE_BUILDS ON) set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) Loading @@ -21,7 +21,7 @@ find_package(XACC REQUIRED) configure_file(${CMAKE_SOURCE_DIR}/scripts/qcor.in ${CMAKE_BINARY_DIR}/qcor) include_directories(/home/cades/dev/llvm-project/clang/include) add_subdirectory(runtime) add_subdirectory(compiler) add_subdirectory(ir) Loading
README.md +41 −28 Original line number Diff line number Diff line Loading @@ -50,41 +50,54 @@ the following file int main(int argc, char **argv) { // Initialize the QCOR Runtime // Initialize QCOR qcor::Initialize(argc, argv); auto optimizer = qcor::getOptimizer( "nlopt", {{"nlopt-optimizer", "cobyla"}, {"nlopt-maxeval", 20}}); auto op = qcor::getObservable("pauli", "5.907 - 2.1433 X0X1 " // Define your quantum kernel, here as a // standard C++ lambda containing quantum code auto ansatz = [&](qbit q, std::vector<double> t) { X(q[0]); Ry(q[1], t[0]); CNOT(q[1], q[0]); }; // Get a valid Optimizer auto optimizer = qcor::getOptimizer("nlopt", {std::make_pair("nlopt-optimizer", "cobyla"), std::make_pair("nlopt-maxeval", 20)}); // Define the Observable auto observable = qcor::getObservable("pauli", std::string("5.907 - 2.1433 X0X1 " "- 2.1433 Y0Y1" "+ .21829 Z0 - 6.125 Z1"); // Schedule an asynchronous VQE execution // with the given quantum kernel ansatz auto future = qcor::submit([&](qcor::qpu_handler &qh) { qh.vqe( [&](double t0) { X(0); Ry(t0, 1); CX(1, 0); }, op, optimizer); }); // Get and print the results auto results = future.get(); results->print(); "+ .21829 Z0 - 6.125 Z1")); // Call qcor::taskInitiate to kick off asynchronous execution of // VQE with given ansatz, optimizer, and observable, and initial params 0.0 auto handle = qcor::taskInitiate(ansatz, "vqe", optimizer, observable, std::vector<double>{0.0}); // Go do other work, task is running asynchronously // Now request the results, this will wait // until the task finishes. auto results = qcor::sync(handle); // Get the results... std::cout << results->getInformation("opt-val").as<double>() << "\n"; // Finalize the framework. qcor::Finalize(); } ``` To compile this with QCOR, run the following ```bash $ qcor deuteron.cpp -o deuteron $ qcor -o deuteron deuteron.cpp ``` This will create the ```deuteron``` quantum-classical binary executable. Now just run ```bash $ ./deuteron $ ./deuteron --accelerator tnqvm ```
compiler/CMakeLists.txt +20 −33 Original line number Diff line number Diff line add_subdirectory(clang) set(LIBRARY_NAME qcor-compiler) file(GLOB SRC *.cpp) usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC) usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC) add_library(${LIBRARY_NAME} SHARED ${SRC}) set(LIBRARY_NAME qcor-ast-plugin) add_library(${LIBRARY_NAME} SHARED fuzzy_parsing.cpp qcor_ast_visitor.cpp qcor_ast_consumer.cpp qcor_frontend_action.cpp) target_include_directories(${LIBRARY_NAME} PUBLIC . ${XACC_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ) ${LLVM_INCLUDE_DIRS}) target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc qcor-ast-plugin ${CLANG_LIBS} ${LLVM_LIBS}) set(_bundle_name qcor_compiler) set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name} US_BUNDLE_NAME ${_bundle_name}) target_link_libraries(${LIBRARY_NAME} PUBLIC ${CLANG_LIBS} ${LLVM_LIBS} tinfo xacc::xacc) usfunctionembedresources(TARGET ${LIBRARY_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} FILES manifest.json) xacc_configure_library_rpath(${LIBRARY_NAME}) xacc_configure_plugin_rpath(${LIBRARY_NAME}) install(TARGETS ${LIBRARY_NAME} DESTINATION lib) if(QCOR_BUILD_TESTS) #add_subdirectory(tests) add_subdirectory(tests) endif() file(GLOB HEADERS *.hpp) install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins) configure_file(qcor-driver.in.cpp ${CMAKE_BINARY_DIR}/compiler/qcor-driver.cpp) add_executable(qcor-driver ${CMAKE_BINARY_DIR}/compiler/qcor-driver.cpp) target_link_libraries(qcor-driver PRIVATE qcor-ast-plugin qcor) install(PROGRAMS ${CMAKE_BINARY_DIR}/compiler/qcor-driver DESTINATION bin)
compiler/QCORCompiler.cppdeleted 100644 → 0 +0 −46 Original line number Diff line number Diff line #include "QCORCompiler.hpp" #include "IRProvider.hpp" #include "xacc_service.hpp" namespace qcor { std::shared_ptr<IR> QCORCompiler::compile(const std::string &src, std::shared_ptr<Accelerator> acc) { return nullptr; } std::shared_ptr<IR> QCORCompiler::compile(const std::string &src) { return compile(src, nullptr); } const std::shared_ptr<Function> QCORCompiler::compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) { auto provider = xacc::getService<xacc::IRProvider>("quantum"); auto ir = provider->createIR(); ir->addKernel(f); // FIXME Hardware Independent Transformation // Hardware Dependent Transformations if (acc) { auto ts = acc->getIRTransformations(); for (auto& t : ts) { ir = t->transform(ir); } } // FIXME Program Verification??? return f; } const std::string QCORCompiler::translate(const std::string &bufferVariable, std::shared_ptr<Function> function) { xacc::error("QCORCompiler::translate() not implemented."); return ""; } }
compiler/QCORCompiler.hppdeleted 100644 → 0 +0 −78 Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2019 UT-Battelle, LLC. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompanies this * distribution. The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution *License is available at https://eclipse.org/org/documents/edl-v10.php * * Contributors: * Alexander J. McCaskey - initial API and implementation *******************************************************************************/ #ifndef COMPILER_QCORCOMPILER_HPP_ #define COMPILER_QCORCOMPILER_HPP_ #include "XACC.hpp" using namespace xacc; namespace qcor { /** * The PyXACCCompiler is an XACC Compiler that compiles * python-like gate instruction source code to produce a * XACC IR. */ class QCORCompiler : public xacc::Compiler { public: /** * The Compiler. */ QCORCompiler() {} /** * Compile the given kernel code for the * given Accelerator. * * @param src The source code * @param acc Reference to the D-Wave Accelerator * @return */ virtual std::shared_ptr<xacc::IR> compile(const std::string &src, std::shared_ptr<Accelerator> acc); /** * Compile the given kernel code. * * @param src The source code * @return */ virtual std::shared_ptr<xacc::IR> compile(const std::string &src); const std::shared_ptr<Function> compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) override; /** * We don't allow translations for the PyXACC Compiler. * @param bufferVariable * @param function * @return */ virtual const std::string translate(const std::string &bufferVariable, std::shared_ptr<Function> function); virtual const std::string name() const { return "qcor"; } virtual const std::string description() const { return ""; } /** * The destructor */ virtual ~QCORCompiler() {} }; } // namespace xacc #endif