Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QED lookup tables generator/reader in /Tools #3137

Merged
merged 64 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
daa3dcd
initial commit
lucafedeli88 May 24, 2022
2eab133
added support for BW table
lucafedeli88 May 25, 2022
dea483e
table generator is working
lucafedeli88 May 25, 2022
4c62c5b
added reader
lucafedeli88 May 25, 2022
b57cfea
fixed cmake issue
lucafedeli88 Jun 8, 2022
ac3b2a7
add test
lucafedeli88 Jun 9, 2022
cd5122a
fixed bug
lucafedeli88 Jun 9, 2022
7a8f172
fixed bug
lucafedeli88 Jun 14, 2022
4a31a8e
add table generation to test
lucafedeli88 Jun 14, 2022
62b0a1e
add terminal newline
lucafedeli88 Jun 14, 2022
887db9a
added diff test
lucafedeli88 Jun 14, 2022
6b6c401
increase precision of table reader
lucafedeli88 Jun 14, 2022
0c9a783
fixed bug in table reading
lucafedeli88 Jun 14, 2022
b048fa6
fixed bug
lucafedeli88 Jun 14, 2022
ee6c16f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2022
5faee75
correct test
lucafedeli88 Jun 14, 2022
d58869e
added documentation
lucafedeli88 Jun 14, 2022
cca3b9a
complete test
lucafedeli88 Jun 14, 2022
af21b32
modified CI test
lucafedeli88 Jun 14, 2022
2b7338e
fixed issues
lucafedeli88 Jun 14, 2022
e8155fa
fix bug
lucafedeli88 Jun 14, 2022
69c70ad
Update .github/workflows/ubuntu.yml
lucafedeli88 Jun 16, 2022
3eb9744
Update Docs/source/usage/workflows/generate_lookup_tables_with_tools.rst
lucafedeli88 Jun 19, 2022
a139a0c
fixed bug
lucafedeli88 Jun 19, 2022
41456d1
add entry in cmake.rst
lucafedeli88 Jun 19, 2022
5f85984
using script
lucafedeli88 Jun 20, 2022
ae7a1e4
fixed bug
lucafedeli88 Jun 20, 2022
713333c
change permission of script
lucafedeli88 Jun 20, 2022
cc17530
removed 'false' from script
lucafedeli88 Jun 20, 2022
28ad0bb
add newline at the end of a file
lucafedeli88 Jun 20, 2022
22d2065
added new logic to control OpenMP support for lookup table generation
lucafedeli88 Aug 23, 2022
91ad32e
document cmake parameter
lucafedeli88 Aug 23, 2022
ca421d2
fixed trailing space
lucafedeli88 Sep 7, 2022
f7b6b8e
Frontier/Crusher: rocFFT Cache Control (#3366)
ax3l Sep 9, 2022
bd77365
`SyncCurrent`: Split Filter and Sum over Guard Cells (#3222)
EZoni Sep 9, 2022
5d4c423
Update Docs/source/usage/workflows/generate_lookup_tables_with_tools.rst
lucafedeli88 Dec 7, 2022
d7c7e07
Update Tools/QedTablesUtils/Source/ArgParser/QedTablesArgParser.H
lucafedeli88 Dec 7, 2022
f5fc6a7
remove wrong comment
lucafedeli88 Dec 7, 2022
4ebb3a9
improve documentation
lucafedeli88 May 4, 2023
e2898fc
updated test
lucafedeli88 May 4, 2023
a3311b5
fix bug
lucafedeli88 May 25, 2023
c90133e
use the right executable to run test simulation
lucafedeli88 May 25, 2023
bf1d942
FIX BUG
lucafedeli88 May 25, 2023
bc81124
Merge remote-tracking branch 'upstream/development' into add_new_tool
lucafedeli88 Jun 15, 2023
30464b1
Merge remote-tracking branch 'upstream/development' into add_new_tool
lucafedeli88 Jun 23, 2023
74a00d9
Merge remote-tracking branch 'upstream/development' into add_new_tool
lucafedeli88 Jun 25, 2023
2aa0342
Merge remote-tracking branch 'upstream/development' into add_new_tool
lucafedeli88 Aug 3, 2023
d7c3632
fixed merge conflict
lucafedeli88 Aug 21, 2023
3be126e
Build & Test Cleanups
ax3l Oct 16, 2023
c45ffa7
Merge remote-tracking branch 'mainline/development' into add_new_tool
ax3l Oct 16, 2023
172f859
Update CI Script
ax3l Oct 19, 2023
6fa5a44
Fix wrong path in checkQEDTableGenerator.sh
lucafedeli88 Oct 20, 2023
632bf79
Update checkQEDTableGenerator.sh
lucafedeli88 Oct 20, 2023
2123ca7
Merge remote-tracking branch 'upstream/development' into add_new_tool
lucafedeli88 Oct 31, 2023
bab799c
fixed merge conflict
lucafedeli88 Feb 29, 2024
86fee9f
fixed bug
lucafedeli88 Feb 29, 2024
fd3f7da
debug
lucafedeli88 Feb 29, 2024
ceddaed
workaround
lucafedeli88 Feb 29, 2024
1913bb2
Merge branch 'add_new_tool' of github.com:lucafedeli88/WarpX into add…
lucafedeli88 Mar 19, 2024
4e18008
Merge remote-tracking branch 'upstream/development' into add_new_tool
lucafedeli88 Mar 19, 2024
2594a41
fix merge conflict
lucafedeli88 Mar 20, 2024
dd1552f
fix issues with CI tests
lucafedeli88 Mar 20, 2024
1aedaa5
rename test
lucafedeli88 Mar 20, 2024
f9a6128
update Doc
lucafedeli88 Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/scripts/checkQEDTableGenerator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

#!/usr/bin/env bash
#
# Copyright 2022 Luca Fedeli
#
# License: BSD-3-Clause-LBNL

set -eu -o pipefail

export OMP_NUM_THREADS=2

#
# Generate QED lookup tables using external tool
#
./build_qed/bin/qed_tools/qed_table_generator \
--table BW --mode DP --dndt_chi_min 0.01 \
--dndt_chi_max 100 --dndt_how_many 64 \
--pair_chi_min 0.01 --pair_chi_max 100 \
--pair_chi_how_many 64 --pair_frac_how_many 64 \
-o bw_table_tool
./build_qed/bin/qed_tools/qed_table_generator \
--table QS --mode DP --dndt_chi_min 0.001 \
--dndt_chi_max 100 --dndt_how_many 64 \
--em_chi_min 0.001 --em_chi_max 100 \
--em_chi_how_many 64 --em_frac_how_many 64 \
--em_frac_min 1e-12 -o qs_table_tool

#
# Generate QED lookup tables using WarpX
#
./build_qed/bin/warpx.3d \
./Examples/Tests/qed/quantum_synchrotron/inputs_3d \
qed_bw.lookup_table_mode = "generate" \
qed_bw.tab_dndt_chi_min = 0.01 \
qed_bw.tab_dndt_chi_max = 100.0 \
qed_bw.tab_dndt_how_many = 64 \
qed_bw.tab_pair_chi_min = 0.01 \
qed_bw.tab_pair_chi_max = 100.0 \
qed_bw.tab_pair_chi_how_many = 64 \
qed_bw.tab_pair_frac_how_many = 64 \
qed_bw.save_table_in = "bw_table" \
qed_qs.lookup_table_mode = "generate" \
qed_qs.tab_dndt_chi_min = 0.001 \
qed_qs.tab_dndt_chi_max = 100.0 \
qed_qs.tab_dndt_how_many = 64 \
qed_qs.tab_em_chi_min = 0.001 \
qed_qs.tab_em_frac_min = 1.0e-12 \
qed_qs.tab_em_chi_max = 100.0 \
qed_qs.tab_em_chi_how_many = 64 \
qed_qs.tab_em_frac_how_many = 64 \
qed_qs.save_table_in = "qs_table"

#
# Convert lookup tables (generated with WarpX and with the external tool) in human-readable format
#
./build_qed/bin/qed_tools/qed_table_reader -i qs_table --table QS --mode DP -o qs_table
./build_qed/bin/qed_tools/qed_table_reader -i qs_table_tool --table QS --mode DP -o qs_table_tool
./build_qed/bin/qed_tools/qed_table_reader -i bw_table --table BW --mode DP -o bw_table
./build_qed/bin/qed_tools/qed_table_reader -i bw_table_tool --table BW --mode DP -o bw_table_tool

#
# Compare the generated lookup tables
#
diff bw_table_dndt bw_table_tool_dndt
diff bw_table_pair bw_table_tool_pair
diff qs_table_phot_em qs_table_tool_phot_em
diff qs_table_dndt qs_table_tool_dndt

#
# Run a WarpX simulation using the lookup tables generated by the external tool
#
./build_qed/bin/warpx.3d \
./Examples/Tests/qed/quantum_synchrotron/inputs_3d \
qed_bw.lookup_table_mode = "load" \
qed_bw.load_table_from = "bw_table_tool" \
qed_qs.lookup_table_mode = "load" \
qed_qs.load_table_from = "qs_table_tool"
32 changes: 32 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,35 @@ jobs:
run: |
export OMP_NUM_THREADS=1
mpirun -n 2 Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py

build_qed_table_tools:
lucafedeli88 marked this conversation as resolved.
Show resolved Hide resolved
name: Clang QED table tools
runs-on: ubuntu-20.04
if: github.event.pull_request.draft == false
env:
# On CI for this test, Ninja is slower than the default:
#CMAKE_GENERATOR: Ninja
# setuptools/mp4py work-around, see
# https://github.com/mpi4py/mpi4py/pull/159
# https://github.com/mpi4py/mpi4py/issues/157#issuecomment-1001022274
SETUPTOOLS_USE_DISTUTILS: stdlib
steps:
- uses: actions/checkout@v2
- name: install dependencies
run: |
.github/workflows/dependencies/pyfull.sh
- name: build WarpX & QED tools
run: |
export CC=$(which clang)
export CXX=$(which clang++)
cmake -S . -B build_qed \
-DWarpX_APP=ON \
-DWarpX_LIB=OFF \
-DWarpX_MPI=ON \
lucafedeli88 marked this conversation as resolved.
Show resolved Hide resolved
-DWarpX_QED_TOOLS=ON \
-DWarpX_QED_TABLE_GEN=ON
cmake --build build_qed -j 6

- name: run table_generator_tool
run: |
./.github/workflows/scripts/checkQEDTableGenerator.sh
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ set_default_install_dirs()
# Options and Variants ########################################################
#
include(CMakeDependentOption)
option(WarpX_APP "Build the WarpX executable application" ON)
option(WarpX_ASCENT "Ascent in situ diagnostics" OFF)
option(WarpX_EB "Embedded boundary support" OFF)
option(WarpX_APP "Build the WarpX executable application" ON)
option(WarpX_ASCENT "Ascent in situ diagnostics" OFF)
option(WarpX_EB "Embedded boundary support" OFF)
cmake_dependent_option(WarpX_GPUCLOCK
"Add GPU kernel timers (cost function)" ON
"WarpX_COMPUTE STREQUAL CUDA OR WarpX_COMPUTE STREQUAL HIP" OFF)
Expand All @@ -72,6 +72,7 @@ option(WarpX_PYTHON "Python bindings" OFF)
option(WarpX_SENSEI "SENSEI in situ diagnostics" OFF)
option(WarpX_QED "QED support (requires PICSAR)" ON)
option(WarpX_QED_TABLE_GEN "QED table generation (requires PICSAR and Boost)" OFF)
option(WarpX_QED_TOOLS "Build external tool to generate QED lookup tables (requires PICSAR and Boost)" OFF)
lucafedeli88 marked this conversation as resolved.
Show resolved Hide resolved

set(WarpX_DIMS_VALUES 1 2 3 RZ)
set(WarpX_DIMS 3 CACHE STRING "Simulation dimensionality <1;2;3;RZ>")
Expand Down Expand Up @@ -103,6 +104,13 @@ if(NOT WarpX_PARTICLE_PRECISION IN_LIST WarpX_PARTICLE_PRECISION_VALUES)
message(FATAL_ERROR "WarpX_PARTICLE_PRECISION (${WarpX_PARTICLE_PRECISION}) must be one of ${WarpX_PARTICLE_PRECISION_VALUES}")
endif()

set(WarpX_QED_TABLES_GEN_OMP_VALUES AUTO ON OFF)
set(WarpX_QED_TABLES_GEN_OMP AUTO CACHE STRING "Enables OpenMP support for QED lookup tables generation (AUTO/ON/OFF)")
set_property(CACHE WarpX_QED_TABLES_GEN_OMP PROPERTY STRINGS ${WarpX_QED_TABLES_GEN_OMP_VALUES})
if(NOT WarpX_QED_TABLES_GEN_OMP IN_LIST WarpX_QED_TABLES_GEN_OMP_VALUES)
message(FATAL_ERROR "WarpX_QED_TABLES_GEN_OMP (${WarpX_QED_TABLES_GEN_OMP}) must be one of ${WarpX_QED_TABLES_GEN_OMP_VALUES}")
endif()

set(WarpX_COMPUTE_VALUES NOACC OMP CUDA SYCL HIP)
set(WarpX_COMPUTE OMP CACHE STRING "On-node, accelerated computing backend (NOACC/OMP/CUDA/SYCL/HIP)")
set_property(CACHE WarpX_COMPUTE PROPERTY STRINGS ${WarpX_COMPUTE_VALUES})
Expand Down
2 changes: 2 additions & 0 deletions Docs/source/install/cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ CMake Option Default & Values Descr
``WarpX_PYTHON`` ON/**OFF** Python bindings
``WarpX_QED`` **ON**/OFF QED support (requires PICSAR)
``WarpX_QED_TABLE_GEN`` ON/**OFF** QED table generation support (requires PICSAR and Boost)
``WarpX_QED_TOOLS`` ON/**OFF** Build external tool to generate QED lookup tables (requires PICSAR and Boost)
``WarpX_QED_TABLES_GEN_OMP`` **AUTO**/ON/OFF Enables OpenMP support for QED lookup tables generation
``WarpX_SENSEI`` ON/**OFF** SENSEI in situ visualization
============================= ============================================ =========================================================

Expand Down
4 changes: 4 additions & 0 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,8 @@ Lookup tables store pre-computed values for functions used by the QED modules.

* ``qed_bw.save_table_in`` (`string`): where to save the lookup table

Alternatively, the lookup table can be generated using a standalone tool (see :ref:`qed tools section <generate-lookup-tables-with-tools>`).

* ``load``: a lookup table is loaded from a pre-generated binary file. The following parameter
must be specified:

Expand Down Expand Up @@ -3071,6 +3073,8 @@ Lookup tables store pre-computed values for functions used by the QED modules.

* ``qed_qs.save_table_in`` (`string`): where to save the lookup table

Alternatively, the lookup table can be generated using a standalone tool (see :ref:`qed tools section <generate-lookup-tables-with-tools>`).

* ``load``: a lookup table is loaded from a pre-generated binary file. The following parameter
must be specified:

Expand Down
1 change: 1 addition & 0 deletions Docs/source/usage/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This section collects typical user workflows and best practices for WarpX.
:maxdepth: 2

workflows/debugging
workflows/generate_lookup_tables_with_tools.rst
Copy link
Member

@ax3l ax3l Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.rst ending not needed :)
#4804

workflows/libensemble
workflows/plot_timestep_duration
workflows/plot_distribution_mapping
Expand Down
45 changes: 45 additions & 0 deletions Docs/source/usage/workflows/generate_lookup_tables_with_tools.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.. _generate-lookup-tables-with-tools:

Generate QED lookup tables using the standalone tool
====================================================

We provide tools to generate and convert into a human-readable format the QED lookup tables.
Such tools can be compiled with ``cmake`` by setting the flag ``WarpX_QED_TOOLS=ON`` (this
requires both ``PICSAR`` and ``Boost`` libraries). The tools are compiled alongside the WarpX executable
in the sub-folder ``bin/qed_tools``. We report here the help message displayed by the tools:

.. code-block:: console

$ ./qed_table_reader -h
### QED Table Reader ###
Command line options:
-h [NO ARG] Prints all command line arguments
-i [STRING] Name of the file to open
--table [STRING] Either BW (Breit-Wheeler) or QS (Quantum Synchrotron)
--mode [STRING] Precision of the calculations: either DP (double) or SP (single)
-o [STRING] filename to save the lookup table in human-readable format

$ ./qed_table_generator -h
### QED Table Generator ###
Command line options:
-h [NO ARG] Prints all command line arguments
--table [STRING] Either BW (Breit-Wheeler) or QS (Quantum Synchrotron)
--mode [STRING] Precision of the calculations: either DP (double) or SP (single)
--dndt_chi_min [DOUBLE] minimum chi parameter for the dNdt table
--dndt_chi_max [DOUBLE] maximum chi parameter for the dNdt table
--dndt_how_many [INTEGR] number of points in the dNdt table
--pair_chi_min [DOUBLE] minimum chi for the pair production table (BW only)
--pair_chi_max [DOUBLE] maximum chi for the pair production table (BW only)
--pair_chi_how_many [INTEGR] number of chi points in the pair production table (BW only)
--pair_frac_how_many [INTEGR] number of frac points in the pair production table (BW only)
--em_chi_min [DOUBLE] minimum chi for the photon emission table (QS only)
--em_chi_max [DOUBLE] maximum chi for the photon emission production table (QS only)
--em_frac_min [DOUBLE] minimum frac for the photon emission production table (QS only)
--em_chi_how_many [INTEGR] number of chi points in the photon emission table (QS only)
--em_frac_how_many [INTEGR] number of frac points in the photon emission table (QS only)
Comment on lines +28 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be useful for users to give recommended table parameters in this file (there are a lot of parameters and it's not trivial to choose them).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right... we need to properly document everything related to the QED module... I promise that I will work on that starting from January 2023!

-o [STRING] filename to save the lookup table

These tools are meant to be compatible with WarpX: ``qed_table_generator`` should generate
tables that can be loaded into WarpX and ``qed_table_reader`` should be able to read tables generated with WarpX.
It is not safe to use these tools to generate a table on a machine using a different endianness with respect to
the machine where the table is used.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"jz": 1045267552192496.5,
"rho": 2205684400.307701
}
}
}
45 changes: 45 additions & 0 deletions Tools/QedTablesUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
########
# Common argument parser library
########
set(arg_parser_cpp "Source/ArgParser/QedTablesArgParser.cpp")
set(arg_parser_h "Source/ArgParser/QedTablesArgParser.H")

add_library( QedToolsArgParser ${arg_parser_cpp} ${arg_parser_h} )
Copy link
Member

@ax3l ax3l Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this library used anywhere else?

If you like, generalize it and make it part of the ABLASTR utils? (as a follow-up PR?)


########
# Build QED lookup tables generator
########
set(qed_generator_name "qed_table_generator")
set(qed_generator_src "Source/QedTableGenerator.cpp")

add_executable(${qed_generator_name} ${qed_generator_src})

target_link_libraries(${qed_generator_name} PRIVATE PXRMP_QED)
target_link_libraries(${qed_generator_name} PRIVATE QedToolsArgParser)

target_compile_features(${qed_generator_name} PUBLIC cxx_std_17)
set_target_properties(${qed_generator_name} PROPERTIES CXX_EXTENSIONS OFF)

set_target_properties(${qed_generator_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/qed_tools)

message(STATUS "QED lookup tables generator: ${qed_generator_name} (${qed_generator_src})")

########
# Build QED lookup tables reader
########
set(qed_reader_name "qed_table_reader")
set(qed_reader_src "Source/QedTableReader.cpp")

add_executable(${qed_reader_name} ${qed_reader_src})

target_link_libraries(${qed_reader_name} PRIVATE PXRMP_QED)
target_link_libraries(${qed_reader_name} PRIVATE QedToolsArgParser)

target_compile_features(${qed_reader_name} PUBLIC cxx_std_17)
set_target_properties(${qed_reader_name} PROPERTIES CXX_EXTENSIONS OFF)

set_target_properties(${qed_reader_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/qed_tools)

message(STATUS "QED lookup tables generator: ${qed_reader_name} (${qed_reader_src})")
58 changes: 58 additions & 0 deletions Tools/QedTablesUtils/Source/ArgParser/QedTablesArgParser.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef QED_TABLES_ARG_PARSER_
#define QED_TABLES_ARG_PARSER_

#include <optional>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <variant>
#include <vector>

namespace ArgParser
{
/* Possible types of parameters of command line arguments (no argument, int, double, or std::string) */
enum class ArgType { NoArg, Integer, Double, String };

/* This type represents the type of a command line argument: if it exists it is either an int, a double, or a std::string */
using ArgVal = std::optional<std::variant<int, double, std::string>>;

/* The type of a possible command line argument */
using Key = std::tuple<std::string, ArgType, std::string>;

/* The type of the map of the parsed command line arguments */
using ParsedArgs = std::unordered_map<std::string, ArgVal>;

/**
* \brief Gets the value out of an ArgVal (std::optional<std::variant<int, double, std::string>>) object
*
* \tparam T the type to return (must be int, double, or std::string)
* \param[in] arg_val the ArgVal object
* \return the value in arg_val
*/
template <typename T>
T GetVal(const ArgVal& arg_val)
{
return std::get<T>(*arg_val);
}

/**
* \brief Function to parse the command line arguments
*
* \param[in] keys the list of possible command line arguments
* \param[in] argc the number of command line arguments
* \param[in] argv all the command line arguments
* \return the parsed command line arguments
*/
ParsedArgs ParseArgs (const std::vector<Key>& keys, const int argc, char const* const* argv);

/**
* \brief Prints the command line options
*
* \param[in] cmd_list the list of possible command line arguments
*/
void PrintHelp (const std::vector<Key>& cmd_list);
};


#endif //QED_TABLES_ARG_PARSER_
Loading
Loading