diff --git a/CMakeLists.txt b/CMakeLists.txt index 83f1d7357..80eaaeb3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ SET(LIB ${CMAKE_SOURCE_DIR}/lib) SET(BIN ${CMAKE_SOURCE_DIR}/bin) SET(MOD ${CMAKE_SOURCE_DIR}/include) #SET(TEST ${CMAKE_SOURCE_DIR}/test) -SET(PY ${CMAKE_SOURCE_DIR}/python/swiftest) +SET(PY ${CMAKE_SOURCE_DIR}/src/python) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB}) @@ -93,8 +93,9 @@ FUNCTION(REPLACE_VERSION IN_FILE LANGUAGE) STRING(FIND "${LINE}" "version=" LINE_HAS_VER) IF (LINE_HAS_VER GREATER_EQUAL 0) # This is the version line FILE(APPEND ${IN_FILE} " version='${CMAKE_PROJECT_VERSION}',\n") - ELSE () - FILE(APPEND ${IN_FILE} "${LINE}\n") # No match. Put this line back like we found it + ELSE () # No match. Put this line back like we found it + STRING(REPLACE ";" "\n" LINE "${LINE}") # Fixes an issue when parsing the list that defines the pydriver extension module + FILE(APPEND ${IN_FILE} "${LINE}\n") ENDIF () ENDIF () ENDFOREACH () diff --git a/Dockerfile b/Dockerfile index 3a4d5ce6a..2962229ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,6 +76,7 @@ RUN cd netcdf-fortran-4.6.1 && \ make install FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_driver +SHELL ["/bin/bash", "--login", "-c"] COPY --from=build_deps /usr/local/. /usr/local/ ENV INSTALL_DIR="/usr/local" ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx" @@ -106,12 +107,22 @@ ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort" ENV FFLAGS="-fPIC -standard-semantics" ENV LDFLAGS="-L/usr/local/lib" ENV LIBS="-lhdf5_hl -lhdf5 -lz" +ENV PATH /root/miniconda3/bin:$PATH + COPY ./cmake/ /swiftest/cmake/ COPY ./src/ /swiftest/src/ COPY ./CMakeLists.txt /swiftest/ COPY ./python/ /swiftest/python/ COPY ./version.txt /swiftest/ -RUN cd swiftest && \ +RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh && \ + /usr/bin/bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh -b && \ + /root/miniconda3/bin/conda init bash && \ + source /root/.bashrc && conda update --all -y && \ + conda install conda-libmamba-solver -y && \ + conda config --set solver libmamba && \ + conda install -c conda-forge numpy -y&& \ + conda install -c anaconda cython -y && \ + cd swiftest && \ cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ -DMACHINE_CODE_VALUE=${MACHINE_CODE_VALUE} \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ @@ -119,7 +130,13 @@ RUN cd swiftest && \ -DBUILD_SHARED_LIBS=OFF \ ${EXTRA_CMAKE_OPTIONS} && \ cmake --build build && \ - cmake --install build + cmake --install build && \ + mv bin/CMakeFiles/swiftest.dir/__/python/swiftest/f2py/driver.f90.o python/swiftest/f2py/ && \ + mv bin/CMakeFiles/swiftest.dir/__/python/swiftest/f2py/pydriver.f90.o python/swiftest/f2py/ + +RUN cd swiftest/python/swiftest/f2py && \ + python setup.py build_ext --inplace + # This build target creates a container that executes just the driver program FROM ubuntu:20.04 as driver diff --git a/python/swiftest/f2py/pydriver.f90 b/python/swiftest/f2py/pydriver.f90 deleted file mode 100644 index fbfbbbe78..000000000 --- a/python/swiftest/f2py/pydriver.f90 +++ /dev/null @@ -1,24 +0,0 @@ -subroutine driver(integrator, param_file_name, display_style) - - !! author: David A. Minton - !! - !! Driver program for the Swiftest integrators. Unlike the earlier Swift and Swifter drivers, in Swiftest all integrators - !! are run from this single program. - !! - !! Adapted from Swifter by David E. Kaufmann's Swifter driver programs swifter_[bs,helio,ra15,rmvs,symba,tu4,whm].f90 - !! Adapted from Hal Levison and Martin Duncan's Swift driver programs - use swiftest, only : swiftest_driver - implicit none - - ! Arguments - character(len=:), intent(in), allocatable :: integrator !! Symbolic code of the requested integrator - character(len=:), intent(in), allocatable :: param_file_name !! Name of the input parameters file - character(len=:), intent(in), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD") - !f2py intent(in) integrator - !f2py intent(in) param_file_name - !f2py intent(in) display_style - - call swiftest_driver(integrator, param_file_name, display_style) - - return -end subroutine driver \ No newline at end of file diff --git a/python/swiftest/requirements.txt b/python/swiftest/requirements.txt deleted file mode 100644 index 4ac7c5101..000000000 --- a/python/swiftest/requirements.txt +++ /dev/null @@ -1,16 +0,0 @@ - python>=3.8 - numpy>=1.24.3 - pandas>=1.5.3 - scipy>=1.10.1 - xarray>=2022.11.0 - dask>=2022.1 - bottleneck>=1.3.5 - h5netcdf>=1.0.2 - netcdf4>=1.6.2 - matplotlib>=3.7.1 - astropy>=5.1 - astroquery>=0.4.6 - tqdm>=4.65.0 - x264>=1!157.20191217 - ffmpeg>=4.3.2 - conda-build \ No newline at end of file diff --git a/python/swiftest/setup.py b/python/swiftest/setup.py deleted file mode 100644 index 3a3c2a674..000000000 --- a/python/swiftest/setup.py +++ /dev/null @@ -1,17 +0,0 @@ -""" - Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh - This file is part of Swiftest. - Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with Swiftest. - If not, see: https://www.gnu.org/licenses. -""" - -from setuptools import setup, find_packages - -setup(name='swiftest', - version='2023.08.00', - author='David A. Minton', - packages=find_packages()) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c07efdd4..d15ef2ffb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,6 +48,8 @@ SET(STRICT_MATH_FILES ${SRC}/whm/whm_gr.f90 ${SRC}/whm/whm_kick.f90 ${SRC}/whm/whm_step.f90 + ${PY}/pydriver/src/driver.f90 + ${PY}/pydriver/src/pydriver.f90 ) SET(FAST_MATH_FILES @@ -81,7 +83,6 @@ SET(FAST_MATH_FILES ${SRC}/symba/symba_util.f90 ${SRC}/walltime/walltime_implementations.f90 ${SRC}/whm/whm_util.f90 - ) SET(COARRAY_FILES @@ -131,7 +132,6 @@ IF(USE_COARRAY) ENDIF(USE_COARRAY) - #Set strict vs fast math flags STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT) IF(BT STREQUAL "RELEASE" OR BT STREQUAL "PROFILE") @@ -176,9 +176,14 @@ ELSE() SET(CMAKE_INSTALL_PREFIX /usr/local) ENDIF(WIN32) INSTALL(TARGETS ${SWIFTEST_DRIVER} ${SWIFTEST_LIBRARY} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + INCLUDES DESTINATION include ) -INSTALL(FILES ${MOD}/swiftest.mod DESTINATION include) +INSTALL(TARGETS ${SWIFTEST_LIBRARY} + LIBRARY DESTINATION "${PY}/pydriver/lib" + ARCHIVE DESTINATION "${PY}/pydriver/lib" + INCLUDES DESTINATION "${PY}pydriver/include" + ) diff --git a/src/python/pydriver/src/driver.f90 b/src/python/pydriver/src/driver.f90 new file mode 100644 index 000000000..fade662d3 --- /dev/null +++ b/src/python/pydriver/src/driver.f90 @@ -0,0 +1,26 @@ +module pydriver_module + use swiftest, only : swiftest_driver + implicit none + + contains + subroutine driver(integrator, param_file_name, display_style) + + !! author: David A. Minton + !! + !! Driver program for the Swiftest integrators. Unlike the earlier Swift and Swifter drivers, in Swiftest all integrators + !! are run from this single program. + !! + !! Adapted from Swifter by David E. Kaufmann's Swifter driver programs swifter_[bs,helio,ra15,rmvs,symba,tu4,whm].f90 + !! Adapted from Hal Levison and Martin Duncan's Swift driver programs + implicit none + + ! Arguments + character(len=:), intent(in), allocatable :: integrator !! Symbolic code of the requested integrator + character(len=:), intent(in), allocatable :: param_file_name !! Name of the input parameters file + character(len=:), intent(in), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD") + + call swiftest_driver(integrator, param_file_name, display_style) + + return + end subroutine driver +end module pydriver_module \ No newline at end of file diff --git a/src/python/pydriver/src/pydriver.f90 b/src/python/pydriver/src/pydriver.f90 new file mode 100644 index 000000000..2ab035387 --- /dev/null +++ b/src/python/pydriver/src/pydriver.f90 @@ -0,0 +1,9 @@ +module pydriver_interface + use iso_c_binding, only : c_char + use pydriver_module, only : driver + implicit none + contains + subroutine c_driver(integrator, param_file_name, display_style) bind(c) + character(kind=c_char) :: integrator(:), param_file_name(:), display_style(:) + end subroutine c_driver +end module pydriver_interface diff --git a/src/python/setup.py b/src/python/setup.py new file mode 100644 index 000000000..3ec0cb128 --- /dev/null +++ b/src/python/setup.py @@ -0,0 +1,35 @@ +""" + Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY + without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" + +from setuptools import setup, find_packages, Extension +from Cython.Build import cythonize +import os + +# Build the pydriver extension that allows us to run the Fortran driver as a Python module. +root_dir = 'pydriver' +include_dir = os.path.join(root_dir,'include') +lib_dir = os.path.join(root_dir,'lib') +pydriver_extension = [Extension('swiftest.pydriver', + [os.path.join(root_dir,'pydriver.pyx')], + extra_compile_args=['-fPIC', '-O3'], + library_dirs=[lib_dir], + libraries=['swiftest','netcdff','netcdf','hdf5_hl','hdf5','m','z'], + include_dirs=[include_dir], + )] + +setup(name='swiftest', + version='2023.08.00', + author='David A. Minton', + author_email='daminton@purdue.edu', + url='https://github.itap.purdue.edu/MintonGroup/swiftest', + ext_modules = cythonize(pydriver_extension), + packages=find_packages()) diff --git a/python/swiftest/swiftest/__init__.py b/src/python/swiftest/__init__.py similarity index 100% rename from python/swiftest/swiftest/__init__.py rename to src/python/swiftest/__init__.py diff --git a/python/swiftest/swiftest/constants.py b/src/python/swiftest/constants.py similarity index 100% rename from python/swiftest/swiftest/constants.py rename to src/python/swiftest/constants.py diff --git a/python/swiftest/swiftest/init_cond.py b/src/python/swiftest/init_cond.py similarity index 100% rename from python/swiftest/swiftest/init_cond.py rename to src/python/swiftest/init_cond.py diff --git a/python/swiftest/swiftest/io.py b/src/python/swiftest/io.py similarity index 100% rename from python/swiftest/swiftest/io.py rename to src/python/swiftest/io.py diff --git a/python/swiftest/swiftest/simulation_class.py b/src/python/swiftest/simulation_class.py similarity index 100% rename from python/swiftest/swiftest/simulation_class.py rename to src/python/swiftest/simulation_class.py diff --git a/python/swiftest/swiftest/tool.py b/src/python/swiftest/tool.py similarity index 100% rename from python/swiftest/swiftest/tool.py rename to src/python/swiftest/tool.py diff --git a/python/swiftest/swiftest/visualize.py b/src/python/swiftest/visualize.py similarity index 100% rename from python/swiftest/swiftest/visualize.py rename to src/python/swiftest/visualize.py diff --git a/python/swiftest/tests/test_suite.py b/src/python/tests/test_suite.py similarity index 100% rename from python/swiftest/tests/test_suite.py rename to src/python/tests/test_suite.py