From 80ac4c528a0e4916152e9e69e1d99909024ddf83 Mon Sep 17 00:00:00 2001 From: Ewan Miller Date: Thu, 7 Nov 2024 03:32:25 -0500 Subject: [PATCH 1/7] change the structure of the python directory so that normal build and pip build of pyMaCh3 can properly install the module --- cmake/Templates/setup.MaCh3.sh.in | 2 +- python/CMakeLists.txt | 11 ++++++----- python/pyMaCh3.cpp | 2 +- python/pyMaCh3/__init__.py | 3 +++ python/pyMaCh3/fitter.py | 2 ++ python/pyMaCh3/manager.py | 2 ++ python/pyMaCh3/plotting.py | 2 ++ python/pyMaCh3/samplePDF.py | 2 ++ python/pyMaCh3/splines.py | 2 ++ 9 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 python/pyMaCh3/__init__.py create mode 100644 python/pyMaCh3/fitter.py create mode 100644 python/pyMaCh3/manager.py create mode 100644 python/pyMaCh3/plotting.py create mode 100644 python/pyMaCh3/samplePDF.py create mode 100644 python/pyMaCh3/splines.py diff --git a/cmake/Templates/setup.MaCh3.sh.in b/cmake/Templates/setup.MaCh3.sh.in index 1fa5efd37..48a8cf9c0 100644 --- a/cmake/Templates/setup.MaCh3.sh.in +++ b/cmake/Templates/setup.MaCh3.sh.in @@ -85,7 +85,7 @@ add_to_PATH ${MaCh3_ROOT}/bin add_to_LD_LIBRARY_PATH ${MaCh3_ROOT}/lib if test -d ${MaCh3_ROOT}/pyMaCh3; then - add_to_PYTHONPATH ${MaCh3_ROOT}/pyMaCh3 + add_to_PYTHONPATH ${MaCh3_ROOT} fi unset SETUPDIR diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index ce3daf3e8..20002f08d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -2,7 +2,7 @@ ################################# pybind11 stuff ################################## ## EM: make a module target out of all the python*Module.cpp files (currently just one...) pybind11_add_module( - pyMaCh3 MODULE + _pyMaCh3 MODULE pyMaCh3.cpp plotting.cpp fitter.cpp @@ -13,7 +13,8 @@ pybind11_add_module( ) ## EM: only works with code compiled with -fPIC enabled.. I think this flag can make things slightly slower ## so would be good to find a way around this. -set_property( TARGET pyMaCh3 PROPERTY POSITION_INDEPENDENT_CODE ON ) -target_link_libraries( pyMaCh3 PUBLIC MaCh3::All ) -target_link_libraries( pyMaCh3 PRIVATE MaCh3Warnings ) -install( TARGETS pyMaCh3 DESTINATION pyMaCh3/) +set_property( TARGET _pyMaCh3 PROPERTY POSITION_INDEPENDENT_CODE ON ) +target_link_libraries( _pyMaCh3 PUBLIC MaCh3::All ) +target_link_libraries( _pyMaCh3 PRIVATE MaCh3Warnings ) +install( DIRECTORY pyMaCh3 DESTINATION ./) +install( TARGETS _pyMaCh3 DESTINATION pyMaCh3/) diff --git a/python/pyMaCh3.cpp b/python/pyMaCh3.cpp index 97e225538..072c7e6b3 100644 --- a/python/pyMaCh3.cpp +++ b/python/pyMaCh3.cpp @@ -10,7 +10,7 @@ void initManager(py::module &); // <- defined in python/manager.cpp void initCovariance(py::module &); // <- defined in python/covariance.cpp void initSplines(py::module &); // <- defined in python/splines.cpp -PYBIND11_MODULE( pyMaCh3, m ) { +PYBIND11_MODULE( _pyMaCh3, m ) { initPlotting(m); initFitter(m); initSamplePDF(m); diff --git a/python/pyMaCh3/__init__.py b/python/pyMaCh3/__init__.py new file mode 100644 index 000000000..5b4fab09e --- /dev/null +++ b/python/pyMaCh3/__init__.py @@ -0,0 +1,3 @@ +from ._pyMaCh3 import __doc__, fitter, manager, plotting, sample_pdf, splines + +__all__ = ["__doc__", "fitter", "manager", "plotting", "sample_pdf", "splines"] \ No newline at end of file diff --git a/python/pyMaCh3/fitter.py b/python/pyMaCh3/fitter.py new file mode 100644 index 000000000..84b3280e0 --- /dev/null +++ b/python/pyMaCh3/fitter.py @@ -0,0 +1,2 @@ +from ._pyMaCh3 import fitter +from ._pyMaCh3.fitter import * \ No newline at end of file diff --git a/python/pyMaCh3/manager.py b/python/pyMaCh3/manager.py new file mode 100644 index 000000000..9cb9c110a --- /dev/null +++ b/python/pyMaCh3/manager.py @@ -0,0 +1,2 @@ +from ._pyMaCh3 import manager +from ._pyMaCh3.manager import * \ No newline at end of file diff --git a/python/pyMaCh3/plotting.py b/python/pyMaCh3/plotting.py new file mode 100644 index 000000000..dbe2b33eb --- /dev/null +++ b/python/pyMaCh3/plotting.py @@ -0,0 +1,2 @@ +from ._pyMaCh3 import plotting +from ._pyMaCh3.plotting import * \ No newline at end of file diff --git a/python/pyMaCh3/samplePDF.py b/python/pyMaCh3/samplePDF.py new file mode 100644 index 000000000..882fc6ba3 --- /dev/null +++ b/python/pyMaCh3/samplePDF.py @@ -0,0 +1,2 @@ +from ._pyMaCh3 import sample_pdf +from ._pyMaCh3.sample_pdf import * \ No newline at end of file diff --git a/python/pyMaCh3/splines.py b/python/pyMaCh3/splines.py new file mode 100644 index 000000000..b6a8682d7 --- /dev/null +++ b/python/pyMaCh3/splines.py @@ -0,0 +1,2 @@ +from ._pyMaCh3 import splines +from ._pyMaCh3.splines import * \ No newline at end of file From d7fe5f86f06efcded2747106acf18bea2121180d Mon Sep 17 00:00:00 2001 From: Ewan Miller Date: Thu, 7 Nov 2024 09:39:26 +0100 Subject: [PATCH 2/7] Update README.md --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 967e177fc..897d33c52 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,17 @@ Some functionalities rely on setting `Env{MACH3}` which should point to path exp ## Python -MaCh3 can be compiled with a python interface by specifying the cmake option +MaCh3 has an optional python interface (pyMaCh3) which provides much of the same functionality as the c++ interface +(see [here](https://mach3-software.github.io/MaCh3/pyMaCh3/mainpage.html) for documentation). + +You can tell the build system to set up the pyMaCh3 interface by specifying + ```bash cmake ../ -DMaCh3_PYTHON_ENABLED=ON make && make install ``` -Currently the python module only contains an interface to the plotting library (see [here](https://github.com/mach3-software/MaCh3/blob/develop/plotting/README.md#python) for more information on how to use it) - +when building ### Building with Pip @@ -79,7 +82,7 @@ Additionally, you can build just the Python module by doing: ```bash pip install -t . ``` -The -t option specifies an install location which can be useful if you are on a computing cluster and don't have write access to the default install location. If you specify a non-standard location you will need to add it to your `PYTHONPATH` as above so that python can find the module. +The (optional) -t option specifies an install location which can be useful if you are on a computing cluster and don't have write access to the default install location. If you specify a non-standard location you will need to add it to your `PYTHONPATH` as above so that python can find the module. ## Multithreading MaCh3 quite heavily relies on Multithreading, it is turned on by default. If for debugging purposes you would like to turn it off please use From dd5f28a22756fc8b51787ddfbb17c79edeebeb48 Mon Sep 17 00:00:00 2001 From: Ewan Miller Date: Thu, 7 Nov 2024 09:54:24 +0100 Subject: [PATCH 3/7] hail to the linter --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 897d33c52..047a23fb4 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,9 @@ Some functionalities rely on setting `Env{MACH3}` which should point to path exp ## Python -MaCh3 has an optional python interface (pyMaCh3) which provides much of the same functionality as the c++ interface -(see [here](https://mach3-software.github.io/MaCh3/pyMaCh3/mainpage.html) for documentation). +MaCh3 has an optional python interface (pyMaCh3) which provides much of the same functionality as the c++ interface (see [here](https://mach3-software.github.io/MaCh3/pyMaCh3/mainpage.html) for documentation). -You can tell the build system to set up the pyMaCh3 interface by specifying +You can tell the build system to set up the pyMaCh3 interface by specifying ```bash cmake ../ -DMaCh3_PYTHON_ENABLED=ON From 17946d580e122397278d885962ba7d950de7cc0f Mon Sep 17 00:00:00 2001 From: Ewan Date: Sun, 10 Nov 2024 18:47:09 -0800 Subject: [PATCH 4/7] I don't think these are actually needed as all is imported in the top level __init__.py --- python/pyMaCh3/fitter.py | 2 -- python/pyMaCh3/manager.py | 2 -- python/pyMaCh3/plotting.py | 2 -- python/pyMaCh3/samplePDF.py | 2 -- python/pyMaCh3/splines.py | 2 -- 5 files changed, 10 deletions(-) delete mode 100644 python/pyMaCh3/fitter.py delete mode 100644 python/pyMaCh3/manager.py delete mode 100644 python/pyMaCh3/plotting.py delete mode 100644 python/pyMaCh3/samplePDF.py delete mode 100644 python/pyMaCh3/splines.py diff --git a/python/pyMaCh3/fitter.py b/python/pyMaCh3/fitter.py deleted file mode 100644 index 84b3280e0..000000000 --- a/python/pyMaCh3/fitter.py +++ /dev/null @@ -1,2 +0,0 @@ -from ._pyMaCh3 import fitter -from ._pyMaCh3.fitter import * \ No newline at end of file diff --git a/python/pyMaCh3/manager.py b/python/pyMaCh3/manager.py deleted file mode 100644 index 9cb9c110a..000000000 --- a/python/pyMaCh3/manager.py +++ /dev/null @@ -1,2 +0,0 @@ -from ._pyMaCh3 import manager -from ._pyMaCh3.manager import * \ No newline at end of file diff --git a/python/pyMaCh3/plotting.py b/python/pyMaCh3/plotting.py deleted file mode 100644 index dbe2b33eb..000000000 --- a/python/pyMaCh3/plotting.py +++ /dev/null @@ -1,2 +0,0 @@ -from ._pyMaCh3 import plotting -from ._pyMaCh3.plotting import * \ No newline at end of file diff --git a/python/pyMaCh3/samplePDF.py b/python/pyMaCh3/samplePDF.py deleted file mode 100644 index 882fc6ba3..000000000 --- a/python/pyMaCh3/samplePDF.py +++ /dev/null @@ -1,2 +0,0 @@ -from ._pyMaCh3 import sample_pdf -from ._pyMaCh3.sample_pdf import * \ No newline at end of file diff --git a/python/pyMaCh3/splines.py b/python/pyMaCh3/splines.py deleted file mode 100644 index b6a8682d7..000000000 --- a/python/pyMaCh3/splines.py +++ /dev/null @@ -1,2 +0,0 @@ -from ._pyMaCh3 import splines -from ._pyMaCh3.splines import * \ No newline at end of file From 725d24c87df6ecfb06c196790d9c643ea207d9fc Mon Sep 17 00:00:00 2001 From: Ewan Date: Tue, 12 Nov 2024 22:51:06 -0800 Subject: [PATCH 5/7] tidy cmake --- python/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 20002f08d..f1d13739f 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -14,7 +14,7 @@ pybind11_add_module( ## EM: only works with code compiled with -fPIC enabled.. I think this flag can make things slightly slower ## so would be good to find a way around this. set_property( TARGET _pyMaCh3 PROPERTY POSITION_INDEPENDENT_CODE ON ) -target_link_libraries( _pyMaCh3 PUBLIC MaCh3::All ) +target_link_libraries( _pyMaCh3 PRIVATE MaCh3::All NuOscillator yaml-cpp::yaml-cpp ) target_link_libraries( _pyMaCh3 PRIVATE MaCh3Warnings ) -install( DIRECTORY pyMaCh3 DESTINATION ./) -install( TARGETS _pyMaCh3 DESTINATION pyMaCh3/) +install( DIRECTORY pyMaCh3 DESTINATION ./ ) +install( TARGETS _pyMaCh3 DESTINATION pyMaCh3/ ) \ No newline at end of file From c4ea092bd01d91f4d6be03b3426e6dd76823edae Mon Sep 17 00:00:00 2001 From: Ewan Date: Wed, 13 Nov 2024 23:09:39 -0800 Subject: [PATCH 6/7] use fancy rpath in the python module to find the needed MaCh3 libraries as otherwise it breaks --- CMakeLists.txt | 1 + python/CMakeLists.txt | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cef69e882..f760d90df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,6 +224,7 @@ add_subdirectory(mcmc) add_subdirectory(Diagnostics) add_subdirectory(plotting) if (MaCh3_PYTHON_ENABLED) + set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib") add_subdirectory(python) endif() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index f1d13739f..5bd30f7f5 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -14,7 +14,6 @@ pybind11_add_module( ## EM: only works with code compiled with -fPIC enabled.. I think this flag can make things slightly slower ## so would be good to find a way around this. set_property( TARGET _pyMaCh3 PROPERTY POSITION_INDEPENDENT_CODE ON ) -target_link_libraries( _pyMaCh3 PRIVATE MaCh3::All NuOscillator yaml-cpp::yaml-cpp ) -target_link_libraries( _pyMaCh3 PRIVATE MaCh3Warnings ) +target_link_libraries( _pyMaCh3 PRIVATE MaCh3::All NuOscillator yaml-cpp::yaml-cpp MaCh3Warnings ) install( DIRECTORY pyMaCh3 DESTINATION ./ ) install( TARGETS _pyMaCh3 DESTINATION pyMaCh3/ ) \ No newline at end of file From bb5f61e0a30a6f371a7a3f7271d088ee2135435a Mon Sep 17 00:00:00 2001 From: Ewan Miller Date: Thu, 14 Nov 2024 08:36:26 +0100 Subject: [PATCH 7/7] oops forgot to include covariance module in __init__.py --- python/pyMaCh3/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pyMaCh3/__init__.py b/python/pyMaCh3/__init__.py index 5b4fab09e..9590b0f16 100644 --- a/python/pyMaCh3/__init__.py +++ b/python/pyMaCh3/__init__.py @@ -1,3 +1,3 @@ -from ._pyMaCh3 import __doc__, fitter, manager, plotting, sample_pdf, splines +from ._pyMaCh3 import __doc__, fitter, manager, plotting, sample_pdf, splines, covariance -__all__ = ["__doc__", "fitter", "manager", "plotting", "sample_pdf", "splines"] \ No newline at end of file +__all__ = ["__doc__", "fitter", "manager", "plotting", "sample_pdf", "splines", "covariance"]