Skip to content

Commit

Permalink
Exposes more Python methods for pineko
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Nov 12, 2024
1 parent 98f89f4 commit af78cb4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
16 changes: 16 additions & 0 deletions pineappl_py/src/fk_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ impl PyFkTable {
Ok(self.fk_table.table().into_pyarray_bound(py))
}

/// Get the type(s) of convolution(s) for the current FK table.
///
/// Returns
/// list(PyConv):
/// list of convolution type with the corresponding PIDs
#[getter]
#[must_use]
pub fn convolutions(&self) -> Vec<PyConv> {
self.fk_table
.grid()
.convolutions()
.iter()
.map(|conv| PyConv { conv: conv.clone() })
.collect()
}

/// Get number of bins.
///
/// Returns
Expand Down
2 changes: 1 addition & 1 deletion pineappl_py/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ impl PyGrid {
/// Returns
/// list(PyConv):
/// list of convolution type with the corresponding PIDs
#[getter]
#[must_use]
pub fn convolutions(&self) -> Vec<PyConv> {
self.grid
Expand Down Expand Up @@ -721,6 +722,5 @@ pub fn register(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
"import sys; sys.modules['pineappl.grid'] = m"
);
m.add_class::<PyGrid>()?;
m.add_class::<PyOrder>()?;
parent_module.add_submodule(&m)
}
4 changes: 2 additions & 2 deletions pineappl_py/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import subprocess
from typing import List

from pineappl.boc import Channel, Kinematics, ScaleFuncForm, Scales
from pineappl.boc import Channel, Kinematics, ScaleFuncForm, Scales, Order
from pineappl.convolutions import Conv
from pineappl.grid import Grid, Order
from pineappl.grid import Grid
from pineappl.interpolation import (
Interp,
InterpolationMethod,
Expand Down
7 changes: 4 additions & 3 deletions pineappl_py/tests/test_bin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import numpy as np
import pytest

from pineappl.boc import Channel
from pineappl.boc import Channel, Order
from pineappl.bin import BinRemapper
from pineappl.convolutions import Conv, ConvType
from pineappl.grid import Order


class TestBinRemapper:
Expand Down Expand Up @@ -38,7 +37,9 @@ def test_binremapper(self, fake_grids):
bin_dims = g.bin_dimensions()
bin_limits = [
(left, right)
for left, right in zip(g.bin_left(bin_dims - 1), g.bin_right(bin_dims - 1))
for left, right in zip(
g.bin_left(bin_dims - 1), g.bin_right(bin_dims - 1)
)
]
normalizations = [10.0 for _ in g.bin_normalizations()]

Expand Down
11 changes: 9 additions & 2 deletions pineappl_py/tests/test_fk_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import numpy as np
import tempfile

from pineappl.boc import Channel
from pineappl.boc import Channel, Order
from pineappl.convolutions import Conv, ConvType
from pineappl.fk_table import FkAssumptions, FkTable
from pineappl.grid import Order
from pineappl.import_subgrid import ImportSubgridV1


Expand Down Expand Up @@ -147,6 +146,14 @@ def test_polarized_convolution(
fk_table = download_objects(f"{fkname}")
fk = FkTable.read(fk_table)

# Check the FK table convolutions
convolutions = fk.convolutions
assert len(convolutions) == 2
assert convolutions[0].conv_type.polarized
assert not convolutions[0].conv_type.time_like
assert not convolutions[1].conv_type.polarized
assert not convolutions[1].conv_type.time_like

# Convolution object of the 1st hadron - Polarized
h1 = ConvType(polarized=True, time_like=False)
h1_conv = Conv(conv_type=h1, pid=2212)
Expand Down
8 changes: 4 additions & 4 deletions pineappl_py/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from numpy.random import Generator, PCG64

from pineappl.bin import BinRemapper
from pineappl.boc import Channel, Kinematics, Scales
from pineappl.boc import Channel, Kinematics, Scales, Order
from pineappl.convolutions import Conv, ConvType
from pineappl.evolution import OperatorSliceInfo
from pineappl.fk_table import FkTable
from pineappl.grid import Grid, Order
from pineappl.grid import Grid
from pineappl.import_subgrid import ImportSubgridV1
from pineappl.pids import PidBasis

Expand Down Expand Up @@ -221,7 +221,7 @@ def test_grid(
g = Grid.read(grid)

# Get the types of convolutions for this grid
for conv in g.convolutions():
for conv in g.convolutions:
assert isinstance(conv, Conv)

# Check that the scalings work, ie run without error
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_polarized_convolution(
g = Grid.read(grid)

# Check the Grid convolutions - can be used to construct `grid.convolve`
convolutions = g.convolutions()
convolutions = g.convolutions
assert len(convolutions) == 2
assert convolutions[0].conv_type.polarized
assert not convolutions[0].conv_type.time_like
Expand Down

0 comments on commit af78cb4

Please sign in to comment.