Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing with ORNL-QCI #2

Merged
merged 5 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
[submodule "quantum/plugins/dwave/embedding/minorminer"]
path = quantum/plugins/dwave/embedding/minorminer
url = https://github.com/dwavesystems/minorminer
[submodule "xacc/optimizer/nlopt-optimizers/nlopt"]
path = xacc/optimizer/nlopt-optimizers/nlopt
[submodule "tpls/nlopt"]
path = tpls/nlopt
url = https://github.com/stevengj/nlopt
[submodule "quantum/plugins/dwave/tpls/legacy-sapi-clients"]
path = quantum/plugins/dwave/tpls/legacy-sapi-clients
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ 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)
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()

if(FROM_SETUP_PY AND NOT APPLE)
message(STATUS "Running build from setup.py, linking to static libstdc++")
Expand Down
6 changes: 5 additions & 1 deletion python/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}

target_include_directories(${LIBRARY_NAME} PRIVATE . generated
${CMAKE_SOURCE_DIR}/tpls/antlr/runtime/src)
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc xacc-quantum-gate xacc-quantum-annealing ${ANTLR_LIB})
if(XACC_BUILD_ANNEALING)
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc xacc-quantum-gate xacc-quantum-annealing ${ANTLR_LIB})
else()
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc xacc-quantum-gate ${ANTLR_LIB})
endif()

if(APPLE)
set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib")
Expand Down
11 changes: 9 additions & 2 deletions python/compiler/pyxasm_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

#include "pyxasm_listener.hpp"
#include "Circuit.hpp"
#include "AnnealingProgram.hpp"
#ifdef ANNEALING_ENABLED
#include "AnnealingProgram.hpp"
#endif
#include <memory>
#include <regex>

Expand Down Expand Up @@ -49,12 +51,15 @@ void PyXASMListener::enterInstruction(pyxasmParser::InstructionContext *ctx) {
instructionName = "CNOT";
} else if (instructionName == "MEASURE") {
instructionName = "Measure";
} else if (instructionName == "dwqmi") {
}
#ifdef ANNEALING_ENABLED
else if (instructionName == "dwqmi") {
auto isCircuit = std::dynamic_pointer_cast<quantum::Circuit>(function);
if (isCircuit) {
function = irProvider->createComposite(function->name(), function->getVariables(), "anneal");
}
}
#endif

auto nRequiredBits = irProvider->getNRequiredBits(instructionName);
std::vector<std::size_t> bits;
Expand Down Expand Up @@ -122,9 +127,11 @@ void PyXASMListener::enterInstruction(pyxasmParser::InstructionContext *ctx) {
}
}

#ifdef ANNEALING_ENABLED
if (std::dynamic_pointer_cast<quantum::AnnealingProgram>(tmpInst) && std::dynamic_pointer_cast<quantum::Circuit>(function)) {
function = irProvider->createComposite(function->name(), function->getVariables(), "anneal");
}
#endif
}
function->addInstruction(tmpInst);
function->expand(options);
Expand Down
4 changes: 3 additions & 1 deletion quantum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# Alexander J. McCaskey - initial API and implementation
# *******************************************************************************/
add_subdirectory(gate)
add_subdirectory(annealing)
if (XACC_BUILD_ANNEALING)
add_subdirectory(annealing)
endif()
add_subdirectory(provider)
add_subdirectory(observable)
add_subdirectory(plugins)
Expand Down
6 changes: 5 additions & 1 deletion quantum/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
add_subdirectory(ibm)
add_subdirectory(rigetti)
#add_subdirectory(cmr)
add_subdirectory(dwave)
add_subdirectory(algorithms)
add_subdirectory(decorators)
add_subdirectory(circuits)
add_subdirectory(optimizers)
add_subdirectory(circuit_optimizers)
add_subdirectory(iontrap)
add_subdirectory(ionq)
add_subdirectory(placement)
Expand All @@ -37,6 +37,10 @@ else()
message("-- Could NOT find Qrack library (missing: find_library(QRACK_LIBRARY NAMES qrack))")
endif()

if(XACC_BUILD_ANNEALING)
add_subdirectory(dwave)
endif()

add_subdirectory(optimal_control)
add_subdirectory(qsim)
add_subdirectory(atos_qlm)
Expand Down
63 changes: 63 additions & 0 deletions quantum/plugins/circuit_optimizers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# *******************************************************************************
# 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 v.10 which accompany 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
# *******************************************************************************/
set (LIBRARY_NAME xacc-circuit-optimizers)

file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC simple/*.cpp OptimizersActivator.cpp pulse/*.cpp gate_merge/*.cpp lnn_transform/*.cpp)

# Set up dependencies to resources to track changes
usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
# Generate bundle initialization code
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)

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

set(_bundle_name xacc_circuit_optimizers)

set_target_properties(${LIBRARY_NAME} PROPERTIES
# This is required for every bundle
COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name}
# This is for convenience, used by other CMake functions
US_BUNDLE_NAME ${_bundle_name}
)

# Embed meta-data from a manifest.json file
usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
FILES
manifest.json
)

target_include_directories(${LIBRARY_NAME} PUBLIC simple pulse gate_merge lnn_transform ${EIGEN_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/tpls/exprtk)
target_link_libraries(${LIBRARY_NAME} xacc xacc-quantum-gate)

if(APPLE)
set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib;@loader_path")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared")
endif()

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

# Gather tests
if(XACC_BUILD_TESTS)
add_subdirectory(simple/tests)
add_subdirectory(pulse/tests)
add_subdirectory(gate_merge/tests)
add_subdirectory(lnn_transform/tests)
endif()

add_subdirectory(qsearch)
65 changes: 2 additions & 63 deletions quantum/plugins/optimizers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,63 +1,2 @@
# *******************************************************************************
# 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 v.10 which accompany 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
# *******************************************************************************/
set (LIBRARY_NAME xacc-circuit-optimizers)

file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC simple/*.cpp OptimizersActivator.cpp pulse/*.cpp gate_merge/*.cpp lnn_transform/*.cpp)

# Set up dependencies to resources to track changes
usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
# Generate bundle initialization code
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)

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

set(_bundle_name xacc_circuit_optimizers)

set_target_properties(${LIBRARY_NAME} PROPERTIES
# This is required for every bundle
COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name}
# This is for convenience, used by other CMake functions
US_BUNDLE_NAME ${_bundle_name}
)

# Embed meta-data from a manifest.json file
usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
FILES
manifest.json
)

target_include_directories(${LIBRARY_NAME} PUBLIC simple pulse gate_merge lnn_transform ${EIGEN_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/tpls/exprtk)
target_link_libraries(${LIBRARY_NAME} xacc xacc-quantum-gate)

if(APPLE)
set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib;@loader_path")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared")
endif()

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

# Gather tests
if(XACC_BUILD_TESTS)
add_subdirectory(simple/tests)
add_subdirectory(pulse/tests)
add_subdirectory(gate_merge/tests)
add_subdirectory(lnn_transform/tests)
endif()

add_subdirectory(qsearch)
add_subdirectory(nlopt-optimizers)
add_subdirectory(mlpack)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SET(NLOPT_SWIG OFF CACHE BOOL "")
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings")
endif()
set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
add_subdirectory(nlopt)
add_subdirectory(${CMAKE_SOURCE_DIR}/tpls/nlopt ${CMAKE_BINARY_DIR}/tpls/nlopt)

set(LIBRARY_NAME xacc-optimizer-nlopt)

Expand All @@ -22,7 +22,7 @@ add_library(${LIBRARY_NAME} SHARED ${SRC})

target_include_directories(
${LIBRARY_NAME}
PUBLIC . .. ${CMAKE_BUILD_DIR}/xacc/optimizer/nlopt-optimizers/nlopt/src/api)
PUBLIC . .. ${CMAKE_SOURCE_DIR}/tpls/nlopt/src/api)

target_link_libraries(${LIBRARY_NAME} PUBLIC nlopt xacc CppMicroServices)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "nlopt_optimizer.hpp"
//#include "nlopt_optimizer.hpp"

using namespace xacc;

Expand Down
4 changes: 3 additions & 1 deletion quantum/plugins/placement/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
add_subdirectory(minor_graph_embedding)
if(XACC_BUILD_ANNEALING)
add_subdirectory(minor_graph_embedding)
endif()

# Note: TriQ depends on Z3 library.
# Users need to install Z3, e.g.
Expand Down
6 changes: 5 additions & 1 deletion quantum/provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ usFunctionEmbedResources(TARGET
FILES
manifest.json)

target_link_libraries(${LIBRARY_NAME} PUBLIC xacc PRIVATE xacc-quantum-gate xacc-quantum-annealing)
if(XACC_BUILD_ANNEALING)
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc PRIVATE xacc-quantum-gate xacc-quantum-annealing)
else()
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc PRIVATE xacc-quantum-gate)
endif()
target_compile_features(${LIBRARY_NAME}
PUBLIC
cxx_std_14
Expand Down
24 changes: 18 additions & 6 deletions quantum/provider/QuantumIRProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include "GateIR.hpp"
#include "Circuit.hpp"

#include "DWIR.hpp"
#include "AnnealingProgram.hpp"
#ifdef ANNEALING_ENABLED
#include "DWIR.hpp"
#include "AnnealingProgram.hpp"
#endif

#include "CompositeInstruction.hpp"
#include "xacc_service.hpp"
Expand Down Expand Up @@ -131,9 +133,13 @@ std::shared_ptr<Instruction> QuantumIRProvider::createInstruction(
// FIXME, update to handle D-Wave...
if (type == "circuit") {
return std::make_shared<xacc::quantum::Circuit>(name,variables);
} else if (type == "anneal") {
}
#ifdef ANNEALING_ENABLED
else if (type == "anneal") {
return std::make_shared<xacc::quantum::AnnealingProgram>(name,variables);
} else {
}
#endif
else {
xacc::error("Invalid Composite type, can be circuit or anneal");
return nullptr;
}
Expand All @@ -142,9 +148,15 @@ std::shared_ptr<Instruction> QuantumIRProvider::createInstruction(
std::shared_ptr<IR> QuantumIRProvider::createIR(const std::string type) {
if (type == "circuit") {
return std::make_shared<GateIR>();
} else if (type == "anneal") {
}

#ifdef ANNEALING_ENABLED
else if (type == "anneal") {
return std::make_shared<DWIR>();
} else {
}
#endif

else {
xacc::error("Invalid IR type, can be circuit or anneal");
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion tpls/boost-cmake
Submodule boost-cmake updated 1 files
+15 −7 CMakeLists.txt
1 change: 0 additions & 1 deletion xacc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ endif()
install(FILES ${HEADERS} DESTINATION include/xacc)
install(TARGETS xacc DESTINATION lib)

add_subdirectory(optimizer)
add_subdirectory(utils/exprtk_parsing)
add_subdirectory(ir/graph-impl)
add_subdirectory(utils/ini_config_parsing)
2 changes: 0 additions & 2 deletions xacc/optimizer/CMakeLists.txt

This file was deleted.

Loading