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

Changing pycv into a proper python package #1134

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
73304a2
setting up a way for calling pycv wit the python module
Iximiel Oct 11, 2024
3754faf
Now pycv works with pip
Iximiel Oct 11, 2024
d15ab27
now the action is included within the wheel
Iximiel Oct 11, 2024
e99df2f
now pycv looks more like a package
Iximiel Oct 11, 2024
0484d68
Reordering the installation procedure
Iximiel Oct 11, 2024
2fa0fa3
added a sort of "FIND PLUMED" that does not work
Iximiel Oct 11, 2024
f64b088
some cleaning
Iximiel Oct 14, 2024
9112fa1
reorganized the code to try to work
Iximiel Oct 14, 2024
389e11a
bettwen naming
Iximiel Oct 14, 2024
a487595
setting up a second run option, adding an helper
Iximiel Oct 14, 2024
4b81b97
removed the self-import gor getting the path of pycv
Iximiel Oct 14, 2024
938228d
adding an example
Iximiel Oct 14, 2024
f237404
Better CMakefiles
Iximiel Oct 14, 2024
c5062fc
moving to a more "external" include fashion
Iximiel Oct 16, 2024
32041be
Now pycv seems to work again
Iximiel Oct 16, 2024
b9d1e0a
A more "canonical" CMake
Iximiel Oct 16, 2024
9dc5e48
now it shoudl work with plumed from pkg-config or not installed (just…
Iximiel Oct 16, 2024
8eb73c9
Restored the Makefile
Iximiel Oct 17, 2024
1c8737c
restoring the standalone tests
Iximiel Oct 17, 2024
62d8aba
resahping the python test
Iximiel Oct 17, 2024
287ae99
adding some extra tests
Iximiel Oct 17, 2024
557887b
updating the WF
Iximiel Oct 17, 2024
6e405e9
better makefile?
Iximiel Oct 17, 2024
840993e
addressing a problem with master
Iximiel Oct 18, 2024
a22dd66
Now pycv appears to load correcly
Iximiel Oct 18, 2024
b3e9f22
added an extra test
Iximiel Oct 18, 2024
a699ba5
set up aslo a few basic tests for pyfunc
Iximiel Oct 18, 2024
42a8dfc
updated the docker recipes with the new installation method of pycv
Iximiel Oct 18, 2024
e7012f7
using pip3 in the makefile
Iximiel Oct 21, 2024
4ab187d
sourcing the correct bashrc in rocky8
Iximiel Oct 21, 2024
cd5bd13
checking if changing env will make the CI pass
Iximiel Oct 21, 2024
34aeec9
now findplumed uses plumed--no-mpi
Iximiel Oct 21, 2024
ea2e77f
readding a donfiguration file
Iximiel Oct 22, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/linuxWF.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ jobs:
if: contains( matrix.variant, '-pycv-' )
working-directory: ./plugins/pycv/
run: |
pip install --user -r requirements.txt
source ../../sourceme.sh
ln -s $(realpath ../../regtest/scripts) ./regtest/scripts
./prepareMakeForDevelop.sh
make check

13 changes: 11 additions & 2 deletions docker/fedora39-pycv
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ FROM plumed:fedora39

RUN source /etc/bashrc \
&& module load mpi \
&& export OMPI_MCA_btl_base_warn_component_unused=0 \
&& export OMPI_MCA_btl_base_verbose=0 \
&& export OMPI_MCA_plm=isolated \
&& export OMPI_MCA_btl_vader_single_copy_mechanism=none \
&& export OMPI_MCA_rmaps_base_oversubscribe=yes \
&& export PATH=$HOME/opt/bin:$PATH \
&& export CPATH=$HOME/opt/include:$CPATH \
&& export INCLUDE=$HOME/opt/include:$INCLUDE \
&& export LIBRARY_PATH=$HOME/opt/lib:$LIBRARY_PATH \
&& export LD_LIBRARY_PATH=$HOME/opt/lib:$LD_LIBRARY_PATH \
&& cd plumed2 \
&& source ./sourceme.sh \
&& cd plugins/pycv \
&& pip3 install -r requirements.txt \
&& ./configurePyCV.sh \
&& ln -s $(realpath ../../regtest/scripts) ./regtest/scripts \
&& python_bin=python3 ./prepareMakeForDevelop.sh \
&& make check
15 changes: 12 additions & 3 deletions docker/rocky8-pycv
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
FROM plumed:rocky8

RUN source ./.bashrc \
RUN . ./.bashrc \
&& module load mpi \
&& export OMPI_MCA_btl_base_warn_component_unused=0 \
&& export OMPI_MCA_btl_base_verbose=0 \
&& export OMPI_MCA_plm=isolated \
&& export OMPI_MCA_btl_vader_single_copy_mechanism=none \
&& export OMPI_MCA_rmaps_base_oversubscribe=yes \
&& export PATH=$HOME/opt/bin:$PATH \
&& export CPATH=$HOME/opt/include:$CPATH \
&& export INCLUDE=$HOME/opt/include:$INCLUDE \
&& export LIBRARY_PATH=$HOME/opt/lib:$LIBRARY_PATH \
&& export LD_LIBRARY_PATH=$HOME/opt/lib:$LD_LIBRARY_PATH \
&& cd plumed2 \
&& source ./sourceme.sh \
&& cd plugins/pycv \
&& pip3 install --user -r requirements.txt \
&& ./configurePyCV.sh \
&& ln -s $(realpath ../../regtest/scripts) ./regtest/scripts \
&& python_bin=python3 ./prepareMakeForDevelop.sh \
&& make check
5 changes: 4 additions & 1 deletion plugins/pycv/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/Makefile.conf
*.o
*.so
env
/env*/
/build*/
/dist*/
*.whl
75 changes: 75 additions & 0 deletions plugins/pycv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
cmake_minimum_required(VERSION 3.15...3.27)
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)

message(
STATUS
"Everithing should work fine if you are in the same environment in which you have compiled plumed"
)
# FinPlumed is here:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
# Finding necessary packages
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG REQUIRED)
find_package(Plumed REQUIRED)

# Finding optionals things
if(Plumed_HAS_MPI)
find_package(MPI REQUIRED)
endif()
if(MPI_CXX_FOUND)
list(APPEND extraLibs MPI::MPI_CXX)
endif()

if(Plumed_HAS_OPENMP)
find_package(OpenMP REQUIRED)
endif()
if(OpenMP_CXX_FOUND)
list(APPEND extraLibs OpenMP::OpenMP_CXX)
endif()

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fno-gnu-unique USE_NO_GNU_UNIQUE)
if(USE_NO_GNU_UNIQUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-gnu-unique")
endif()

# plumed_STATIC_LDFLAGS_OTHER:INTERNAL=-rdynamic;-Wl,-Bsymbolic;-fopenmp
# -rdynamic is automatically set by cmake, and also -fPIC

################################################################################
################################the pycv library################################
################################################################################

add_library(
PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp
src/PythonFunction.cpp)
# public, so they trickle down to the python module
target_compile_definitions(PythonCVInterface PUBLIC ${Plumed_CFLAGS})
target_include_directories(PythonCVInterface PUBLIC src ${Plumed_INCLUDEDIR})
# ####################################################################
# uncommenting this brings problems since some symbols here are needed
# by the python module even if it should be the correct setting...
# https://gcc.gnu.org/wiki/Visibility could be a starting point
#######################################################################
# target_compile_options(PythonCVInterface PRIVATE -fvisibility=hidden)
target_link_libraries(PythonCVInterface PRIVATE pybind11::embed)
target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${extraLibs})
# this removes the "lib" prefix
set_target_properties(PythonCVInterface PROPERTIES PREFIX "")

install(TARGETS PythonCVInterface DESTINATION pycv)

################################################################################
###########################The pvCV companion module############################
################################################################################

pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp)
target_link_libraries(plumedCommunications PRIVATE pybind11::headers)
target_link_libraries(plumedCommunications PUBLIC PythonCVInterface)

# The install directory is the output (wheel) directory
install(TARGETS plumedCommunications DESTINATION .)
87 changes: 87 additions & 0 deletions plugins/pycv/FindPlumed.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
if(NOT Plumed_FOUND)
find_package(PkgConfig)
if(Plumed_FIND_QUIETLY)
function(message)
# THIS completely shuts down messages
endfunction()
pkg_check_modules(PLUMED QUIET plumedInternals)
else()
pkg_check_modules(PLUMED plumedInternals)
endif()

if(Plumed_FOUND)
if("-D__PLUMED_HAS_MPI=1" IN_LIST Plumed_CFLAGS)
set(Plumed_HAS_MPI
1
CACHE INTERNAL "plumed has MPI")
endif()
if("-fopenmp" IN_LIST Plumed_STATIC_LDFLAGS_OTHER)
set(Plumed_HAS_OPENMP
1
CACHE INTERNAL "plumed has OpenMP")
endif()
else()
message(STATUS "plumed not found via pkgconfig, trying executable")

execute_process(
COMMAND plumed --no-mpi info --include-dir
RESULT_VARIABLE PLUMED_EXECUTABLE
OUTPUT_QUIET ERROR_QUIET)
if(PLUMED_EXECUTABLE EQUAL 0)
set(Plumed_FOUND
1
CACHE INTERNAL "plumed found")

message(STATUS "Configuring plumed from executable")
execute_process(
COMMAND plumed --no-mpi info --include-dir
OUTPUT_VARIABLE Plumed_INCLUDEDIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

set(Plumed_INCLUDEDIR
${Plumed_INCLUDEDIR}
CACHE INTERNAL "plumed include dir")
execute_process(
COMMAND plumed --no-mpi info --configuration
OUTPUT_VARIABLE Plumed_CONFIG
OUTPUT_STRIP_TRAILING_WHITESPACE)

set(Plumed_CPP_FLAGS "")

string(REPLACE "\n" ";" ProcessFile_LINES "${Plumed_CONFIG}")
foreach(_line ${ProcessFile_LINES})
if(${_line} MATCHES "CPPFLAGS=.*")
set(Plumed_CPP_FLAGS ${_line})
string(REGEX REPLACE "CPPFLAGS= *" "" Plumed_CPP_FLAGS
${Plumed_CPP_FLAGS})
string(REPLACE "\\" "" Plumed_CPP_FLAGS ${Plumed_CPP_FLAGS})
string(REPLACE "-D" ";" Plumed_CPP_FLAGS ${Plumed_CPP_FLAGS})
# message(STATUS "Found PLUMED CPP_FLAGS: \"${Plumed_CPP_FLAGS}\"")
# message(STATUS "Found PLUMED CPP_FLAGS:") foreach(_flag
# ${Plumed_CPP_FLAGS}) message(STATUS " \"${_flag}\"") endforeach()
endif()
if(${_line} MATCHES ".*-fopenmp.*")
set(Plumed_HAS_MPI
1
CACHE INTERNAL "plumed has MPI")
endif()
endforeach()
set(Plumed_CFLAGS
${Plumed_CPP_FLAGS}
CACHE INTERNAL "plumed Definitions flags")

execute_process(COMMAND plumed --no-mpi config -q has mpi
RESULT_VARIABLE Plumed_WITH_MPI)
if(Plumed_WITH_MPI EQUAL 0)
set(Plumed_HAS_MPI
1
CACHE INTERNAL "plumed has MPI")
endif()

else()
if(Plumed_FIND_REQUIRED)
message(FATAL_ERROR "plumed not found")
endif()
endif()
endif()
endif()
65 changes: 20 additions & 45 deletions plugins/pycv/Makefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
# include the machine dependent configuration
ifneq ($(MAKECMDGOALS),clean)
-include ../../Makefile.conf
ifndef canPyCV
include ./Makefile.conf
endif
endif

.PHONY: clean check all
#Dependency tracking based on https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr
#this assumes gcc
DEPDIR := .deps
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
PYBIND11FLAG =
ADDCPPFLAGS:=$(python_cf_embedded) $(pybind11_cflags) $(ADDCPPFLAGS)
ADDCLDFLAGS:=$(ADDCLDFLAGS) $(python_ld_embedded)
OBJS = ActionWithPython.o PythonCVInterface.o PythonFunction.o PlumedPythonEmbeddedModule.o
PYTHON=python
#optional, just in case you want to override python with ./configurePyCV.sh
-include Makefile.conf
#this makefiles assume that pip and pytest are installed
.PHONY: clean check check_standalone check_python all

ifeq ($(SOEXT),dylib)
SONAME_OPTION:=-Wl,-install_name
else
SONAME_OPTION:=-Wl,-soname
endif
all: pycv_here

all: PythonCVInterface.$(SOEXT)

#-fvisibility=hidden is needed for pybind11 (to not conflict with different pybind11 versions)
#I think I enforced this nearly everywhere I set up a flag for the compiler
ActionWithPython.o PythonCVInterface.o PythonFunction.o PlumedPythonEmbeddedModule.o: PYBIND11FLAG= -fvisibility=hidden

%.o: %.cpp $(DEPDIR)/%.d | $(DEPDIR)
@echo Compiling object $@
@$(CXX) -c $(DEPFLAGS) $(CPPFLAGS) $(PYBIND11FLAG) $(ADDCPPFLAGS) $(CXXFLAGS) $< -o $@


$(DEPDIR): ; @mkdir -p $@

DEPFILES := $(OBJS:%.o=$(DEPDIR)/%.d)
$(DEPFILES):
include $(wildcard $(DEPFILES))

#-Wl,--no-as-needed forces the python library to be linked, without this in a WSL does not work
#TODO: seems that $PLUMED_KERNEL is not needed, check
PythonCVInterface.$(SOEXT): $(OBJS)
@echo Linking $@
$(LDSHARED) $(SONAME_OPTION),"$(notdir $@)" $(DYNAMIC_LIBS) $(PLUMED_KERNEL) $(ADDCLDFLAGS) $^ -o $@
pycv_here: src/*.cpp src/*.h src/pycv/*.py
@echo installing pycv
$(PYTHON) -m pip install .
@touch $@

clean:
rm -f $(OBJS) PythonCVInterface.$(SOEXT)
@$(PYTHON) -m pip uninstall pycv -y
@rm -fv pycv_here

check: all
check_standalone: pycv_here
$(MAKE) -C regtest testclean
$(MAKE) -C regtest checkfail

#just in case pytest is still not installed we install it before the tests
check_python: pycv_here
@$(PYTHON) -m pip install pytest
@$(PYTHON) -m pytest -v

check: check_standalone check_python
3 changes: 2 additions & 1 deletion plugins/pycv/astyle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#formatted with shfmt https://github.com/mvdan/sh/releases
#checked with shellcheck

cd src || exit 1
for file in *.c *.cpp *.h *.inc.in; do

test -f "$file" || continue

echo -n "astyle $file"

../../astyle/astyle --options=../../.astyle.options <"$file" >"${file}.tmp" && {
../../../astyle/astyle --options=../../../.astyle.options <"$file" >"${file}.tmp" && {
if cmp -s "$file" "${file}.tmp"; then
echo
else
Expand Down
54 changes: 0 additions & 54 deletions plugins/pycv/compileConfiguration.sh

This file was deleted.

Loading
Loading