Merge branch 'master' of bitbucket.org:glavaux/cosmotool

This commit is contained in:
Guilhem Lavaux 2021-10-15 18:39:01 +02:00
commit 533d8d0630
15 changed files with 295 additions and 257 deletions

View File

@ -70,8 +70,8 @@ SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A toolbox for impatient cosmologists")
SET(CPACK_PACKAGE_VENDOR "Guilhem Lavaux") SET(CPACK_PACKAGE_VENDOR "Guilhem Lavaux")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENCE_CeCILL_V2") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENCE_CeCILL_V2")
SET(CPACK_PACKAGE_VERSION_MAJOR "1") SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "2") SET(CPACK_PACKAGE_VERSION_MINOR "3")
SET(CPACK_PACKAGE_VERSION_PATCH "2${EXTRA_VERSION}") SET(CPACK_PACKAGE_VERSION_PATCH "0${EXTRA_VERSION}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CosmoToolbox-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CosmoToolbox-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
SET(CPACK_STRIP_FILES "lib/libCosmoTool.so") SET(CPACK_STRIP_FILES "lib/libCosmoTool.so")
SET(CPACK_SOURCE_IGNORE_FILES SET(CPACK_SOURCE_IGNORE_FILES

View File

@ -86,6 +86,7 @@ include sample/testSmooth.cpp
include sample/test_cosmopower.cpp include sample/test_cosmopower.cpp
include sample/test_fft_calls.cpp include sample/test_fft_calls.cpp
include sample/test_healpix_calls.cpp include sample/test_healpix_calls.cpp
include sample/test_special.cpp
include sample/testkd.cpp include sample/testkd.cpp
include sample/testkd2.cpp include sample/testkd2.cpp
include sample/testkd3.cpp include sample/testkd3.cpp
@ -167,3 +168,4 @@ include src/tf_fit.hpp
include src/yorick.hpp include src/yorick.hpp
include src/yorick_nc3.cpp include src/yorick_nc3.cpp
include src/yorick_nc4.cpp include src/yorick_nc4.cpp
include src/special_math.hpp

View File

@ -1,8 +1,10 @@
python: python:
- 3.7
- 3.8
- 3.9 - 3.9
- 3.8
- 3.7
numpy: numpy:
- 1.11
- 1.19 - 1.19
gsl:
- 2.4

View File

@ -1,48 +1,50 @@
package: package:
name: cosmotool name: cosmotool
version: "1.2.2" version: "1.3.0"
source: source:
git_rev: 03033b6 git_rev: a86c9a8
git_url: https://bitbucket.org/glavaux/cosmotool git_url: https://bitbucket.org/glavaux/cosmotool
requirements: requirements:
build: build:
- numpy >=1.11 - python # [build_platform != target_platform]
- cross-python_{{ target_platform }} # [build_platform != target_platform]
- cython # [build_platform != target_platform]
- numpy # [build_platform != target_platform]
- {{ compiler('c') }} - {{ compiler('c') }}
- {{ compiler('cxx') }} - {{ compiler('cxx') }}
- python - llvm-openmp # [osx]
- setuptools - libgomp # [linux]
- cython
- healpy
- numexpr
- cffi
- pyfftw
- gsl
- h5py
host: host:
- python - python
- pip
- numpy
- pkgconfig
- numexpr - numexpr
- cython - cython
- healpy - healpy
- cffi - cffi
- pyfftw - pyfftw
- gsl - gsl {{ gsl }}
- h5py - h5py
run: run:
- numpy
- python - python
- {{ pin_compatible('numpy') }}
- healpy - healpy
- numexpr - numexpr
- cffi - cffi
- pyfftw - pyfftw
- h5py - h5py
- {{ pin_compatible('gsl') }}
- llvm-openmp
test: test:
imports: imports:
- cosmotool - cosmotool
requires:
- pip
about: about:
home: https://bitbucket.org/glavaux/cosmotool home: https://bitbucket.org/glavaux/cosmotool

View File

@ -8,7 +8,7 @@ SET(GENGETOPT_URL "ftp://ftp.gnu.org/gnu/gengetopt/gengetopt-2.22.5.tar.gz" CACH
SET(HDF5_URL "https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.18/src/hdf5-1.8.18.tar.bz2" CACHE STRING "URL to download HDF5 from") SET(HDF5_URL "https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.18/src/hdf5-1.8.18.tar.bz2" CACHE STRING "URL to download HDF5 from")
SET(NETCDF_URL "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.5.0.tar.gz" CACHE STRING "URL to download NetCDF from") SET(NETCDF_URL "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.5.0.tar.gz" CACHE STRING "URL to download NetCDF from")
SET(NETCDFCXX_URL "https://github.com/Unidata/netcdf-cxx4/archive/v4.3.0.tar.gz" CACHE STRING "URL to download NetCDF-C++ from") SET(NETCDFCXX_URL "https://github.com/Unidata/netcdf-cxx4/archive/v4.3.0.tar.gz" CACHE STRING "URL to download NetCDF-C++ from")
SET(BOOST_URL "http://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.gz/download" CACHE STRING "URL to download Boost from") SET(BOOST_URL "https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.tar.bz2" CACHE STRING "URL to download Boost from")
SET(GSL_URL "ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz" CACHE STRING "URL to download GSL from ") SET(GSL_URL "ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz" CACHE STRING "URL to download GSL from ")
mark_as_advanced(FFTW_URL EIGEN_URL HDF5_URL NETCDF_URL BOOST_URL GSL_URL) mark_as_advanced(FFTW_URL EIGEN_URL HDF5_URL NETCDF_URL BOOST_URL GSL_URL)
@ -234,6 +234,7 @@ if (INTERNAL_BOOST)
ExternalProject_Add(boost ExternalProject_Add(boost
URL ${BOOST_URL} URL ${BOOST_URL}
PREFIX ${BUILD_PREFIX}/boost-prefix PREFIX ${BUILD_PREFIX}/boost-prefix
URL_HASH MD5=da07ca30dd1c0d1fdedbd487efee01bd
CONFIGURE_COMMAND CONFIGURE_COMMAND
${BOOST_SOURCE_DIR}/bootstrap.sh --prefix=${CMAKE_BINARY_DIR}/ext_build/boost ${BOOST_SOURCE_DIR}/bootstrap.sh --prefix=${CMAKE_BINARY_DIR}/ext_build/boost
BUILD_IN_SOURCE 1 BUILD_IN_SOURCE 1

57
external/patch-omptl vendored
View File

@ -1,6 +1,6 @@
diff -ur omptl.orig/omptl_algorithm omptl/omptl_algorithm diff -ur omptl.old/omptl_algorithm omptl/omptl_algorithm
--- omptl.orig/omptl_algorithm 2017-01-16 14:58:37.996690639 +0100 --- omptl.old/omptl_algorithm 2012-04-22 16:29:41.000000000 +0200
+++ omptl/omptl_algorithm 2017-01-16 15:00:26.678641720 +0100 +++ omptl/omptl_algorithm 2021-06-20 15:40:29.000000000 +0200
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
#define OMPTL_ALGORITHM 1 #define OMPTL_ALGORITHM 1
@ -22,9 +22,9 @@ diff -ur omptl.orig/omptl_algorithm omptl/omptl_algorithm
#endif #endif
#endif /* OMPTL_ALGORITHM */ #endif /* OMPTL_ALGORITHM */
diff -ur omptl.orig/omptl_algorithm_par.h omptl/omptl_algorithm_par.h diff -ur omptl.old/omptl_algorithm_par.h omptl/omptl_algorithm_par.h
--- omptl.orig/omptl_algorithm_par.h 2017-01-16 14:58:37.996690639 +0100 --- omptl.old/omptl_algorithm_par.h 2012-04-22 16:29:41.000000000 +0200
+++ omptl/omptl_algorithm_par.h 2017-01-16 14:59:57.974126410 +0100 +++ omptl/omptl_algorithm_par.h 2021-06-20 15:40:50.000000000 +0200
@@ -21,8 +21,8 @@ @@ -21,8 +21,8 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
@ -36,9 +36,18 @@ diff -ur omptl.orig/omptl_algorithm_par.h omptl/omptl_algorithm_par.h
#include <iterator> #include <iterator>
diff -ur omptl.orig/omptl_numeric omptl/omptl_numeric @@ -1700,7 +1700,7 @@
--- omptl.orig/omptl_numeric 2017-01-16 14:58:37.996690639 +0100
+++ omptl/omptl_numeric 2017-01-16 15:00:57.051186974 +0100 std::vector<char> pivot_used(pivots.size(), false); // can't be bool due to parallel write
- const unsigned max_depth = std::floor(std::tr1::log2(P));
+ const unsigned max_depth = unsigned(std::floor(std::log2(P)));
assert(1u << max_depth <= P);
for (unsigned i = 0; i < max_depth; ++i)
{
diff -ur omptl.old/omptl_numeric omptl/omptl_numeric
--- omptl.old/omptl_numeric 2012-04-22 16:29:41.000000000 +0200
+++ omptl/omptl_numeric 2021-06-20 15:40:29.000000000 +0200
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
#define OMPTL_NUMERIC 1 #define OMPTL_NUMERIC 1
@ -63,9 +72,9 @@ diff -ur omptl.orig/omptl_numeric omptl/omptl_numeric
+#include "omptl_numeric_extensions.h" +#include "omptl_numeric_extensions.h"
#endif /* OMPTL_NUMERIC */ #endif /* OMPTL_NUMERIC */
diff -ur omptl.orig/omptl_numeric_extensions.h omptl/omptl_numeric_extensions.h diff -ur omptl.old/omptl_numeric_extensions.h omptl/omptl_numeric_extensions.h
--- omptl.orig/omptl_numeric_extensions.h 2017-01-16 14:58:37.996690639 +0100 --- omptl.old/omptl_numeric_extensions.h 2012-04-22 16:29:41.000000000 +0200
+++ omptl/omptl_numeric_extensions.h 2017-01-16 14:59:21.549472508 +0100 +++ omptl/omptl_numeric_extensions.h 2021-06-20 15:40:29.000000000 +0200
@@ -51,9 +51,9 @@ @@ -51,9 +51,9 @@
} // namespace } // namespace
@ -78,9 +87,9 @@ diff -ur omptl.orig/omptl_numeric_extensions.h omptl/omptl_numeric_extensions.h
#endif #endif
namespace omptl namespace omptl
diff -ur omptl.orig/omptl_numeric_par.h omptl/omptl_numeric_par.h diff -ur omptl.old/omptl_numeric_par.h omptl/omptl_numeric_par.h
--- omptl.orig/omptl_numeric_par.h 2017-01-16 14:58:37.996690639 +0100 --- omptl.old/omptl_numeric_par.h 2012-04-22 16:29:41.000000000 +0200
+++ omptl/omptl_numeric_par.h 2017-01-16 14:59:36.397739066 +0100 +++ omptl/omptl_numeric_par.h 2021-06-20 15:40:29.000000000 +0200
@@ -23,8 +23,8 @@ @@ -23,8 +23,8 @@
#include <functional> #include <functional>
#include <iterator> #include <iterator>
@ -92,15 +101,15 @@ diff -ur omptl.orig/omptl_numeric_par.h omptl/omptl_numeric_par.h
namespace omptl namespace omptl
{ {
diff -ur omptl.orig/omptl_algorithm_par.h omptl/omptl_algorithm_par.h diff -ur omptl.old/omptl_tools.h omptl/omptl_tools.h
--- omptl.orig/omptl_algorithm_par.h 2021-05-09 14:26:47.227632829 +0300 --- omptl.old/omptl_tools.h 2012-04-22 16:29:41.000000000 +0200
+++ omptl/omptl_algorithm_par.h 2021-05-09 14:27:02.815744567 +0300 +++ omptl/omptl_tools.h 2021-06-20 15:40:42.000000000 +0200
@@ -1700,7 +1700,7 @@ @@ -25,7 +25,7 @@
#include <climits>
#include <iterator>
std::vector<char> pivot_used(pivots.size(), false); // can't be bool due to parallel write -#include <tr1/cmath>
+#include <cmath>
- const unsigned max_depth = std::floor(std::tr1::log2(P)); namespace omptl
+ const unsigned max_depth = unsigned(std::floor(std::tr1::log2(P)));
assert(1u << max_depth <= P);
for (unsigned i = 0; i < max_depth; ++i)
{ {

View File

@ -116,8 +116,17 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cosmotool/config.py.in ${CMAKE_CURREN
INSTALL(TARGETS INSTALL(TARGETS
${ct_TARGETS} ${ct_TARGETS}
COMPONENT python
LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/cosmotool LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/cosmotool
) )
INSTALL(DIRECTORY cosmotool ${CMAKE_CURRENT_BINARY_DIR}/cosmotool DESTINATION ${PYTHON_SITE_PACKAGES} INSTALL(DIRECTORY cosmotool ${CMAKE_CURRENT_BINARY_DIR}/cosmotool
COMPONENT python DESTINATION ${PYTHON_SITE_PACKAGES}
FILES_MATCHING PATTERN "*.py") FILES_MATCHING PATTERN "*.py")
add_custom_target(
python-install
DEPENDS ${ct_TARGETS}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=python -P
"${CMAKE_BINARY_DIR}/cmake_install.cmake")

View File

@ -247,6 +247,9 @@ class PySimulationAdaptor(PySimulationBase):
def __init__(self,sim): def __init__(self,sim):
self.simu = sim self.simu = sim
def getNumParticles(self):
return self.simu.numParticles
def getBoxsize(self): def getBoxsize(self):
return self.simu.BoxSize return self.simu.BoxSize

View File

@ -533,12 +533,13 @@ cdef void INTERNAL_project_cic_with_mass_periodic(DTYPE_t[:,:,:] g,
def project_cic(npx.ndarray[DTYPE_t, ndim=2] x not None, npx.ndarray[DTYPE_t, ndim=1] mass, int Ngrid, def project_cic(npx.ndarray[DTYPE_t, ndim=2] x not None, npx.ndarray[DTYPE_t, ndim=1] mass, int Ngrid,
double Lbox, bool periodic = False, centered=True): double Lbox, bool periodic = False, centered=True, output=None):
""" """
project_cic(x array (N,3), mass (may be None), Ngrid, Lbox, periodict, centered=True) project_cic(x array (N,3), mass (may be None), Ngrid, Lbox, periodict, centered=True, output=None)
This function does a Cloud-In-Cell projection of a 3d unstructured dataset. First argument is a Nx3 array of coordinates. This function does a Cloud-In-Cell projection of a 3d unstructured dataset. First argument is a Nx3 array of coordinates.
Second argument is an optinal mass. Ngrid is the size output grid and Lbox is the physical size of the grid. Second argument is an optinal mass. Ngrid is the size output grid and Lbox is the physical size of the grid.
if output is not None, it must be a numpy array with dimension NgridxNgridxNgrid. The result will be accumulated in that array.
""" """
cdef npx.ndarray[DTYPE_t, ndim=3] g cdef npx.ndarray[DTYPE_t, ndim=3] g
cdef double shifter cdef double shifter
@ -558,7 +559,13 @@ def project_cic(npx.ndarray[DTYPE_t, ndim=2] x not None, npx.ndarray[DTYPE_t, nd
if mass is not None and mass.shape[0] != x.shape[0]: if mass is not None and mass.shape[0] != x.shape[0]:
raise ValueError("Mass array and coordinate array must have the same number of elements") raise ValueError("Mass array and coordinate array must have the same number of elements")
if output is None:
g = np.zeros((Ngrid,Ngrid,Ngrid),dtype=DTYPE) g = np.zeros((Ngrid,Ngrid,Ngrid),dtype=DTYPE)
else:
if type(output) != np.ndarray:
raise ValueError("Invalid array type")
g = output
cdef DTYPE_t[:,:,:] d_g = g cdef DTYPE_t[:,:,:] d_g = g
cdef DTYPE_t[:,:] d_x = x cdef DTYPE_t[:,:] d_x = x

View File

@ -1,4 +1,4 @@
numpy numpy<1.19
cffi cffi
numexpr numexpr
pyfftw pyfftw

View File

@ -168,10 +168,16 @@ class BuildCMakeExt(build_ext):
# Below is just an example set of arguments for building Blender as a Python module # Below is just an example set of arguments for building Blender as a Python module
compilers=[] compilers=[]
if "CC" in os.environ: fill_up_settings=[
compilers.append('-DCMAKE_C_COMPILER=' + os.environ["CC"]) ("CMAKE_C_COMPILER", "CC"),
if "CXX" in os.environ: ("CMAKE_CXX_COMPILER", "CXX"),
compilers.append("-DCMAKE_CXX_COMPILER=" + os.environ["CXX"]) ("CMAKE_C_FLAGS", "CFLAGS"),
("CMAKE_EXE_LINKER_FLAGS_INIT", "LDFLAGS"),
("CMAKE_SHARED_LINKER_FLAGS_INIT", "LDFLAGS"),
("CMAKE_MODULE_LINKER_FLAGS_INIT", "LDFLAGS")]
for cmake_flag, os_flag in fill_up_settings:
if os_flag in os.environ:
compilers.append(f"-D{cmake_flag}={os.environ[os_flag]}")
self.spawn(['cmake', '-H'+SOURCE_DIR, '-B'+self.build_temp, self.spawn(['cmake', '-H'+SOURCE_DIR, '-B'+self.build_temp,
'-DENABLE_OPENMP=ON','-DINTERNAL_BOOST=ON','-DINTERNAL_EIGEN=ON', '-DENABLE_OPENMP=ON','-DINTERNAL_BOOST=ON','-DINTERNAL_EIGEN=ON',
@ -223,7 +229,7 @@ class BuildCMakeExt(build_ext):
CosmoTool_extension = CMakeExtension(name="cosmotool") CosmoTool_extension = CMakeExtension(name="cosmotool")
setup(name='cosmotool', setup(name='cosmotool',
version='1.2.2', version='1.3.0',
packages=["cosmotool"], packages=["cosmotool"],
package_dir={'cosmotool': 'python/cosmotool'}, package_dir={'cosmotool': 'python/cosmotool'},
install_requires=['numpy','cffi','numexpr','pyfftw','h5py'], install_requires=['numpy','cffi','numexpr','pyfftw','h5py'],

View File

@ -38,6 +38,7 @@ if (HDF5_FOUND)
h5_readFlash.cpp h5_readFlash.cpp
loadFlash.cpp loadFlash.cpp
) )
add_dependencies(CosmoHDF5 ${cosmotool_DEPS})
set_property(TARGET CosmoHDF5 PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}) set_property(TARGET CosmoHDF5 PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
target_include_directories(CosmoHDF5 BEFORE PRIVATE ${HDF5_INCLUDE_DIR}) target_include_directories(CosmoHDF5 BEFORE PRIVATE ${HDF5_INCLUDE_DIR})
else(HDF5_FOUND) else(HDF5_FOUND)

View File

@ -426,7 +426,7 @@ namespace CosmoTool {
#define CTOOL_HDF5_INSERT_ELEMENT(r, STRUCT, element) \ #define CTOOL_HDF5_INSERT_ELEMENT(r, STRUCT, element) \
{ \ { \
::CosmoTool::get_hdf5_data_type<BOOST_PP_TUPLE_ELEM(2, 0, element)> t; \ ::CosmoTool::get_hdf5_data_type<BOOST_PP_TUPLE_ELEM(2, 0, element)> t; \
position = HOFFSET(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \ long position = HOFFSET(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \
const char *field_name = BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, element)); \ const char *field_name = BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, element)); \
type.insertMember(field_name, position, t.type()); \ type.insertMember(field_name, position, t.type()); \
} }
@ -439,7 +439,6 @@ namespace CosmoTool { \
\ \
TNAME() : type(sizeof(STRUCT)) \ TNAME() : type(sizeof(STRUCT)) \
{ \ { \
long position; \
BOOST_PP_SEQ_FOR_EACH(CTOOL_HDF5_INSERT_ELEMENT, STRUCT, ATTRIBUTES) \ BOOST_PP_SEQ_FOR_EACH(CTOOL_HDF5_INSERT_ELEMENT, STRUCT, ATTRIBUTES) \
} \ } \
\ \
@ -471,7 +470,6 @@ namespace CosmoTool { \
\ \
TNAME() : type(sizeof(STRUCT)) \ TNAME() : type(sizeof(STRUCT)) \
{ \ { \
long position; \
BOOST_PP_SEQ_FOR_EACH(CTOOL_HDF5_INSERT_ENUM_ELEMENT, STRUCT, ATTRIBUTES) \ BOOST_PP_SEQ_FOR_EACH(CTOOL_HDF5_INSERT_ENUM_ELEMENT, STRUCT, ATTRIBUTES) \
} \ } \
\ \

View File

@ -222,8 +222,7 @@ namespace CosmoTool
template<typename T> template<typename T>
void loadArray(const std::string& fname, void loadArray(const std::string& fname,
T*& array, uint32_t *& dimList, uint32_t& rank) T*& array, uint32_t *& dimList, uint32_t& rank);
throw (NoSuchFileException);
ProgressiveDoubleOutput saveDoubleArrayProgressive(const char *fname, uint32_t *dimList, uint32_t rank); ProgressiveDoubleOutput saveDoubleArrayProgressive(const char *fname, uint32_t *dimList, uint32_t rank);
}; };

View File

@ -224,7 +224,6 @@ namespace CosmoTool {
template<typename T> template<typename T>
void loadArray(const std::string& fname, void loadArray(const std::string& fname,
T*&array, uint32_t *&dimList, uint32_t& rank) T*&array, uint32_t *&dimList, uint32_t& rank)
throw (NoSuchFileException)
{ {
NcFile f(fname.c_str(), NcFile::read); NcFile f(fname.c_str(), NcFile::read);