Commit 4c0325e4 authored by Daniel Claudino's avatar Daniel Claudino
Browse files

Merge remote-tracking branch 'upstream/mc-vqe-devel' into mc-vqe-devel

parents b3cbfec1 46e82e89
......@@ -58,6 +58,17 @@ int main(int argc, char **argv) {
// Simulate:
accelerator->execute(buffer, f);
std::cout << "First experiment:\n";
buffer->print();
// Run gate-pulse simulation.
// Also, this will test Python interpreter lifetime.
auto x0 = provider->createInstruction("X", {0});
auto f2 = provider->createComposite("tmp2");
f2->addInstructions({x0, m0, m1, m2, m3, m4});
auto buffer2 = xacc::qalloc(5);
accelerator->execute(buffer2, f2);
std::cout << "Second experiment:\n";
buffer2->print();
xacc::Finalize();
}
\ No newline at end of file
......@@ -14,6 +14,10 @@ include_directories(${CMAKE_BINARY_DIR})
add_xacc_test(GradientStrategies)
target_link_libraries(GradientStrategiesTester xacc xacc-quantum-gate xacc-pauli)
add_xacc_test(QuantumNatualGradient)
target_link_libraries(QuantumNatualGradientTester xacc xacc-pauli xacc-gradient-strategies)
target_include_directories(QuantumNatualGradientTester PRIVATE ../)
\ No newline at end of file
# Only test QNG module if LAPACK was installed.
find_package(LAPACK)
if(LAPACK_FOUND)
add_xacc_test(QuantumNatualGradient)
target_link_libraries(QuantumNatualGradientTester xacc xacc-pauli xacc-gradient-strategies)
target_include_directories(QuantumNatualGradientTester PRIVATE ../)
endif()
\ No newline at end of file
set(LIBRARY_NAME xacc-py-aer-adapter)
file(GLOB SRC *.cpp)
find_package(Python COMPONENTS Interpreter Development)
get_filename_component(PYTHON_LIB_NAME ${Python_LIBRARIES} NAME)
configure_file(aer_python_adapter.in.cpp
${CMAKE_BINARY_DIR}/quantum/plugins/ibm/aer/py-aer/aer_python_adapter.cpp)
file(GLOB SRC ${CMAKE_BINARY_DIR}/quantum/plugins/ibm/aer/py-aer/aer_python_adapter.cpp)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -O2 -g -pipe -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wformat -fexceptions --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=native -D_GNU_SOURCE -fPIC -fwrapv")
add_library(${LIBRARY_NAME} SHARED ${SRC})
find_package(Python COMPONENTS Interpreter Development)
if(Python_FOUND)
message(STATUS "${BoldGreen}Found Python version ${Python_VERSION}.${ColorReset}")
# Check if we have Qiskit installed
......@@ -14,7 +17,7 @@ if(Python_FOUND)
message(STATUS "${BoldYellow}Qiskit not found. Aer Pulse Simulator is disabled.${ColorReset}")
else()
message(STATUS "${BoldGreen}Found Qiskit.${ColorReset}")
target_include_directories(${LIBRARY_NAME} PUBLIC . ${Python_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/tpls/pybind11/include)
target_include_directories(${LIBRARY_NAME} PUBLIC . ${Python_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/tpls/pybind11/include ${CMAKE_BINARY_DIR})
target_link_libraries(${LIBRARY_NAME} PRIVATE Python::Python)
target_compile_definitions(${LIBRARY_NAME} PUBLIC XACC_QISKIT_FOUND)
endif()
......
......@@ -5,6 +5,8 @@
#ifdef XACC_QISKIT_FOUND
#include <pybind11/embed.h>
#include <pybind11/stl.h>
#include <dlfcn.h>
#include "xacc_config.hpp"
#endif
namespace xacc {
......@@ -14,7 +16,18 @@ std::string runPulseSim(const std::string &hamJsonStr, double dt,
const std::vector<int> &uChanLoRefs,
const std::string &qObjJson) {
#ifdef XACC_QISKIT_FOUND
pybind11::scoped_interpreter guard{};
static bool PythonInit = false;
if (!PythonInit) {
if (!XACC_IS_APPLE) {
// If not MacOs, preload Python lib to the address space.
// Note: we don't need to dlclose, just need to load the lib to prevent
// linking issue on Linux.
auto libPythonPreload =
dlopen("@PYTHON_LIB_NAME@", RTLD_LAZY | RTLD_GLOBAL);
}
pybind11::initialize_interpreter();
PythonInit = true;
}
auto py_src = R"#(
import json, warnings
import numpy as np
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment