Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
457d690
Stabilize Python API and add more `boc` tests
Radonirinaunimi Feb 2, 2025
65993b9
Add more tests for `Pyboc`
Radonirinaunimi Feb 3, 2025
288501b
Complete adding unit tests for `Pyboc`
Radonirinaunimi Feb 3, 2025
4287eea
Improve test coverage fo the Python API
Radonirinaunimi Feb 3, 2025
0f2126f
Fix the tutorials
Radonirinaunimi Feb 3, 2025
26936da
Add missed unit tests in `test_fk_table.py`
Radonirinaunimi Feb 3, 2025
8b3dd3d
Fix tests in the Fortran API
Radonirinaunimi Feb 3, 2025
1f75424
Run Fortran examples on the CI
Radonirinaunimi Feb 3, 2025
e88d5f8
Minor fixes to `Makefile`
Radonirinaunimi Feb 3, 2025
f981155
Remove maximum characte limit in Fortran examples
Radonirinaunimi Feb 3, 2025
eaa6067
Use PDF sets available in the container
Radonirinaunimi Feb 3, 2025
53272a0
Fix choice of PDF
Radonirinaunimi Feb 3, 2025
14150cb
Complete Fortran API and make CI tests running
Radonirinaunimi Feb 4, 2025
8232607
Minor cosmetic changes to the C++ examples
Radonirinaunimi Feb 4, 2025
742823a
Cover more parts in the C examples
Radonirinaunimi Feb 4, 2025
dcfd364
Check errors raised from `Grid.set_bwfl` and `Grid.merge`
Radonirinaunimi Feb 4, 2025
87efcae
Start updating the C++ OOP API
Radonirinaunimi Feb 5, 2025
87afbe8
Trigger OO C++ examples on the CI
Radonirinaunimi Feb 5, 2025
1d633f7
Remove unused default in `PyBoc`
Radonirinaunimi Feb 5, 2025
ac2448b
Commit suggestion from CR
Radonirinaunimi Feb 6, 2025
03c4bda
First fix `pineappl_grid_convolve` in the C binding
Radonirinaunimi Feb 6, 2025
10ac40f
Fully fix `pineappl_grid_convolve/convolute_with_two`
Radonirinaunimi Feb 6, 2025
6461e6e
Complete fix for the convolutions in the C API
Radonirinaunimi Feb 6, 2025
9eee993
Temporarily exclude checks of the Fortran examples on the CI
Radonirinaunimi Feb 6, 2025
8db10ab
Remap the `enums` in `cbindgen.toml`
Radonirinaunimi Feb 6, 2025
7f7184a
Nuke `v0` in OOP C++
Radonirinaunimi Feb 7, 2025
f153ec3
Rename enums consistently
cschwan Feb 7, 2025
bc021f5
Add ScreamingSnakeCase constants for `GridOptFlags`
cschwan Feb 7, 2025
f4d5ccf
Various minor fixes from changes of enum variants and CR
Radonirinaunimi Feb 7, 2025
b4bb0f8
Undo changes in `pineappl_convol{ve,ute}_with_two`
Radonirinaunimi Feb 7, 2025
cd297ee
Add `MSHT20qed_nnlo` as installed PDF in the container
Radonirinaunimi Feb 7, 2025
6015f46
Fix memory leaks in C++ examples
cschwan Feb 10, 2025
c54516a
Run C++ examples with sanitizers
cschwan Feb 10, 2025
f040c4f
Convolve grids in C++ examples with different PDFs
Radonirinaunimi Feb 7, 2025
999c139
Complete OO C++ interface and example
Radonirinaunimi Feb 10, 2025
a4f8c7b
Also run OO C++ with sanitizers
Radonirinaunimi Feb 10, 2025
e9da0dd
Complete Fortran interface and examples
Radonirinaunimi Feb 10, 2025
7542747
Reactivate checks for Fortran examples in the CI
Radonirinaunimi Feb 10, 2025
b5fe4c6
`deallocate` objects in Fortran examples
Radonirinaunimi Feb 11, 2025
64e77ca
Fix an initialization bug in case FF is involved
Radonirinaunimi Feb 12, 2025
f8cb9c6
Tiny change for a more concise naming
Radonirinaunimi Feb 12, 2025
b5e98c3
Fix `fall through` error in switch statement
Radonirinaunimi Feb 13, 2025
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
20 changes: 9 additions & 11 deletions .github/workflows/capi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,29 @@ jobs:
# `-C link-dead-code` is needed to prevent 'warning: XX functions have mismatched data' warnings
RUSTFLAGS: '-Cinstrument-coverage -Clink-dead-code'
run: |
cargo cinstall --verbose --prefix=/usr/local/ --libdir=lib --manifest-path pineappl_capi/Cargo.toml
cd pineappl_capi
cargo cinstall --verbose --prefix=/usr/local/ --libdir=/usr/local/lib
ldconfig

- name: Test C++ example
- name: Test C++ examples
run: |
cd examples/cpp
# if `make` is too old, it doesn't support the `!=` operator
sed -i "s/\([a-zA-Z_]\+\) != \(.*\)$/echo \1 = \$(\2)/e" Makefile
make test-examples
# run tests with sanitizer
make CXXFLAGS="-O0 -ggdb -Wall -Wextra -fsanitize=address,undefined" test-examples

- name: Test Fortran example
- name: Test Fortran examples
run: |
cd examples/fortran
sed -i "s/\([a-zA-Z_]\+\) != \(.*\)$/echo \1 = \$(\2)/e" Makefile
make
./dyaa
test -f ./DY-LO-AA.pineappl.lz4
make test-examples

- name: Test OO C++ example
- name: Test OO C++ examples
run: |
cd examples/object-oriented-cpp
sed -i "s/\([a-zA-Z_]\+\) != \(.*\)$/echo \1 = \$(\2)/e" Makefile
make
./dyaa
test -f ./DY-LO-AA.pineappl.lz4
make CXXFLAGS="-O0 -ggdb -Wall -Wextra -fsanitize=address,undefined" test-examples

- name: Generate code coverage
run: |
Expand Down
8 changes: 4 additions & 4 deletions examples/cpp/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CXX = c++
CXXFLAGS = -std=c++11 -O3 -Wall -Wextra
CXX = c++ -std=c++11
CXXFLAGS = -O3 -Wall -Wextra
PINEAPPL_DEPS != pkg-config --cflags --libs pineappl_capi
LHAPDF_DEPS != pkg-config --cflags --libs lhapdf

Expand All @@ -24,7 +24,7 @@ PROGRAMS = \
all: $(PROGRAMS)

test-examples: $(PROGRAMS)
set -e && for i in $(PROGRAMS); do ./$${i}; done > test-output && diff -u output test-output && rm test-output
set -e && for i in $(PROGRAMS); do ./$${i}; done > output

advanced-convolution-deprecated: advanced-convolution-deprecated.cpp
$(CXX) $(CXXFLAGS) $< $(LHAPDF_DEPS) $(PINEAPPL_DEPS) -o $@
Expand Down Expand Up @@ -77,4 +77,4 @@ modify-grid: modify-grid.cpp
PHONY: clean

clean:
rm -f $(PROGRAMS)
rm -f $(PROGRAMS) *.pineappl *.lz4
77 changes: 57 additions & 20 deletions examples/cpp/advanced-convolution-deprecated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,46 @@
#include <iomanip>
#include <ios>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

// An object to hold the state of the different PDFs
struct PDFState {
LHAPDF::PDF* pdfs[2];
};

// The callable PDF function using the 1st PDF
double xfx1(int32_t id, double x, double q2, void* state) {
auto* pdf = static_cast <PDFState*> (state)->pdfs[0];
return pdf -> xfxQ2(id, x, q2);
};

// The callable PDF function using the 2nd PDF
double xfx2(int32_t id, double x, double q2, void* state) {
auto* pdf = static_cast <PDFState*> (state)->pdfs[1];
return pdf -> xfxQ2(id, x, q2);
};

// The callable alphasQ2 function using the 2nd PDF
double alphas(double q2, void* state) {
auto* pdf = static_cast <PDFState*> (state)->pdfs[1];
return pdf -> alphasQ2(q2);
};

int main(int argc, char* argv[]) {
std::string filename = "drell-yan-rap-ll-deprecated.pineappl.lz4";
std::string pdfset = "NNPDF31_nlo_as_0118_luxqed";
std::string pdfset1 = "NNPDF31_nlo_as_0118_luxqed";
std::string pdfset2 = "MSHT20qed_nnlo";

switch (argc) {
case 4:
pdfset2 = argv[3];
// fall through
Comment thread
cschwan marked this conversation as resolved.
case 3:
pdfset = argv[2];
pdfset1 = argv[2];
// set the two PDFs the same if only one is provided
if (argc == 3) pdfset2 = argv[2];
// fall through
case 2:
filename = argv[1];
Expand All @@ -31,18 +61,9 @@ int main(int argc, char* argv[]) {
// read the grid from a file
auto* grid = pineappl_grid_read(filename.c_str());

auto* pdf = LHAPDF::mkPDF(pdfset, 0);

// define callables for the PDFs and alphas
auto xfx1 = [](int32_t id, double x, double q2, void* pdf) {
return static_cast <LHAPDF::PDF*> (pdf)->xfxQ2(id, x, q2);
};
auto xfx2 = [](int32_t id, double x, double q2, void* pdf) {
return static_cast <LHAPDF::PDF*> (pdf)->xfxQ2(id, x, q2);
};
auto alphas = [](double q2, void* pdf) {
return static_cast <LHAPDF::PDF*> (pdf)->alphasQ2(q2);
};
auto pdf1 = std::unique_ptr<LHAPDF::PDF>(LHAPDF::mkPDF(pdfset1, 0));
auto pdf2 = std::unique_ptr<LHAPDF::PDF>(LHAPDF::mkPDF(pdfset2, 0));
PDFState state = {pdf1.get(), pdf2.get()};

// how many perturbative orders does the grid contain?
std::size_t orders = pineappl_grid_order_count(grid);
Expand Down Expand Up @@ -78,37 +99,53 @@ int main(int argc, char* argv[]) {
// `xfx1` and `alphas` are *proton* PDFs. If the grid contains cross sections of either a
// proton-proton, proton-antiproton or antiproton-antiproton collision PineAPPL will perform the
// necessary charge conjugations to yield the correct convolutions
pineappl_grid_convolve_with_one(grid, 2212, xfx1, alphas, pdf, order_mask.get(),
pineappl_grid_convolve_with_one(grid, 2212, xfx1, alphas, &state, order_mask.get(),
channel_mask.get(), xir, xif, dxsec1.data());

// how does the grid know which PDFs it must be convolved with? This is determined by the
// metadata keys `initial_state_1` and `initial_state_2`, which are by default set to `2212`,
// the PDG MC ID for the proton. Let's change the second value to an antiproton:
pineappl_grid_set_key_value(grid, "initial_state_1", "2212");
char* initial_state_1 = pineappl_grid_key_value(grid, "initial_state_1");
assert( std::string(initial_state_1) == "2212" );
// don't forget to deallocate!
pineappl_string_delete(initial_state_1);

pineappl_grid_set_key_value(grid, "initial_state_2", "-2212");
char* initial_state_2 = pineappl_grid_key_value(grid, "initial_state_2");
assert( std::string(initial_state_2) == "-2212" );
// don't forget to deallocate!
pineappl_string_delete(initial_state_2);

std::vector<double> dxsec2(bins);

// this calculates the corresponding proton-antiproton differential cross sections. Since the
// grid itself is unchanged, this change effectively means that for the second PDF the charge
// convolved PDFs are used
pineappl_grid_convolve_with_one(grid, 2212, xfx1, alphas, pdf, order_mask.get(),
pineappl_grid_convolve_with_one(grid, 2212, xfx1, alphas, &state, order_mask.get(),
channel_mask.get(), xir, xif, dxsec2.data());

// what if we have a collision where we actually need two PDFs? Let's simulate the collision of
// protons with deuterons:
pineappl_grid_set_key_value(grid, "initial_state_2", "1000010020"); // 1000010020 = deuteron
char* new_initial_state_2 = pineappl_grid_key_value(grid, "initial_state_2");
assert( std::string(new_initial_state_2) == "1000010020" );
// don't forget to deallocate!
pineappl_string_delete(new_initial_state_2);

std::vector<double> dxsec3(bins);

// For proton-deuteron collisions we can't easily relate the PDFs and have to actually pass two
// different PDFs, each with their ID of the particle they represent:
pineappl_grid_convolve_with_two(grid, 2212, xfx1, 1000010020, xfx2, alphas, pdf,
// different PDFs, each with their ID of the particle they represent. In this example, we use
// the first PDF to compute alphasQ2.
pineappl_grid_convolve_with_two(grid, 2212, xfx1, 1000010020, xfx2, alphas, &state,
order_mask.get(), channel_mask.get(), xir, xif, dxsec3.data());

std::vector<double> dxsec4(bins);

// test with both masks set to `nullptr`
pineappl_grid_convolve_with_two(grid, 2212, xfx1, 1000010020, xfx2, alphas, pdf, nullptr,
// test with both masks set to `nullptr`. And in the following example, we use the second PDF
// to compue the values of alphasQ2
pineappl_grid_convolve_with_two(grid, 2212, xfx1, 1000010020, xfx2, alphas, &state, nullptr,
nullptr, xir, xif, dxsec4.data());

std::vector<double> normalizations(bins);
Expand Down
58 changes: 36 additions & 22 deletions examples/cpp/advanced-convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
#include <iomanip>
#include <ios>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

int main(int argc, char* argv[]) {
std::string filename = "drell-yan-rap-ll.pineappl.lz4";
std::string pdfset = "NNPDF31_nlo_as_0118_luxqed";
std::string pdfset1 = "NNPDF31_nlo_as_0118_luxqed";
std::string pdfset2 = "MSHT20qed_nnlo";

switch (argc) {
case 4:
pdfset2 = argv[3];
// fall through
case 3:
pdfset = argv[2];
pdfset1 = argv[2];
// set the two PDFs the same if only one is provided
if (argc == 3) pdfset2 = argv[2];
// fall through
case 2:
filename = argv[1];
Expand All @@ -31,13 +38,11 @@ int main(int argc, char* argv[]) {
// read the grid from a file
auto* grid = pineappl_grid_read(filename.c_str());

auto* pdf = LHAPDF::mkPDF(pdfset, 0);
auto pdf1 = std::unique_ptr<LHAPDF::PDF>(LHAPDF::mkPDF(pdfset1, 0));
auto pdf2 = std::unique_ptr<LHAPDF::PDF>(LHAPDF::mkPDF(pdfset2, 0));

// define callables for the PDFs and alphas, the grid collides two protons
auto xfx1 = [](int32_t id, double x, double q2, void* pdf) {
return static_cast <LHAPDF::PDF*> (pdf)->xfxQ2(id, x, q2);
};
auto xfx2 = [](int32_t id, double x, double q2, void* pdf) {
auto xfx = [](int32_t id, double x, double q2, void* pdf) {
return static_cast <LHAPDF::PDF*> (pdf)->xfxQ2(id, x, q2);
};
auto alphas = [](double q2, void* pdf) {
Expand All @@ -51,18 +56,18 @@ int main(int argc, char* argv[]) {
std::size_t bins = pineappl_grid_bin_count(grid);

// how many channels does the grid have?
auto* lumi = pineappl_grid_channels(grid);
std::size_t channels = pineappl_channels_count(lumi);
auto* channels = pineappl_grid_channels(grid);
std::size_t channels_length = pineappl_channels_count(channels);

pineappl_channels_delete(lumi);
pineappl_channels_delete(channels);

// std::vector<bool> doesn't have `.data()` member
std::unique_ptr<bool[]> order_mask(new bool[orders]());

// allocate a vector holding the differential cross sections
std::vector<double> dxsec1(bins);

std::unique_ptr<bool[]> channel_mask(new bool[channels]());
std::unique_ptr<bool[]> channel_mask(new bool[channels_length]());

// use the variables to select the included orders and channels
order_mask[0] = true;
Expand All @@ -71,42 +76,51 @@ int main(int argc, char* argv[]) {
// use these variables to perform scale variations
double xir = 1.0;
double xif = 1.0;
double xia = 1.0;

// with this choice `order_mask` and `channel_mask` we extract the contribution of the first
// perturbative order and first channel stored in the grid. If the grid contains cross sections
// of either a proton-proton, proton-antiproton or antiproton-antiproton collision PineAPPL will
// perform the necessary charge conjugations to yield the correct convolutions.
// In the case where the convolution requires two different PDFs, it suffices to modify `xfx1`
// and `xfx2`.
std::vector<double> mu_scales = { xir, xif, 1.0 };
using LambdaType = double(*)(int32_t, double, double, void *);
LambdaType xfxs[] = { xfx1, xfx2 };
// In the case where the convolution requires two different PDFs, it suffices to use different
// PDF sets in `pdf_states`.
std::vector<double> mu_scales = { xir, xif, xia };

pineappl_grid_convolve(grid, xfxs, alphas, pdf, order_mask.get(), channel_mask.get(), nullptr, 1,
mu_scales.data(), dxsec1.data());
std::vector<LHAPDF::PDF*> pdfs = {pdf1.get(), pdf2.get()};
void** pdf_states = reinterpret_cast<void**>(pdfs.data());

pineappl_grid_convolve(grid, xfx, alphas, pdf_states, pdf1.get(), order_mask.get(),
channel_mask.get(), nullptr, 1, mu_scales.data(), dxsec1.data());

// test with both masks set to `nullptr`
std::vector<double> dxsec2(bins);

pineappl_grid_convolve(grid, xfxs, alphas, pdf, nullptr, nullptr, nullptr, 1,
pineappl_grid_convolve(grid, xfx, alphas, pdf_states, pdf2.get(), nullptr, nullptr, nullptr, 1,
mu_scales.data(), dxsec2.data());

// test with both `mu_scales` set to `nullptr`
std::vector<double> dxsec3(bins);

pineappl_grid_convolve(grid, xfx, alphas,pdf_states, pdf2.get(), nullptr, nullptr, nullptr, 1,
nullptr, dxsec3.data());

std::vector<double> normalizations(bins);

// read out the bin normalizations, which is usually the size of each bin
pineappl_grid_bin_normalizations(grid, normalizations.data());

// print table header
std::cout << "idx p-p c#0 l#0 p-d dx\n"
"--- ------------ ------------ ------\n";
std::cout << "idx p-p c#0 l#0 p-d p-d (w/o μ) dx\n"
"--- ------------ ------------ ------------ ------\n";

for (std::size_t bin = 0; bin != bins; ++bin) {
// print the bin index
std::cout << std::setw(3) << bin << ' ';

// print the result together with the normalization
std::cout << std::scientific << dxsec1.at(bin) << ' ' << dxsec2.at(bin) << ' '
<< std::defaultfloat << std::setw(6) << normalizations.at(bin) << '\n';
<< dxsec3.at(bin) << ' ' << std::defaultfloat << std::setw(6)
<< normalizations.at(bin) << '\n';
}

pineappl_grid_delete(grid);
Expand Down
1 change: 1 addition & 0 deletions examples/cpp/advanced-filling-deprecated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int main() {
};

auto* keyval = pineappl_keyval_new();
pineappl_keyval_set_bool(keyval, "reweight", false);

auto* grid = pineappl_grid_new(channels, orders.size() / 4, orders.data(), bins.size() - 1,
bins.data(), keyval);
Expand Down
Loading