Skip to content

Commit

Permalink
Merge pull request #88 from tnguyen-ornl/tnguyen/dm-full
Browse files Browse the repository at this point in the history
Implement density matrix simulation via full tensor network contraction
  • Loading branch information
1tnguyen authored Jan 29, 2021
2 parents 3f704f8 + bbe41a7 commit 347f9d3
Show file tree
Hide file tree
Showing 9 changed files with 1,607 additions and 5 deletions.
21 changes: 17 additions & 4 deletions tnqvm/TNQVM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ class TNQVM : public Accelerator {
vqeMode = config.get<bool>("vqe-mode");
}

if (config.stringExists("tnqvm-visitor")) {
const auto requestedBackend = config.getString("tnqvm-visitor");
const auto& allVisitorServices = xacc::getServices<TNQVMVisitor>();
if (config.stringExists("tnqvm-visitor") ||
config.stringExists("backend")) {
// Get the specific TNQVM visitor, either using the `tnqvm-visitor` key
// or the `backend` key.
// e.g., when users use the convention "tnqvm::exatn", "exatn" will be
// parsed and passed in the "backend" field.
const auto requestedBackend = config.stringExists("tnqvm-visitor")
? config.getString("tnqvm-visitor")
: config.getString("backend");
const auto &allVisitorServices = xacc::getServices<TNQVMVisitor>();
// We must have at least one TNQVM service registered.
assert(!allVisitorServices.empty());
bool foundRequestedBackend = false;
Expand Down Expand Up @@ -133,7 +140,13 @@ class TNQVM : public Accelerator {
const std::string& getVisitorName() const { return backendName; }

virtual ~TNQVM() {}


virtual HeterogeneousMap getExecutionInfo() const override {
auto result = visitor->getExecutionInfo();
result.insert("visitor", visitor->name());
return result;
}

int verbose() const { return __verbose; }
void verbose(int level) { __verbose = level; }
void set_verbose(int level) { __verbose = level; }
Expand Down
3 changes: 2 additions & 1 deletion tnqvm/visitors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(itensor)
add_subdirectory(exatn)
add_subdirectory(exatn-mps)
add_subdirectory(exatn-mpo)
add_subdirectory(exatn-mpo)
add_subdirectory(exatn-dm)
5 changes: 5 additions & 0 deletions tnqvm/visitors/TNQVMVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ class TNQVMVisitor : public AllGateVisitor, public OptionsProvider,
// Does this visitor implementation support VQE mode execution?
// i.e. ability to cache the state vector after simulating the ansatz.
virtual bool supportVqeMode() const { return false; }
// Execution information that visitor wants to persist.
HeterogeneousMap getExecutionInfo() const { return executionInfo; }

protected:
std::shared_ptr<AcceleratorBuffer> buffer;
HeterogeneousMap options;
// Visitor impl to set if need be.
HeterogeneousMap executionInfo;
};

} // namespace tnqvm
Expand Down
79 changes: 79 additions & 0 deletions tnqvm/visitors/exatn-dm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
find_package(ExaTN QUIET)

if (ExaTN_FOUND)
message(STATUS "Found ExaTN at ${EXATN_ROOT}")
set (PACKAGE_NAME "TNQVM ExaTN Density Matrix Visitor")
set (PACKAGE_DESCIPTION "TNQVM ExaTN Density Matrix backend")
set (LIBRARY_NAME tnqvm-exatn-dm)

if (TNQVM_MPI_ENABLED)
find_package(MPI REQUIRED)
message(STATUS "Found a suitable MPI compiler ${MPI_CXX_COMPILER}.")
message(STATUS "Compiler vendor is [${CMAKE_CXX_COMPILER_ID}]")
message(STATUS "Include path: ${MPI_CXX_INCLUDE_DIRS}")
message(STATUS "Compile flags: ${MPI_CXX_COMPILE_FLAGS}")
message(STATUS "Link flags: ${MPI_CXX_LINK_FLAGS}")
message(STATUS "Libraries: ${MPI_CXX_LIBRARIES}")
include_directories(${MPI_CXX_INCLUDE_DIRS})
link_libraries(${MPI_CXX_LIBRARIES})
add_definitions(-DTNQVM_MPI_ENABLED)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTNQVM_HAS_EXATN")
set(CMAKE_INSTALL_RPATH "${EXATN_ROOT}/lib")
set(EXATN_VISITOR_CPP_FILE ExaTnDmVisitor.cpp)

if (EXATN_BLAS_LIB MATCHES MKL)
# Fix for bug #30
message(STATUS "Exatn built with MKL, updating our build: ${EXATN_MKL_PATH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTNQVM_EXATN_USES_MKL_BLAS")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ExaTnDmVisitor.cpp"
"${CMAKE_BINARY_DIR}/tnqvm/visitors/exatn-mpo/ExaTnDmVisitor.cpp" @ONLY)
set(EXATN_VISITOR_CPP_FILE ${CMAKE_BINARY_DIR}/tnqvm/visitors/exatn-mpo/ExaTnDmVisitor.cpp)
endif()

file (GLOB HEADERS *.hpp)
file (GLOB SRC ${EXATN_VISITOR_CPP_FILE})

usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)

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

set(_bundle_name tnqvm_exatn_dm)
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 . .. ${XACC_DIR}/include/xacc/)

# Links to ExaTN using its linker config flags.
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc exatn::exatn xacc::quantum_gate)

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

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

if(TNQVM_BUILD_TESTS)
add_subdirectory(tests)
endif()
else()
message(STATUS "ExaTN not found, skipping ExaTNVisitor build")
endif()
Loading

0 comments on commit 347f9d3

Please sign in to comment.