Skip to content

Commit

Permalink
Complete coverage of the C and Python APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Jan 20, 2025
1 parent 072ebc5 commit 91c1f95
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 9 deletions.
4 changes: 4 additions & 0 deletions examples/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PROGRAMS = \
display-channels-deprecated \
display-channels \
display-orders \
display-orders-deprecated \
merge-grids \
modify-grid

Expand Down Expand Up @@ -52,6 +53,9 @@ display-channels-deprecated: display-channels-deprecated.cpp
display-channels: display-channels.cpp
$(CXX) $(CXXFLAGS) $< $(PINEAPPL_DEPS) -o $@

display-orders-deprecated: display-orders-deprecated.cpp
$(CXX) $(CXXFLAGS) $< $(PINEAPPL_DEPS) -o $@

display-orders: display-orders.cpp
$(CXX) $(CXXFLAGS) $< $(PINEAPPL_DEPS) -o $@

Expand Down
52 changes: 52 additions & 0 deletions examples/cpp/display-orders-deprecated.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <pineappl_capi.h>

#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

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

switch (argc) {
case 2:
filename = argv[1];
case 1:
break;

default:
std::cout << "Usage: " << argv[0] << " [grid]\n";
}

// read the grid from a file
auto* grid = pineappl_grid_read(filename.c_str());

// how many perturbative orders does this grid contain?
std::size_t orders = pineappl_grid_order_count(grid);

std::vector<std::uint32_t> order_params(4 * orders);

// read out all exponents of the perturbative orders in the grid
pineappl_grid_order_params(grid, order_params.data());

for (std::size_t order = 0; order != orders; ++order) {
std::cout << std::setw(4) << order << ' ';

// exponent of the strong coupling
std::uint32_t exp_as = order_params.at(4 * order + 0);
// exponent of the electromagnetic/electroweak coupling
std::uint32_t exp_al = order_params.at(4 * order + 1);
// exponent of the renormalization log
std::uint32_t exp_lr = order_params.at(4 * order + 2);
// exponent of the factorization log
std::uint32_t exp_lf = order_params.at(4 * order + 3);

std::cout << "O(as^" << exp_as << " a^" << exp_al << " lr^" << exp_lr << " lf^" << exp_lf
<< ")\n";
}

// release memory
pineappl_grid_delete(grid);
}
18 changes: 10 additions & 8 deletions examples/cpp/display-orders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@ int main(int argc, char* argv[]) {
// how many perturbative orders does this grid contain?
std::size_t orders = pineappl_grid_order_count(grid);

std::vector<std::uint32_t> order_params(4 * orders);
std::vector<std::uint32_t> order_params(5 * orders);

// read out all exponents of the perturbative orders in the grid
pineappl_grid_order_params(grid, order_params.data());
pineappl_grid_order_params2(grid, order_params.data());

for (std::size_t order = 0; order != orders; ++order) {
std::cout << std::setw(4) << order << ' ';
std::cout << std::setw(5) << order << ' ';

// exponent of the strong coupling
std::uint32_t exp_as = order_params.at(4 * order + 0);
std::uint32_t exp_as = order_params.at(5 * order + 0);
// exponent of the electromagnetic/electroweak coupling
std::uint32_t exp_al = order_params.at(4 * order + 1);
std::uint32_t exp_al = order_params.at(5 * order + 1);
// exponent of the renormalization log
std::uint32_t exp_lr = order_params.at(4 * order + 2);
std::uint32_t exp_lr = order_params.at(5 * order + 2);
// exponent of the factorization log
std::uint32_t exp_lf = order_params.at(4 * order + 3);
std::uint32_t exp_lf = order_params.at(5 * order + 3);
// exponent of the fragmentation log
std::uint32_t exp_la = order_params.at(5 * order + 4);

std::cout << "O(as^" << exp_as << " a^" << exp_al << " lr^" << exp_lr << " lf^" << exp_lf
<< ")\n";
<< " la^" << exp_la<< ")\n";
}

// release memory
Expand Down
3 changes: 3 additions & 0 deletions examples/cpp/output
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ idx p-p c#0 l#0 p-p~ c#0 l# p-d c#0 l#0 p-d dx
1 1 x ( 1, -1) + 1 x ( 3, -3) + 1 x ( 5, -5)
0 1 x ( 22, 22)
1 1 x ( 1, -1) + 1 x ( 3, -3) + 1 x ( 5, -5)
0 O(as^0 a^2 lr^0 lf^0 la^0)
1 O(as^1 a^2 lr^0 lf^0 la^0)
2 O(as^1 a^2 lr^0 lf^1 la^0)
0 O(as^0 a^2 lr^0 lf^0)
1 O(as^1 a^2 lr^0 lf^0)
2 O(as^1 a^2 lr^0 lf^1)
4 changes: 3 additions & 1 deletion pineappl_py/tests/test_boc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
from pineappl.boc import Channel, Kinematics, Order, ScaleFuncForm
from pineappl.boc import Channel, Kinematics, Order, ScaleFuncForm, Scales


class TestChannel:
Expand Down Expand Up @@ -52,7 +52,9 @@ class TestScaleFuncForm:
def test_init(self, scaletype: ScaleFuncForm, argument: list):
scale_method = getattr(ScaleFuncForm, scaletype)
result = scale_method(*argument)
scale_funcs = Scales(ren=result, fac=result, frg=result)
assert isinstance(result, ScaleFuncForm)
assert isinstance(scale_funcs, Scales)


class TestOrder:
Expand Down

0 comments on commit 91c1f95

Please sign in to comment.