Skip to content

Commit

Permalink
Merge pull request #26 from danclaudino/disable_remote
Browse files Browse the repository at this point in the history
Remote accelerators can be disabled
  • Loading branch information
danclaudino authored Jul 30, 2024
2 parents 85fca92 + 0a6cda4 commit 4eb4cbb
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 139 deletions.
49 changes: 27 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,49 @@ set(CMAKE_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
message(STATUS "C++ version ${CXX_STANDARD} configured.")

if(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()

option(XACC_BUILD_TESTS "Build test programs" OFF)
option(XACC_BUILD_EXAMPLES "Build example programs" OFF)
option(XACC_ENSMALLEN_INCLUDE_DIR "Path to ensmallen.hpp for mlpack optimizer" "")
option(XACC_ARMADILLO_INCLUDE_DIR "Path to armadillo header for mlpack optimizer" "")
option(XACC_BUILD_ANNEALING "Build annealing libraries" OFF)
option(XACC_BUILD_SCIPY "Build Scipy optimizer plugin" OFF)
option(XACC_BUILD_ANNEALING "Build annealing libraries" OFF)
if(XACC_BUILD_ANNEALING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DANNEALING_ENABLED")
else()
message(STATUS "${BoldYellow}Skipping Annealing libraries by default. You can turn it on with -DXACC_BUILD_ANNEALING=ON${ColorReset}")
endif()

option(QIREE_MINIMAL_BUILD "Build only components for QIREE CI" OFF)

if(QIREE_MINIMAL_BUILD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQIREE_BUILD")
endif()

option(XACC_REMOTE_ACCELERATORS "Build remove (cloud) accelerators" ON)
if(NOT XACC_REMOTE_ACCELERATORS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DREMOTE_DISABLED")
message(STATUS "${BoldYellow}Skipping remote accelerators. Only local simulators are now enabled.{ColorReset}")
endif()

if(FROM_SETUP_PY AND NOT APPLE)
message(STATUS "Running build from setup.py, linking to static libstdc++")
set(CMAKE_SHARED_LINKER_FLAGS "-static-libstdc++" CACHE INTERNAL "" FORCE)
Expand Down Expand Up @@ -92,26 +117,6 @@ include(format)
include(cxxFlags)
include(ExternalProject)

if(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.xacc" CACHE PATH "default install path" FORCE)
endif()
Expand Down
36 changes: 21 additions & 15 deletions quantum/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,33 @@
# *******************************************************************************/
add_subdirectory(ibm)
add_subdirectory(algorithms)
add_subdirectory(ionq)
add_subdirectory(xasm)
add_subdirectory(qpp)
add_subdirectory(staq)
add_subdirectory(honeywell)

if(XACC_REMOTE_ACCELERATORS)
add_subdirectory(ionq)
add_subdirectory(honeywell)
endif()

if(NOT QIREE_MINIMAL_BUILD)
add_subdirectory(placement)
add_subdirectory(iontrap)
add_subdirectory(circuits)
add_subdirectory(optimizers)
add_subdirectory(circuit_optimizers)
add_subdirectory(rigetti)
add_subdirectory(decorators)
add_subdirectory(observable_transforms)
add_subdirectory(optimal_control)
add_subdirectory(qsim)
add_subdirectory(atos_qlm)
add_subdirectory(noise_model)
add_subdirectory(placement)
add_subdirectory(iontrap)
add_subdirectory(circuits)
add_subdirectory(optimizers)
add_subdirectory(circuit_optimizers)
add_subdirectory(decorators)
add_subdirectory(observable_transforms)
add_subdirectory(optimal_control)
add_subdirectory(qsim)
add_subdirectory(noise_model)
add_subdirectory(rigetti)

if(XACC_REMOTE_ACCELERATORS)
add_subdirectory(atos_qlm)
endif()

find_library(QRACK_LIBRARY NAMES qrack)
find_library(QRACK_LIBRARY NAMES qrack)
if (QRACK_LIBRARY)
message("-- Found Qrack library (find_library(QRACK_LIBRARY NAMES qrack))")
add_subdirectory(qrack)
Expand Down
35 changes: 18 additions & 17 deletions quantum/plugins/ibm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,29 @@ file(GLOB SRC
compiler/generated/*.cpp
accelerator/OpenPulseVisitor.cpp)


usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC)
usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC)

add_library(${LIBRARY_NAME} SHARED ${SRC})

target_include_directories(${LIBRARY_NAME}
PUBLIC accelerator
compiler
common
compiler/generated
accelerator/json
${CMAKE_SOURCE_DIR}/tpls/antlr/runtime/src
${CMAKE_SOURCE_DIR}/tpls/rapidjson/include)
#${CMAKE_SOURCE_DIR}/tpls/exprtk

target_link_libraries(${LIBRARY_NAME}
PUBLIC xacc
xacc-quantum-gate
${ANTLR_LIB}
CppMicroServices PRIVATE cpr)
target_include_directories(${LIBRARY_NAME}
PUBLIC accelerator
compiler
common
compiler/generated
accelerator/json
${CMAKE_SOURCE_DIR}/tpls/antlr/runtime/src
${CMAKE_SOURCE_DIR}/tpls/rapidjson/include)

target_link_libraries(${LIBRARY_NAME}
PUBLIC xacc
xacc-quantum-gate
${ANTLR_LIB}
CppMicroServices)

if(XACC_REMOTE_ACCELERATORS)
target_link_libraries(${LIBRARY_NAME} PRIVATE cpr)
endif()

set(_bundle_name xacc_ibm)
set_target_properties(${LIBRARY_NAME}
Expand Down Expand Up @@ -81,4 +82,4 @@ if(XACC_BUILD_TESTS)
add_subdirectory(accelerator/json/tests)
endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
8 changes: 6 additions & 2 deletions quantum/plugins/ibm/IBMActivator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ class US_ABI_LOCAL IBMActivator : public BundleActivator {
/**
*/
void Start(BundleContext context) {

//#
//ifndef REMOTE_DISABLED
auto acc = std::make_shared<xacc::quantum::IBMAccelerator>();
context.RegisterService<xacc::Accelerator>(acc);
//#
//endif

#ifdef LAPACK_FOUND
auto acc2 = std::make_shared<xacc::quantum::LocalIBMAccelerator>();
Expand All @@ -52,8 +58,6 @@ class US_ABI_LOCAL IBMActivator : public BundleActivator {
auto c2 = std::make_shared<xacc::quantum::QObjectCompiler>();
context.RegisterService<xacc::Compiler>(c2);

context.RegisterService<xacc::Accelerator>(acc);

auto qasm_qobj_gen = std::make_shared<xacc::quantum::QasmQObjGenerator>();
auto pulse_qobj_gen = std::make_shared<xacc::quantum::PulseQObjGenerator>();

Expand Down
14 changes: 13 additions & 1 deletion quantum/plugins/ibm/accelerator/IBMAccelerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "OpenPulseVisitor.hpp"
#include "CountGatesOfTypeVisitor.hpp"

#ifndef REMOTE_DISABLED
#include <cpr/cpr.h>
#endif

#include "xacc.hpp"
#include "xacc_service.hpp"
Expand Down Expand Up @@ -1085,7 +1087,7 @@ const std::string RestClient::post(const std::string &remoteUrl,
const std::string &path,
const std::string &postStr,
std::map<std::string, std::string> headers) {

#ifndef REMOTE_DISABLED
if (headers.empty()) {
headers.insert(std::make_pair("Content-type", "application/json"));
headers.insert(std::make_pair("Connection", "keep-alive"));
Expand All @@ -1109,10 +1111,14 @@ const std::string RestClient::post(const std::string &remoteUrl,
r.error.message + ": " + r.text);

return r.text;
#else
return "";
#endif
}

void RestClient::put(const std::string &remoteUrl, const std::string &putStr,
std::map<std::string, std::string> headers) {
#ifndef REMOTE_DISABLED
if (headers.empty()) {
headers.insert(std::make_pair("Content-type", "application/json"));
headers.insert(std::make_pair("Connection", "keep-alive"));
Expand All @@ -1133,12 +1139,14 @@ void RestClient::put(const std::string &remoteUrl, const std::string &putStr,
throw std::runtime_error("HTTP POST Error - status code " +
std::to_string(r.status_code) + ": " +
r.error.message + ": " + r.text);
#endif
return;
}
const std::string
RestClient::get(const std::string &remoteUrl, const std::string &path,
std::map<std::string, std::string> headers,
std::map<std::string, std::string> extraParams) {
#ifndef REMOTE_DISABLED
if (headers.empty()) {
headers.insert(std::make_pair("Content-type", "application/json"));
headers.insert(std::make_pair("Connection", "keep-alive"));
Expand Down Expand Up @@ -1166,6 +1174,9 @@ RestClient::get(const std::string &remoteUrl, const std::string &path,
r.error.message + ": " + r.text);

return r.text;
#else
return "";
#endif
}

std::string IBMAccelerator::post(const std::string &_url,
Expand Down Expand Up @@ -1424,6 +1435,7 @@ void IBMPulseTransform::apply(std::shared_ptr<CompositeInstruction> program,
program->clear();
program->addInstructions(loweredKernel->getInstructions());
}

} // namespace quantum
} // namespace xacc

Expand Down
6 changes: 4 additions & 2 deletions quantum/plugins/rigetti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)

add_subdirectory(qcs)
add_subdirectory(quilc)
if(XACC_REMOTE_ACCELERATORS)
add_subdirectory(qcs)
add_subdirectory(quilc)
endif()
Loading

0 comments on commit 4eb4cbb

Please sign in to comment.