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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/actions/cache-data/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# .github/actions/cache-data/action.yml

name: Cache Data for the Tests
description: Caches and downloads data
runs:
using: "composite"
steps:
- name: Cache data
id: cache-data
uses: actions/cache@v4
with:
path: neopdf-data
key: data-v4
- name: Download data if cache miss
if: steps.cache-data.outputs.cache-hit != 'true'
run: |
cd maintainer
./download-data.sh
shell: bash
12 changes: 1 addition & 11 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Get data
id: cache-data
uses: actions/cache@v4
with:
path: neopdf-data
key: data-v3

- name: Download data
if: steps.cache-data.outputs.cache-hit != 'true'
run: |
cd maintainer
./download-data.sh
uses: ./.github/actions/cache-data

- name: Cache Criterion baseline
uses: actions/cache@v4
Expand Down
11 changes: 1 addition & 10 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Get data
id: cache-data
uses: actions/cache@v4
with:
path: neopdf-data
key: data-v3
- name: Download data
if: steps.cache-data.outputs.cache-hit != 'true'
run: |
cd maintainer
./download-data.sh
uses: ./.github/actions/cache-data
- name: Build NeoPDF crate 🦀
run: cargo build --release
- name: Run tests 🚀
Expand Down
15 changes: 15 additions & 0 deletions docs/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ body {
.md-content__inner li {
text-align: justify;
}

/* Hide Jupyter input/output prompts in mkdocs-jupyter */
.jp-InputPrompt, .jp-OutputPrompt, .prompt, .nbinput .prompt, .nboutput .prompt {
display: none !important;
}

/* Slightly increase font size in notebook code cells for mkdocs-jupyter and similar renderers */
div.nbinput .input_area pre,
div.input_area pre,
div.jp-InputArea-editor,
div.jp-CodeCell .jp-InputArea-editor,
div.highlight pre,
pre {
font-size: 1.06em !important;
}
106 changes: 42 additions & 64 deletions docs/examples/c-oop.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ below in the case the grid should explicitly depend on more parameters.
is correct. However, this makes the codes very verbose. To easily spot the parts that
actually fills the grid, some lines are highlighted.

```cpp linenums="1" hl_lines="62-70 73-81 93 101 118-138 148"
#include "neopdf_capi.h"
```cpp linenums="1" hl_lines="62-70 51-59 62-70 83-95 97-115 126"
#include <NeoPDF.hpp>
#include <cassert>
#include <cmath>
Expand Down Expand Up @@ -315,31 +314,21 @@ int main() {
// Extract the number of subgrids
std::size_t num_subgrids = ref_pdf.num_subgrids();

// Create a collection
NeoPDFGridArrayCollection* collection = neopdf_gridarray_collection_new();
if (!collection) {
std::cerr << "Failed to create grid array collection!\n";
return 1;
}
// Create a grid writer
GridWriter writer;

// For each member, build a grid
for (size_t m = 0; m < neo_pdfs.size(); ++m) {
NeoPDF& pdf = neo_pdfs[m];
NeoPDFGrid* grid = neopdf_grid_new();

if (!grid) {
std::cerr << "Failed to create grid for member: " << m << "!\n";
continue;
}

bool member_ok = true;
// Loop over the Subgrids
for (std::size_t subgrid_idx = 0; subgrid_idx != num_subgrids; subgrid_idx++) {
// Extract the parameter values of the given subgrid
// Extract the knot values of the parameters for the subgrid
auto xs = pdf.subgrid_for_param(NEOPDF_SUBGRID_PARAMS_MOMENTUM, subgrid_idx);
auto q2s = pdf.subgrid_for_param(NEOPDF_SUBGRID_PARAMS_SCALE, subgrid_idx);
auto alphas = pdf.subgrid_for_param(NEOPDF_SUBGRID_PARAMS_ALPHAS, subgrid_idx);
auto nucleons = pdf.subgrid_for_param(NEOPDF_SUBGRID_PARAMS_NUCLEONS, subgrid_idx);
auto kts = pdf.subgrid_for_param(NEOPDF_SUBGRID_PARAMS_KT, subgrid_idx);

// Compute grid_data: [q2s][xs][flavors], instead of [nucleons][alphas][q2s][xs][flavors]
// NOTE: This assumes that there is no 'A' and `alphas` dependence.
Expand All @@ -353,87 +342,76 @@ int main() {
}
}

// Add subgrid
int add_subgrid =neopdf_grid_add_subgrid(
grid,
nucleons.data(), nucleons.size(),
alphas.data(), alphas.size(),
kts.data(), kts.size(),
xs.data(), xs.size(),
q2s.data(), q2s.size(),
grid_data.data(), grid_data.size()
// Add grid
writer.add_grid(
nucleons,
alphas,
kts,
xs,
q2s,
grid_data,
pids
);
if (add_subgrid != NEOPDF_RESULT_SUCCESS) {
std::cerr << "Failed to add subgrid for member: " << m << "!\n";
neopdf_grid_free(grid);
member_ok = false;
break;
}
}

if (!member_ok) continue;

// Set flavor PIDs
int add_flavors = neopdf_grid_set_flavors(grid, pids.data(), pids.size());
if (add_flavors != NEOPDF_RESULT_SUCCESS) {
std::cerr << "Failed to set flavors for member: " << m << "!\n";
neopdf_grid_free(grid);
continue;
}

// Add grid to collection
int add_grid = neopdf_gridarray_collection_add_grid(collection, grid);
if (add_grid != NEOPDF_RESULT_SUCCESS) {
std::cerr << "Failed to add grid to collection for member: " << m << "!\n";
neopdf_grid_free(grid);
continue;
}
std::cout << "Added grid for member " << m << "\n";
}

// Fill the running of alphas with some random values
double alphas_qs[] = {2.0};
double alphas_vals[] = {0.118};
std::vector<double> alphas_qs = {2.0};
std::vector<double> alphas_vals = {0.118};

// Extract the ranges for the momentum x and scale Q2
auto x_range = ref_pdf.param_range(NEOPDF_SUBGRID_PARAMS_MOMENTUM);
auto q2_range = ref_pdf.param_range(NEOPDF_SUBGRID_PARAMS_SCALE);

NeoPDFMetaData meta = {
PhysicsParameters phys_params = {
.flavor_scheme = "variable",
.order_qcd = 2,
.alphas_order_qcd = 2,
.m_w = 80.352,
.m_z = 91.1876,
.m_up = 0.0,
.m_down = 0.0,
.m_strange = 0.0,
.m_charm = 1.51,
.m_bottom = 4.92,
.m_top = 172.5,
};

MetaData meta = {
.set_desc = "NNPDF40_nnlo_as_01180 collection",
.set_index = 0,
.num_members = (uint32_t)neo_pdfs.size(),
.x_min = x_range[0],
.x_max = x_range[1],
.q_min = sqrt(q2_range[0]),
.q_max = sqrt(q2_range[1]),
.flavors = pids.data(),
.num_flavors = (size_t)pids.size(),
.flavors = pids,
.format = "neopdf",
.alphas_q_values = alphas_qs,
.num_alphas_q = 1,
.alphas_vals = alphas_vals,
.num_alphas_vals = 1,
.polarised = false,
.set_type = SET_TYPE_PDF,
.set_type = SET_TYPE_SPACE_LIKE,
.interpolator_type = INTERPOLATOR_TYPE_LOG_BICUBIC,
.error_type = "replicas",
.hadron_pid = 2212,
.phys_params = phys_params,
};

// Check if `NEOPDF_DATA_PATH` is defined and store the Grid there.
const char* filename = "check-writer.neopdf.lz4";
const char* filename = "check-writer-oop.neopdf.lz4";
const char* neopdf_path = std::getenv("NEOPDF_DATA_PATH");
std::string output_path = neopdf_path
? std::string(neopdf_path) + (std::string(neopdf_path).back() == '/' ? "" : "/") + filename
: filename;

// Write the PDF Grid into disk
int result = neopdf_grid_compress(collection, &meta, output_path.c_str());
if (result != 0) {
std::cerr << "Compression failed with code " << result << "\n";
} else {
std::cout << "Compression succeeded!" << "\n";
try {
writer.compress(meta, output_path);
std::cout << "Compression succeeded!\n";
} catch (const std::runtime_error& err) {
std::cerr << "Compression failed: " << err.what() << "\n";
return EXIT_FAILURE;
}

// If `NEOPDF_DATA_PATH` is defined, reload the grid and check ther results.
Expand All @@ -454,7 +432,7 @@ int main() {
assert(std::abs(res2 - ref2) < TOLERANCE);
}

return result == 0 ? 0 : 1;
return EXIT_SUCCESS;
}
```

Expand Down
23 changes: 20 additions & 3 deletions docs/examples/c.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ the process of constructing a grid for each PDF member and serializing the colle
is correct. However, this makes the codes very verbose. To easily spot the parts that
actually fills the grid, some lines are highlighted.

```cpp linenums="1" hl_lines="110-119 122-130 139 147 166-186 196"
```cpp linenums="1" hl_lines="112-121 124-132 141 149 168-180 182-203 213"
#include <cstddef>
#include <neopdf_capi.h>
#include <cassert>
Expand Down Expand Up @@ -320,11 +320,13 @@ int main() {
auto q2s = extract_subgrid_params(pdf, NEOPDF_SUBGRID_PARAMS_SCALE, subgrid_idx, num_subgrids);
auto alphas = extract_subgrid_params(pdf, NEOPDF_SUBGRID_PARAMS_ALPHAS, subgrid_idx, num_subgrids);
auto nucleons = extract_subgrid_params(pdf, NEOPDF_SUBGRID_PARAMS_NUCLEONS, subgrid_idx, num_subgrids);
auto kts = extract_subgrid_params(pdf, NEOPDF_SUBGRID_PARAMS_KT, subgrid_idx, num_subgrids);

// Compute grid_data: [q2s][xs][flavors], instead of [nucleons][alphas][q2s][xs][flavors]
// NOTE: This assumes that there is no 'A' and `alphas` dependence.
assert(nucleons.size() == 1);
assert(alphas.size() == 1);
assert(kts.size() == 1);
std::vector<double> grid_data;
for (size_t xi = 0; xi < xs.size(); ++xi) {
for (size_t qi = 0; qi < q2s.size(); ++qi) {
Expand Down Expand Up @@ -381,6 +383,20 @@ int main() {
neopdf_pdf_param_range(neo_pdfs.pdfs[0], NEOPDF_SUBGRID_PARAMS_MOMENTUM, x_range.data());
neopdf_pdf_param_range(neo_pdfs.pdfs[0], NEOPDF_SUBGRID_PARAMS_SCALE, q2_range.data());

NeoPDFPhysicsParameters phys_params = {
.flavor_scheme = "variable",
.order_qcd = 2,
.alphas_order_qcd = 2,
.m_w = 80.352,
.m_z = 91.1876,
.m_up = 0.0,
.m_down = 0.0,
.m_strange = 0.0,
.m_charm = 1.51,
.m_bottom = 4.92,
.m_top = 172.5,
};

NeoPDFMetaData meta = {
.set_desc = "NNPDF40_nnlo_as_01180 collection",
.set_index = 0,
Expand All @@ -397,10 +413,11 @@ int main() {
.alphas_vals = alphas_vals,
.num_alphas_vals = 1,
.polarised = false,
.set_type = SET_TYPE_PDF,
.set_type = SET_TYPE_SPACE_LIKE,
.interpolator_type = INTERPOLATOR_TYPE_LOG_BICUBIC,
.error_type = "replicas",
.hadron_pid = 2212,
.phys_params = phys_params,
};

// Check if `NEOPDF_DATA_PATH` is defined and store the Grid there.
Expand Down Expand Up @@ -439,7 +456,7 @@ int main() {
neopdf_pdf_free(wpdf);
}

// Remove objects from memory.
// Cleanup
neopdf_gridarray_collection_free(collection);
neopdf_pdf_array_free(neo_pdfs);

Expand Down
Loading