Skip to content

Commit

Permalink
working on WS
Browse files Browse the repository at this point in the history
  • Loading branch information
vicenley committed Nov 21, 2024
1 parent 8adf8ac commit 23ca4bb
Show file tree
Hide file tree
Showing 2 changed files with 470 additions and 0 deletions.
88 changes: 88 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,93 @@ option(XACC_BUILD_QFACTOR "Build the QFactor plugin" OFF)
option(XACC_BUILD_QSEARCH "Build the QSearch plugin" OFF)
option(XACC_BUILD_QRACK "Build the Qrack plugin" OFF)

# set the conditional if linux
if(UNIX AND NOT APPLE)
set(GDL_ROOT "/usr/lib/x86_64-linux-gnu" CACHE PATH "Path to GDL root directory")
set(GEOS_ROOT "/usr/lib/x86_64-linux-gnu" CACHE PATH "Path to GEOS root directory")
set(PCRE_ROOT "/usr/lib/x86_64-linux-gnu" CACHE PATH "Path to PCRE root directory")
set(NETCDF_ROOT "/usr/lib/x86_64-linux-gnu" CACHE PATH "Path to NetCDF root directory")
endif()
# Add option to specify if a Python environment should be created
option(PY_ENV "Create and use a Conda Python environment" OFF)

if(PY_ENV)
# Check if the environment already exists by using conda info --envs
execute_process(
COMMAND conda info --base
OUTPUT_VARIABLE CONDA_BASE_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Set the environment name to xacc
set(ANACONDA_ENV_NAME "xacc")
# Set the base path to the Conda installation
message(STATUS "Using Conda: ${CONDA_BASE_PATH}")
set(ANACONDA_ENV_PATH "${CONDA_BASE_PATH}/envs/${ANACONDA_ENV_NAME}")
# List of required Python packages as separate arguments
set(PYTHON_PACKAGES "iPOPO" "qsrs" "rpcq" "qiskit" "qsearch" "scipy" "myqlm" "scikit-quant" "qfactor")


# Check if the xacc environment is found in the list of conda environments
if(EXISTS "${ANACONDA_ENV_PATH}")
message(STATUS "Conda environment ${ANACONDA_ENV_NAME} already exists at ${ANACONDA_ENV_PATH}")
else()
# If the environment does not exist, create it
message(STATUS "Conda environment ${ANACONDA_ENV_NAME} not found. Creating the environment.")
execute_process(COMMAND conda create -y --name ${ANACONDA_ENV_NAME} python==3.12.4
RESULT_VARIABLE CONDA_CREATE_RESULT)

if(NOT CONDA_CREATE_RESULT EQUAL "0")
message(FATAL_ERROR "Failed to create Conda environment ${ANACONDA_ENV_NAME}")
endif()

# After creation, update the environment path
execute_process(
COMMAND conda info --base
OUTPUT_VARIABLE CONDA_BASE_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(ANACONDA_ENV_PATH "${CONDA_BASE_PATH}/envs/${ANACONDA_ENV_NAME}")

message(STATUS "Conda environment ${ANACONDA_ENV_NAME} created at ${ANACONDA_ENV_PATH}")
endif()

# Set the path to Python executable directly from the conda environment
set(Python_EXECUTABLE "${ANACONDA_ENV_PATH}/bin/python")

message(STATUS "Using Python from Conda environment: ${Python_EXECUTABLE}${colorreset}")

# Install necessary Python packages using conda run to ensure environment context
foreach(package ${PYTHON_PACKAGES})
message(STATUS "Checking installation of Python package: ${package}")

# First, check if the package is already installed by trying to import it
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import ${package}"
RESULT_VARIABLE PACKAGE_INSTALLED
OUTPUT_QUIET ERROR_QUIET
)

if(PACKAGE_INSTALLED EQUAL "0")
message(STATUS "Python package ${package} is already installed.")
else()
message(STATUS "Installing Python package: ${package}")
execute_process(
COMMAND conda run -n ${ANACONDA_ENV_NAME} ${Python_EXECUTABLE} -m pip install ${package}

#COMMAND conda run -n ${ANACONDA_ENV_NAME} ${Python_EXECUTABLE} -m pip install ${package}
RESULT_VARIABLE PIP_INSTALL_RESULT
)

if(NOT PIP_INSTALL_RESULT EQUAL "0")
message(WARNING "Failed to install Python package ${package}. Continuing without it.")
endif()

endif()
endforeach()
else()
message(STATUS "Using system Python")
endif()

if(XACC_BUILD_ANNEALING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DANNEALING_ENABLED")
else()
Expand Down Expand Up @@ -188,6 +275,7 @@ if (XACC_DEPS_EXTERNAL)
endif()

include_directories(${CMAKE_BINARY_DIR}/tpls/cppmicroservices/include)
#include_directories(/usr/local/include/cppmicroservices4/cppmicroservices)
add_subdirectory(tpls)

IF(CMAKE_BUILD_TYPE MATCHES "Debug" OR CMAKE_BUILD_TYPE MATCHES "DEBUG")
Expand Down
Loading

0 comments on commit 23ca4bb

Please sign in to comment.