Skip to content

Commit d11d46e

Browse files
committed
cmake modifications
1 parent c4f011e commit d11d46e

File tree

2 files changed

+24
-40
lines changed

2 files changed

+24
-40
lines changed

CMakeLists.txt

+24-34
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,25 @@ option(XACC_BUILD_IONTRAP "Build the iontrap plugin" OFF)
5353
option(PY_ENV "Create and use a Conda Python environment" OFF)
5454

5555
if(PY_ENV)
56-
# Set the environment name to xacc
57-
set(ANACONDA_ENV_NAME "xacc")
58-
59-
# List of required Python packages as separate arguments
60-
set(PYTHON_PACKAGES "iPOPO" "qsrs" "rpcq" "qiskit" "qsearch" "scipy" "myqlm" "scikit-quant" "qfactor" "pybind11")
61-
6256
# Check if the environment already exists by using conda info --envs
6357
execute_process(
64-
COMMAND conda info --envs
65-
OUTPUT_VARIABLE CONDA_ENVS
58+
COMMAND conda info --base
59+
OUTPUT_VARIABLE CONDA_BASE_PATH
6660
OUTPUT_STRIP_TRAILING_WHITESPACE
6761
)
62+
# Set the environment name to xacc
63+
set(ANACONDA_ENV_NAME "xacc")
64+
# Set the base path to the Conda installation
65+
message(STATUS "Using Conda: ${CONDA_BASE_PATH}")
66+
set(ANACONDA_ENV_PATH "${CONDA_BASE_PATH}/envs/${ANACONDA_ENV_NAME}")
67+
# List of required Python packages as separate arguments
68+
set(PYTHON_PACKAGES "iPOPO" "qsrs" "rpcq" "qiskit" "qsearch" "scipy" "myqlm" "scikit-quant" "qfactor")
6869

69-
# Check if the xacc environment is found in the list of conda environments
70-
string(REGEX MATCH "[^ \n]*${ANACONDA_ENV_NAME}[^ \n]*" ANACONDA_ENV_PATH "${CONDA_ENVS}")
7170

72-
if(NOT ANACONDA_ENV_PATH)
71+
# Check if the xacc environment is found in the list of conda environments
72+
if(EXISTS "${ANACONDA_ENV_PATH}")
73+
message(STATUS "Conda environment ${ANACONDA_ENV_NAME} already exists at ${ANACONDA_ENV_PATH}")
74+
else()
7375
# If the environment does not exist, create it
7476
message(STATUS "Conda environment ${ANACONDA_ENV_NAME} not found. Creating the environment.")
7577
execute_process(COMMAND conda create -y --name ${ANACONDA_ENV_NAME} python==3.12.4
@@ -81,17 +83,20 @@ if(PY_ENV)
8183

8284
# After creation, update the environment path
8385
execute_process(
84-
COMMAND conda info --envs
85-
OUTPUT_VARIABLE CONDA_ENVS
86+
COMMAND conda info --base
87+
OUTPUT_VARIABLE CONDA_BASE_PATH
8688
OUTPUT_STRIP_TRAILING_WHITESPACE
8789
)
90+
set(ANACONDA_ENV_PATH "${CONDA_BASE_PATH}/envs/${ANACONDA_ENV_NAME}")
8891

89-
string(REGEX MATCH "[^ \n]*${ANACONDA_ENV_NAME}[^ \n]*" ANACONDA_ENV_PATH "${CONDA_ENVS}")
9092
message(STATUS "Conda environment ${ANACONDA_ENV_NAME} created at ${ANACONDA_ENV_PATH}")
91-
else()
92-
message(STATUS "Conda environment ${ANACONDA_ENV_NAME} already exists at ${ANACONDA_ENV_PATH}")
9393
endif()
9494

95+
# Set the path to Python executable directly from the conda environment
96+
set(Python_EXECUTABLE "${ANACONDA_ENV_PATH}/bin/python")
97+
98+
message(STATUS "Using Python from Conda environment: ${Python_EXECUTABLE}${colorreset}")
99+
95100
# Install necessary Python packages using conda run to ensure environment context
96101
foreach(package ${PYTHON_PACKAGES})
97102
message(STATUS "Checking installation of Python package: ${package}")
@@ -108,7 +113,7 @@ if(PY_ENV)
108113
else()
109114
message(STATUS "Installing Python package: ${package}")
110115
execute_process(
111-
COMMAND conda run -n ${ANACONDA_ENV_NAME} ${Python_EXECUTABLE} pip install ${package}
116+
COMMAND conda run -n ${ANACONDA_ENV_NAME} ${Python_EXECUTABLE} -m pip install ${package}
112117

113118
#COMMAND conda run -n ${ANACONDA_ENV_NAME} ${Python_EXECUTABLE} -m pip install ${package}
114119
RESULT_VARIABLE PIP_INSTALL_RESULT
@@ -117,28 +122,13 @@ if(PY_ENV)
117122
if(NOT PIP_INSTALL_RESULT EQUAL "0")
118123
message(WARNING "Failed to install Python package ${package}. Continuing without it.")
119124
endif()
125+
120126
endif()
121127
endforeach()
122-
123-
execute_process(
124-
COMMAND conda activate ${ANACONDA_ENV_NAME}
125-
)
126-
127-
# Set the path to Python executable directly from the conda environment
128-
set(Python_EXECUTABLE "${ANACONDA_ENV_PATH}/bin/python")
129-
130-
message(STATUS "Using Python from Conda environment: ${Python_EXECUTABLE}{colorreset}")
131128
else()
132-
message(STATUS "PY_ENV is OFF, not using Conda environment.")
129+
message(STATUS "Using system Python")
133130
endif()
134131

135-
136-
137-
138-
139-
140-
141-
142132
if(XACC_BUILD_ANNEALING)
143133
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DANNEALING_ENABLED")
144134
else()

quantum/plugins/ibm/aer/py-aer/CMakeLists.txt

-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
set(LIBRARY_NAME xacc-py-aer-adapter)
2-
# Set the python_ROOT_DIR to the root of your Anaconda environment
3-
4-
set(Python_EXECUTABLE ${ANACONDA_ENV_PATH}/bin/python)
5-
set(Python_INCLUDE_DIRS ${ANACONDA_ENV_PATH}/include/python3.12)
6-
set(Python_LIBRARIES ${ANACONDA_ENV_PATH}/lib/libpython3.12.so)
7-
82

93
find_package(Python COMPONENTS Interpreter Development)
104

0 commit comments

Comments
 (0)