Skip to content

Commit

Permalink
Add python bindings for QED library 🐍 (#20)
Browse files Browse the repository at this point in the history
* improve table_generator

* Update multi_physics/QED/QED_table_generator/table_generator.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/QED_table_generator/table_generator.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/QED_table_generator/table_generator.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/QED_table_generator/table_generator.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/QED_table_generator/table_generator.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* move MAX_CMD_SIZE

* add default values for optional parameters

* check for duplicated arguments

* add wrappers to stod and stoi to check if conversion succeeds

* initial work to add python bindings to the library

* progress with python bindings

* added CMakeLists.txt for python bindings

* Mark pure getters as const

* further progress towards python bindings

* completed python bindings for chi functions

* added python bindings for schwinger pair production

* added optical depths to python bindings

* added lookup table parameters to python bindings

* now table params have __repr__ method

* added BW lookup tables to python bindings

* added interp methods to python bindings

* added BW optical depth evolution to python bindings

* added optical depth evolution for QS in python bindings

* added demo script for python bindings

* removed binary file accidentally ended up in git

* removed binary file accidentally ended up in git

* install pybind11 in CI

* fixed bug

* added Breit-Wheeler pair production

* removed trailing spaces

* added QS photon emission to python bindings

* updated demo script

* updated structure

* fixed compilation with units != SI

* added plenty of comments

* updated CI

* fix CI

* Update multi_physics/QED/python_bindings/CMakeLists.txt

Co-authored-by: Axel Huebl <[email protected]>

* Update multi_physics/QED/python_bindings/CMakeLists.txt

Co-authored-by: Axel Huebl <[email protected]>

* Update multi_physics/QED/python_bindings/CMakeLists.txt

Co-authored-by: Axel Huebl <[email protected]>

* implement Axel's suggetion (can't do that on github)

* use 2.6 instead of 2.6.0 as version

* reduce version from 2.6 to 2.4!

* use version 2.6 and try pybind11 installation with pip

* using pybind11[global]

* fixed installation directory

* Update multi_physics/QED/python_bindings/pxr_qed.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/python_bindings/pxr_qed.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/python_bindings/pxr_qed.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/python_bindings/pxr_qed.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* fix bug concerning qs_photon_emission_lookup_table_params constructor in python bindings

* add missing parameter

* Update multi_physics/QED/python_bindings/pxr_qed.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/python_bindings/pxr_qed.cpp

Co-authored-by: Neïl Zaim <[email protected]>

* Update multi_physics/QED/python_bindings/pxr_qed.cpp

Co-authored-by: Neïl Zaim <[email protected]>

Co-authored-by: Neïl Zaim <[email protected]>
Co-authored-by: Axel Huebl <[email protected]>
  • Loading branch information
3 people authored Apr 21, 2021
1 parent 3a948c4 commit 0b6b880
Show file tree
Hide file tree
Showing 7 changed files with 1,916 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

- name: Build
run: |
cmake -S multi_physics/QED \
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/dependencies/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2020 The PICSAR Community
#
# License: BSD-3-Clause-LBNL
# Authors: Axel Huebl
# Authors: Axel Huebl, Luca Fedeli

set -eu -o pipefail

Expand All @@ -15,4 +15,7 @@ sudo apt-get install -y --no-install-recommends \
libboost-dev \
libboost-math-dev \
libboost-test-dev \
g++ gfortran
g++ gfortran \
python3-dev

pip install "pybind11[global]"
5 changes: 3 additions & 2 deletions .github/workflows/dependencies/dependencies_mac.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env bash
#
# Copyright 2020 The AMReX Community
# Copyright 2020 The PICSAR Community
#
# License: BSD-3-Clause-LBNL
# Authors: Axel Huebl
# Authors: Axel Huebl, Luca Fedeli

set -eu -o pipefail

brew update
brew install boost
brew install libomp
brew install pybind11
#brew install open-mpi
5 changes: 5 additions & 0 deletions multi_physics/QED/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option(PXRMP_QED_OMP "Enable OpenMP support" ON)
option(PXRMP_QED_TABLEGEN "Enable table generation (needs Boost)" ON)
option(PXRMP_QED_TEST "Build PICSAR QED tests " ${IS_TOPLEVEL})
option(PXRMP_QED_TOOLS "Build PICSAR QED tools " ${IS_TOPLEVEL})
option(PXRMP_QED_PYTHON_BINDINGS "Build PICSAR QED python bindings " ${IS_TOPLEVEL})
option(PXRMP_BOOST_TEST_DYN_LINK "Link against the Boost Unit Test Framework shared library" ON)
option(PXRMP_DPCPP_FIX "Use cl::sycl::floor cl::sycl::floorf on device" OFF)

Expand Down Expand Up @@ -50,6 +51,10 @@ if(PXRMP_QED_TABLEGEN)
endif()
endif()

if(PXRMP_QED_PYTHON_BINDINGS)
add_subdirectory(python_bindings)
endif()

if(PXRMP_DPCPP_FIX)
target_compile_definitions(PXRMP_QED INTERFACE PXRMP_DPCPP_FIX=1)
endif()
Expand Down
71 changes: 71 additions & 0 deletions multi_physics/QED/python_bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
set(name pxr_qed)

set(_PY_DEV_MODULE Development.Module)
if(CMAKE_VERSION VERSION_LESS 3.18.0)
# over-specification needed for CMake<3.18
# https://pybind11.readthedocs.io/en/latest/compiling.html#findpython-mode
# https://cmake.org/cmake/help/v3.18/module/FindPython.html
set(_PY_DEV_MODULE Development)
endif()
find_package(Python COMPONENTS Interpreter ${_PY_DEV_MODULE} REQUIRED)
find_package(pybind11 2.6 CONFIG REQUIRED)

pybind11_add_module(${name} "${name}.cpp")

target_link_libraries(${name} PRIVATE PXRMP_QED)

option(
PXRQEDPY_DOUBLE_PRECISION
"Compile pxr_qed python module in double precision" ON)

if(PXRQEDPY_DOUBLE_PRECISION)
target_compile_definitions(${name} PRIVATE PXRQEDPY_DOUBLE_PRECISION=1)
endif()

set(PXRQEDPY_UNITS_VALUES SI NORM_OMEGA NORM_LAMBDA HEAVISIDE_LORENTZ)
set(PXRQEDPY_UNITS SI CACHE STRING "Unit system for the pxr_qed python module (SI/NORM_OMEGA/NORM_LAMBDA/HEAVISIDE_LORENTZ)")
set_property(CACHE PXRQEDPY_UNITS PROPERTY STRINGS ${PXRQEDPY_UNITS_VALUES})

if(NOT PXRQEDPY_UNITS IN_LIST PXRQEDPY_UNITS_VALUES)
message(FATAL_ERROR "PXRQEDPY_UNITS (${PXRQEDPY_UNITS}) must be one of ${PXRQEDPY_UNITS_VALUES}")
endif()

if(PXRQEDPY_UNITS STREQUAL "SI")
target_compile_definitions(${name} PRIVATE PXRQEDPY_SI=1)
elseif(PXRQEDPY_UNITS STREQUAL "NORM_OMEGA")
target_compile_definitions(${name} PRIVATE PXRQEDPY_NORM_OMEGA=1)
elseif(PXRQEDPY_UNITS STREQUAL "NORM_LAMBDA")
target_compile_definitions(${name} PRIVATE PXRQEDPY_NORM_LAMBDA=1)
elseif(PXRQEDPY_UNITS STREQUAL "HEAVISIDE_LORENTZ")
target_compile_definitions(${name} PRIVATE PXRQEDPY_HEAVISIDE_LORENTZ=1)
else()
message(FATAL_ERROR "PXRQEDPY_UNITS is incorrectly defined")
endif()

target_link_libraries(${name} PRIVATE pybind11::module pybind11::lto pybind11::windows_extras)

# OpenMP support
if(PXRMP_QED_OMP)
find_package(OpenMP REQUIRED)
target_link_libraries(${name} PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(${name} PRIVATE PXQEDPY_HAS_OPENMP=1)
endif()

# Move module in "python_bindings" subdirectory
set(PXRQEDPY_INSTALL_DIR ${CMAKE_BINARY_DIR}/python_bindings CACHE PATH "Installation directory for the python bindings")
set_target_properties(${name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PXRQEDPY_INSTALL_DIR})

configure_file(demo_python_bindings.ipynb
${CMAKE_BINARY_DIR}/python_bindings/demo_python_bindings.ipynb COPYONLY)

# Require C++14 or newer
target_compile_features(${name} PUBLIC cxx_std_14)
set_target_properties(${name} PROPERTIES CXX_EXTENSIONS OFF)

# Enable warnings
if(MSVC)
target_compile_options(${name} PRIVATE /W4)
else()
target_compile_options(${name} PRIVATE -Wall -Wextra -pedantic)
endif()
Loading

0 comments on commit 0b6b880

Please sign in to comment.