From 7170bc3683be0d4d968a43f68b231b0b879814c2 Mon Sep 17 00:00:00 2001 From: Jost Migenda Date: Fri, 7 Jun 2024 18:22:40 +0100 Subject: [PATCH 1/3] add simple build workflow, update setup.py * remove hard-coded paths from setup.py * remove unused distutils import in setup.py (Note that distutils has been removed in Python 3.12) * skip Ubuntu and Windows for now --- .github/workflows/build.yaml | 54 ++++++++++++++++++++++++++++++++++++ setup.py | 20 +++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..c7a8126 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,54 @@ +name: Build EMEWS + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the main branch +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + strategy: + fail-fast: false + matrix: + os: [macos-latest] # [macos-latest, ubuntu-latest, windows-latest] + python-version: ['3.12'] # ['3.9', '3.10', '3.11', '3.12'] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies (all OSes) + run: | + python -m pip install --upgrade pip + pip install setuptools wheel pybind11 + - name: Install dependencies (macOS) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + brew install libomp + echo "LIBOMP_INCLUDE=`brew --prefix`/opt/libomp/include" >> $GITHUB_ENV + - name: Install dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + exit 1 # TODO: Add Ubuntu dependencies here + - name: Install dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + exit 1 # TODO: Add Windows dependencies here + + - name: Install EMEWS + run: | + python setup.py sdist bdist_wheel + ls -al dist/ + pip install dist/*.whl + - name: Run example script + run: | + python EMEWS_example.py diff --git a/setup.py b/setup.py index ac665fa..d379313 100644 --- a/setup.py +++ b/setup.py @@ -6,9 +6,10 @@ import os -from distutils.command.sdist import sdist as DistutilsSdist from setuptools import setup, find_packages from setuptools.extension import Extension +import sysconfig +import pybind11 # # Begin setup @@ -52,13 +53,20 @@ 'docs':['numpydoc'] } +LIBOMP_INCLUDE = os.environ['LIBOMP_INCLUDE'] +PYBIND11_INCLUDE = os.path.join(pybind11.__path__[0], "include") +if os.name == 'posix': # macOS or Linux + LIBDIR = sysconfig.get_config_var('LIBDIR') +elif os.name == 'nt': # Windows + LIBDIR = sysconfig.get_config_var('LIBDEST') + EMEWS = Extension('EMEWS', define_macros = [('MAJOR_VERSION', '1'), ('MINOR_VERSION', '0')], - include_dirs = ['/usr/local/lib/python3.9/site-packages/pybind11/include', './src', './src/mstl', './src/mstl/math2', './src/mstl/math2/algebra', './src/mstl/math2/analysis', './src/mstl/math2/spline', './src/mstl/physics'], - libraries = ['stdc++', 'm', 'gomp', 'python3'], - library_dirs = ['/usr/lib64'], - extra_compile_args = ['-std=c++17', '-fopenmp', '-fPIC', '-nostartfiles'], - extra_link_args = ['-shared'], + include_dirs = [LIBOMP_INCLUDE, PYBIND11_INCLUDE, './src', './src/mstl', './src/mstl/math2', './src/mstl/math2/algebra', './src/mstl/math2/analysis', './src/mstl/math2/spline', './src/mstl/physics'], + # libraries = ['stdc++', 'm', 'gomp', 'python3'], + library_dirs = [LIBDIR], + extra_compile_args = ['-std=c++17', '-fPIC', '-nostartfiles'], + # extra_link_args = ['-shared'], sources = ['./src/EMEWS.cpp', './src/adiabatic_basis.cpp', './src/eigenvalues.cpp', './src/flavour_basis.cpp', './src/input_class.EMEWS.cpp', './src/jacobians.cpp', './src/mixing_angles.cpp', './src/output.EMEWS.cpp', './src/output_matrix.EMEWS.cpp', './src/parameters.cpp', './src/potentials.cpp', './src/RK.EMEWS.cpp', './src/update.EMEWS.cpp', './src/mstl/errors2.cpp', './src/mstl/messages.cpp', './src/mstl/miscellaneous functions.cpp', './src/mstl/stdarg2.cpp', './src/mstl/math2/algebra/column and row vectors.cpp', './src/mstl/math2/algebra/linear algebra.cpp', './src/mstl/math2/algebra/mmatrix.cpp', './src/mstl/math2/analysis/algorithm3.cpp', './src/mstl/math2/analysis/complex2.cpp', './src/mstl/math2/analysis/derivative.cpp', './src/mstl/math2/analysis/polynomial.cpp', './src/mstl/math2/analysis/roots.cpp', './src/mstl/math2/analysis/runge kutta.cpp', './src/mstl/math2/analysis/special functions.cpp', './src/mstl/math2/spline/discontinuous.cpp', './src/mstl/math2/spline/interpolation data.cpp', './src/mstl/physics/units and constants.cpp']) setup_keywords['ext_modules'] = [EMEWS] From e05975e6836216aa81fbf0a74878336b3ad93df7 Mon Sep 17 00:00:00 2001 From: Jost Migenda Date: Fri, 7 Jun 2024 20:27:13 +0100 Subject: [PATCH 2/3] mstl: delete unary_function and binary_function Both were removed in C++17, so cause errors when compiling with the latest clang version. They can usually just be deleted, see e.g. https://stackoverflow.com/questions/63577103/what-is-an-equivalent-replacement-for-stdunary-function-in-c17 https://devblogs.microsoft.com/cppblog/c17-feature-removals-and-deprecations/#:~:text=if%20you%20have%20classes%20deriving,eliminate%20the%20inheritance --- src/mstl/functional2.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/mstl/functional2.h b/src/mstl/functional2.h index 7aaa75a..4f33f50 100644 --- a/src/mstl/functional2.h +++ b/src/mstl/functional2.h @@ -195,10 +195,10 @@ template struct nullary_member_function : public nullary_function { typedef CType class_type;}; -template struct unary_member_function : public std::unary_function +template struct unary_member_function { typedef CType class_type;}; -template struct binary_member_function : public std::binary_function +template struct binary_member_function { typedef CType class_type;}; template struct ternary_member_function : public ternary_function @@ -328,19 +328,19 @@ class pointer_to_quaternary_member_function : public quaternary_member_function< // ******************************************************* // ******************************************************* -template struct equal : public std::unary_function{ +template struct equal { Type operator()(const Type &x) const { return x;} }; -template struct plus : public std::unary_function{ +template struct plus { Type operator()(const Type &x) const { return x;} }; -template struct square : public std::unary_function{ +template struct square { Type operator()(const Type &x) const { return x*x;} }; -template struct cube : public std::unary_function{ +template struct cube { Type operator()(const Type &x) const { return x*x*x;} }; @@ -348,7 +348,7 @@ template struct cube : public std::unary_function{ // ******************************************************* // ******************************************************* -template struct exclusive_or : public std::binary_function{ +template struct exclusive_or { Type operator()(const Type &x,const Type &y) const { return x^y;} }; @@ -364,15 +364,13 @@ public nullary_function }; template -class UNARYFUNCTORBASE : -public std::unary_function +class UNARYFUNCTORBASE { public : virtual ~UNARYFUNCTORBASE(void){;} virtual RType operator()(AType) const =0; }; template -class BINARYFUNCTORBASE : -public std::binary_function +class BINARYFUNCTORBASE { public : virtual ~BINARYFUNCTORBASE(void){;} virtual RType operator()(AType1,AType2) const =0; }; From 3cfd9d54b88990a9db84e7901c9edfa0b82dcbd1 Mon Sep 17 00:00:00 2001 From: Jost Migenda Date: Fri, 7 Jun 2024 20:53:40 +0100 Subject: [PATCH 3/3] =?UTF-8?q?mstl:=20Replace=20gamma=20with=20lgamma=20g?= =?UTF-8?q?amma=20is=20a=20non-standard=20extension=20in=20the=20GNU=20lib?= =?UTF-8?q?c,=20see=20https://www.gnu.org/software/libc/manual/html=5Fnode?= =?UTF-8?q?/Special-Functions.html#index-gamma=20And=20being=20non-standar?= =?UTF-8?q?d,=20it=20may=20give=20different=20results=20on=20different=20s?= =?UTF-8?q?ystems,=20see=20https://stackoverflow.com/questions/18116376/wh?= =?UTF-8?q?at-is-the-definition-for-gammadouble-x-and-why-is-it-different-?= =?UTF-8?q?on-two-gcc-ve=20=F0=9F=98=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mstl/math2/analysis/special functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mstl/math2/analysis/special functions.cpp b/src/mstl/math2/analysis/special functions.cpp index 976957f..2d84995 100644 --- a/src/mstl/math2/analysis/special functions.cpp +++ b/src/mstl/math2/analysis/special functions.cpp @@ -37,7 +37,7 @@ double Gamma(double N){ return tgamma(N);} }*/ // see Numerical Recipes for the algorithm -double logGamma(double N){ return gamma(N);} +double logGamma(double N){ return lgamma(N);} /*{ if(N<0.){ throw NEGATIVE_NUMBER("logGamma(double)");} double ser; double n=N; double c[6]={ 76.18009172947146,-86.50532032941677, 24.01409824083091,