Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ libnnpdf/REAMDE.md
libnnpdf/scripts/nnpdf.pc
libnnpdf/src/NNPDF/common.h
libnnpdf/src/NNPDF/config.h
evolven3fit/evolven3fit.cc

# Created by https://www.gitignore.io/api/macos

Expand Down
60 changes: 8 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ set(VERSION "\"4.0\"")
set(nnpdfcpp_VERSION 4.0)

# check for dependencies
find_package(PythonInterp 3 REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(LIBARCHIVE REQUIRED libarchive)
pkg_search_module(SQLITE3 REQUIRED sqlite3)
pkg_search_module(GSL REQUIRED gsl)
pkg_search_module(YAML REQUIRED yaml-cpp)


option(ENABLE_OPENMP "Enable openmp parallelism." OFF)
option(ENABLE_OPENMPI "Enable openMPI parallelism." OFF)
option(ENABLE_TESTS "Enable unit test" OFF)
option(ENABLE_ASAN "Enable ASAN" OFF)
option(ENABLE_DEAD_STRIP "Enable use of flag `-dead_strip-dylibs`" OFF)
option(NNPDF_DEV "n3fit and validphys in developer mode" ON)
set(PROFILE_PREFIX "" CACHE STRING "Where you store the 'data' folder. Default empty uses CMAKE_INSTALL_PREFIX/share/NNPDF.")

Expand All @@ -49,19 +45,6 @@ else (PROFILE_PREFIX)
set(PROFILE_PREFIX "${CMAKE_INSTALL_PREFIX}/share/NNPDF")
endif()

if (ENABLE_OPENMPI)
set(LIBNNPDF_HAVE_MPI "#define OPENMPI")
endif()

set(LIBNNPDF_HAVE_SSE "#define SSE_CONV")


if(ENABLE_OPENMP)
find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif(ENABLE_OPENMP)

# LHAPDF
find_program(LHAPDF_CONFIG lhapdf-config REQUIRED)
if (LHAPDF_CONFIG)
Expand Down Expand Up @@ -99,52 +82,25 @@ if (APFEL_CONFIG)
set(APFEL_LIBRARIES ${APFEL_LIBRARIES} CACHE STRING INTERNAL)
endif(APFEL_CONFIG)

set(DEFAULT_CXX_OPTIONS "-Wall -Wextra -march=nocona -mtune=haswell -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe")
set(DEFAULT_CXX_OPTIONS "-Wall -Wextra -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe")

#strip linker flags to avoid duplication of asan flags
string(REPLACE "-fsanitize=address" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
string(REPLACE "-fsanitize=address" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")

set(CMAKE_ALL_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")

#dead_strip_dylibs can cause issues, warn if we remove it
if(ENABLE_DEAD_STRIP)
if(NOT ${CMAKE_ALL_LINKER_FLAGS} MATCHES "-Wl,-dead_strip_dylibs")
message(WARNING "ENABLE_DEAD_STRIP was set true but there were no occurences of the flag `dead_strip_dylibs` found")
endif(NOT ${CMAKE_ALL_LINKER_FLAGS} MATCHES "-Wl,-dead_strip_dylibs")
else(ENABLE_DEAD_STRIP)
if(CMAKE_ALL_LINKER_FLAGS MATCHES "-Wl,-dead_strip_dylibs")
message(WARNING "removing all occurence of flag: `dead_strip_dylibs` (default behaviour). If you are sure this flag is required then ENABLE_DEAD_STRIP")
string(REPLACE "-Wl,-dead_strip_dylibs" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
string(REPLACE "-Wl,-dead_strip_dylibs" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
string(REPLACE "-Wl,-dead_strip_dylibs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
#executable linker flags get set later
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}" CACHE STRING "Flags used by the linker during the creation of modules during all build types" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" CACHE STRING "Flags used by the linker during the creation of shared libraries during all build types" FORCE)
endif(CMAKE_ALL_LINKER_FLAGS MATCHES "-Wl,-dead_strip_dylibs")
endif(ENABLE_DEAD_STRIP)

# Flags for ASAN
if(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "-fsanitize=address ${DEFAULT_CXX_OPTIONS} ${LHAPDF_CXX_FLAGS} ${APFEL_CXX_FLAGS} ${YAML_CFLAGS} ${SQLITE3_CFLAGS} ${GSL_CFLAGS} ${LIBARCHIVE_CFLAGS}" CACHE STRING "compile flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g" CACHE STRING "debug compile flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "linker flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "debug linker flags" FORCE)
else(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${DEFAULT_CXX_OPTIONS} ${LHAPDF_CXX_FLAGS} ${APFEL_CXX_FLAGS} ${YAML_CFLAGS} ${SQLITE3_CFLAGS} ${GSL_CFLAGS} ${LIBARCHIVE_CFLAGS}" CACHE STRING "compile flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g" CACHE STRING "debug compile flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "linker flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "debug linker flags" FORCE)
endif(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${DEFAULT_CXX_OPTIONS} ${LHAPDF_CXX_FLAGS} ${APFEL_CXX_FLAGS} ${YAML_CFLAGS} ${SQLITE3_CFLAGS} ${GSL_CFLAGS} ${LIBARCHIVE_CFLAGS}" CACHE STRING "compile flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g" CACHE STRING "debug compile flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "linker flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "debug linker flags" FORCE)

# libnnpdf configuration
add_subdirectory(libnnpdf)

# nnpdfcpp configuration
add_subdirectory(nnpdfcpp)

# evolven3fit
add_subdirectory(n3fit/evolven3fit)
add_subdirectory(evolven3fit)
install(FILES ${PROJECT_SOURCE_DIR}/validphys2/src/validphys/datafiles/theory.db DESTINATION ${PROFILE_PREFIX}/)

if(NNPDF_DEV)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-deps -e ${PROJECT_SOURCE_DIR})")
Expand Down
8 changes: 1 addition & 7 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,17 @@ requirements:
- recommonmark
- sphinx_rtd_theme >0.5
- sphinxcontrib-bibtex
- curio >=1.0
- pineappl >=0.6.2
- eko >=0.14.1
- fiatlux
- curio >=1.0 # reportengine uses it but it's not in its dependencies

test:
requires:
- hypothesis
- pytest
- coverage
- pytest-mpl
#Build dependencies for catch tests
- {{ compiler("cxx") }}
- {{ compiler("c") }}
- sysroot_linux-64==2.17 # [linux]
- swig ==3.0.10
- cmake

source_files:
- "*"
Expand Down
141 changes: 18 additions & 123 deletions doc/sphinx/source/get-started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ explained above, if the user has not already done so.
Installation from source on M1/M2 Macs
--------------------------------------

Installation on M1/M2 Macs is not directly supported, so everything needs to be
built manually. The following steps are required:
Installation on M1/M2 Macs directly with cmake is not directly supported.
If you install following this tutorial PDFs will need to be evolved with ``evolven3fit_new``.
Make sure you have a valid installation of ``pandoc`` available in your system:

1. Clone the repositories

Expand All @@ -255,153 +256,47 @@ built manually. The following steps are required:
cd nnpdfgit
git clone git@github.com:NNPDF/nnpdf.git
git clone git@github.com:NNPDF/binary-bootstrap.git
git clone https://github.com/scarrazza/apfel.git

2. Execute binary bootstrap to set the channels in ``.condarc``
2. Execute binary bootstrap to set the channels in ``.condarc`` and install miniconda.
Note: if you want to install some specific version of `miniconda<https://docs.conda.io/projects/miniconda/en/latest/>`_ instead it should work just the same.

.. code::

./binary-bootstrap/bootstrap.sh

3. Setup conda environment using python 3.9
3. Setup conda environment using python (we use in this example 3.10) and, if you don't have them yet, install ``lhapdf``, ``pandoc`` and ``sccache`` (for rust).

.. code::

conda create -n nnpdf-dev python=3.9
conda create -n nnpdf-dev python=3.10
conda activate nnpdf-dev
conda install lhapdf pandoc sccache

4. Install ARM compiler
Test that everything is ok:

.. code::

conda install clangxx_osx-arm64

5. LHAPDF

Download version 6.4.0 and decompress

.. code::

wget -O LHAPDF-6.4.0.tar.gz https://lhapdf.hepforge.org/downloads/?f=LHAPDF-6.4.0.tar.gz
tar -xzvf LHAPDF-6.4.0.tar.gz
rm LHAPDF-6.4.0.tar.gz
cd LHAPDF-6.4.0

Regenerate the configuration files, configure the build with python disabled, compile and
install. You may need to `brew install automake` first:

.. code::

autoreconf -f -i
./configure --prefix=$CONDA_PREFIX --disable-python
make -j
make install

Install the python wrapper

.. code::

cd wrappers/python
pip install -e .

Test

.. code::

lhapdf install CT18NNLO
lhapdf install NNPDF40_nnlo_as_01180
python -c "import lhapdf"

6. Apfel


First, we need to install some dependencies:
4. Note for tensorflow

.. code::

conda install pkg-config swig cmake

Then build it
At the time of writing, it is necessary to follow this extra step in order to install ``tensorflow`` which works only for python < 3.12.
Other versions of ``tensorflow-macos`` and ``tensorflow-metal`` might also work, but these are the ones we tested.

.. code::

cd ../../../apfel
autoreconf -f -i
PYTHON=$(which python) ./configure --prefix=$CONDA_PREFIX
make clean
make -j
make install

7. validphys
conda install -c apple tensorflow-deps
pip install tensorflow-macos==2.9.2
pip install tensorflow-metal==0.5.0

First install reportengine and validobj, then validphys itself:
5. Install NNPDF packages (``validphys``, ``n3fit`` and ``evolven3fit_new``) and its dependencies

.. code::

pip install reportengine validobj
cd ../nnpdf/validphys2
pip install -e .

8. nnpdf

Install other dependencies

.. code::

conda install libarchive sqlite gsl yaml-cpp

Run cmake in nnpdf/build directory:

.. code::

cd ..
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX

Edit the file ``nnpdfgit/nnpdf/CMakeLists.txt`` :

- on line 8 change the option to true, so it says:

.. code::

SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

- comment out line 58 (:code:`set(LIBNNPDF_HAVE_SSE "#define SSE_CONV")`)

- line 104 should read:

.. code::

set(DEFAULT_CXX_OPTIONS "-Wall -Wextra -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe")

(so delete ``-march=nocona -mtune=haswell``).

Then make:

.. code::

make -j
make install

Install remaining packages

.. code::

pip install seaborn prompt_toolkit scipy psutil hyperopt

9. Install tensorflow

Not specifying versions will install at the time of writing macos 2.12.0 and metal 0.8.0, which both work.
They only give warnings on the optimizers, that the legacy versions are faster.
If you want an older version, macos 2.9.2 and metal 0.5.0 are also tested to work.

.. code::

conda install -c apple tensorflow-deps
pip install tensorflow-macos==2.9.2
pip install tensorflow-metal==0.5.0

10. Test
6. Test

.. code::

Expand Down
17 changes: 7 additions & 10 deletions n3fit/evolven3fit/CMakeLists.txt → evolven3fit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# Include files (should this information not be known at this point?)
include_directories(${PROJECT_SOURCE_DIR}/nnpdfcpp/src/common/inc)
include_directories(${PROJECT_SOURCE_DIR}/nnpdfcpp/src/nnfit/inc)
include_directories(${PROJECT_SOURCE_DIR}/n3fit/evolven3fit)
include_directories(${PROJECT_SOURCE_DIR}/evolven3fit)
include_directories(${PROJECT_SOURCE_DIR}/libnnpdf/src/)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/binaries)

configure_file(
"${PROJECT_SOURCE_DIR}/libnnpdf/src/NNPDF/common.h.in"
"${PROJECT_SOURCE_DIR}/libnnpdf/src/NNPDF/common.h"
)
"${PROJECT_SOURCE_DIR}/evolven3fit/evolven3fit.cc.in"
"${PROJECT_SOURCE_DIR}/evolven3fit/evolven3fit.cc"
)

# Add files to the make
add_executable(evolven3fit ${PROJECT_SOURCE_DIR}/n3fit/evolven3fit/evolven3fit.cc
${PROJECT_SOURCE_DIR}/nnpdfcpp/src/common/src/md5.cc
${PROJECT_SOURCE_DIR}/nnpdfcpp/src/common/src/exportgrid.cc
${PROJECT_SOURCE_DIR}/nnpdfcpp/src/nnfit/src/evolgrid.cc )
add_executable(evolven3fit ${PROJECT_SOURCE_DIR}/evolven3fit/evolven3fit.cc
${PROJECT_SOURCE_DIR}/evolven3fit/exportgrid.cc
${PROJECT_SOURCE_DIR}/evolven3fit/evolgrid.cc )

# Set all flags
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${NNPDF_LDFLAGS} ${GSL_LDFLAGS} ${APFEL_LIBRARIES} ${YAML_LDFLAGS}")
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <NNPDF/exceptions.h>
#include <NNPDF/nnpdfdb.h>
#include <NNPDF/utils.h>
#include <NNPDF/pathlib.h>
#include <APFEL/APFELdev.h>

#include "exportgrid.h"
Expand All @@ -27,6 +26,8 @@ using std::string;
using std::stringstream;
using std::stoi;

#define DBPATH "@PROFILE_PREFIX@/theory.db"

// Check if folder exists
bool CheckConsistency(string const& folder, string const& exportfile)
{
Expand Down Expand Up @@ -96,7 +97,7 @@ int main(int argc, char **argv)

// load theory from db
std::map<string,string> theory_map;
NNPDF::IndexDB db(get_data_path() + "/theory.db", "theoryIndex");
NNPDF::IndexDB db(DBPATH, "theoryIndex");
auto keys = APFEL::kValues;
keys.push_back("EScaleVar");
db.ExtractMap(theory_id, keys, theory_map);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions libnnpdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ set(exec_prefix "${prefix}")
set(includedir "${prefix}/include")
set(libdir "${prefix}/lib")

configure_file(
"${PROJECT_SOURCE_DIR}/libnnpdf/nnprofile.yaml.in"
"${PROJECT_SOURCE_DIR}/libnnpdf/nnprofile.yaml"
)

configure_file(
"${PROJECT_SOURCE_DIR}/libnnpdf/src/NNPDF/config.h.in"
"${PROJECT_SOURCE_DIR}/libnnpdf/src/NNPDF/config.h"
Expand Down Expand Up @@ -58,14 +53,6 @@ target_link_libraries(nnpdf ${LHAPDF_LIBRARIES} ${GSL_LDFLAGS} ${SQLITE3_LDFLAGS

install(FILES ${PROJECT_SOURCE_DIR}/libnnpdf/scripts/nnpdf.pc DESTINATION lib/pkgconfig)
install(DIRECTORY src/NNPDF DESTINATION include)

file(WRITE ${PROJECT_SOURCE_DIR}/libnnpdf/REAMDE.md "The share folder of NNPDF has been moved, see: https://github.com/NNPDF/nnpdf/pull/1861\n")
install(FILES ${PROJECT_SOURCE_DIR}/libnnpdf/REAMDE.md DESTINATION share/NNPDF)
install(FILES ${PROJECT_SOURCE_DIR}/libnnpdf/nnprofile.yaml DESTINATION share/NNPDF)
install(TARGETS nnpdf DESTINATION lib)

add_subdirectory(wrapper)

if(ENABLE_TESTS)
add_subdirectory(tests)
endif()
Loading