Skip to content

Commit

Permalink
Restore remaining ignored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Oct 24, 2024
1 parent 08a1490 commit d9b50e3
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 44 deletions.
131 changes: 128 additions & 3 deletions pineappl/src/boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ pub enum ScaleFuncForm {
Scale(usize),
/// TODO
QuadraticSum(usize, usize),
/// TODO
QuadraticMean(usize, usize),
/// TODO
QuadraticSumOver4(usize, usize),
/// TODO
LinearMean(usize, usize),
/// TODO
LinearSum(usize, usize),
/// TODO
ScaleMax(usize, usize),
/// TODO
ScaleMin(usize, usize),
/// TODO
Prod(usize, usize),
/// TODO
S2plusS1half(usize, usize),
/// TODO
Pow4Sum(usize, usize),
/// TODO
WgtAvg(usize, usize),
/// TODO
S2plusS1fourth(usize, usize),
/// TODO
ExpProd2(usize, usize),
}

impl ScaleFuncForm {
Expand All @@ -63,16 +87,79 @@ impl ScaleFuncForm {
)
}
}
Self::QuadraticSum(_, _) => todo!(),
Self::QuadraticSum(idx1, idx2)
| Self::QuadraticMean(idx1, idx2)
| Self::QuadraticSumOver4(idx1, idx2)
| Self::LinearMean(idx1, idx2)
| Self::LinearSum(idx1, idx2)
| Self::ScaleMax(idx1, idx2)
| Self::ScaleMin(idx1, idx2)
| Self::Prod(idx1, idx2)
| Self::S2plusS1half(idx1, idx2)
| Self::Pow4Sum(idx1, idx2)
| Self::WgtAvg(idx1, idx2)
| Self::S2plusS1fourth(idx1, idx2)
| Self::ExpProd2(idx1, idx2) => {
let calc_scale: fn((f64, f64)) -> f64 = match self.clone() {
Self::QuadraticSum(_, _) => |(s1, s2)| s1 + s2,
Self::QuadraticMean(_, _) => |(s1, s2)| 0.5 * (s1 + s2),
Self::QuadraticSumOver4(_, _) => |(s1, s2)| 0.25 * (s1 + s2),
Self::LinearMean(_, _) => |(s1, s2)| 0.25 * (s1.sqrt() + s2.sqrt()).powi(2),
Self::LinearSum(_, _) => |(s1, s2)| (s1.sqrt() + s2.sqrt()).powi(2),
Self::ScaleMax(_, _) => |(s1, s2)| s1.max(s2),
Self::ScaleMin(_, _) => |(s1, s2)| s1.min(s2),
Self::Prod(_, _) => |(s1, s2)| s1 * s2,
Self::S2plusS1half(_, _) => |(s1, s2)| 0.5 * (s1 + 2.0 * s2),
Self::Pow4Sum(_, _) => |(s1, s2)| (s1 * s1 + s2 * s2).sqrt(),
Self::WgtAvg(_, _) => |(s1, s2)| (s1 * s1 + s2 * s2) / (s1 + s2),
Self::S2plusS1fourth(_, _) => |(s1, s2)| 0.25 * s1 + s2,
Self::ExpProd2(_, _) => {
|(s1, s2)| (s1.sqrt() * (0.3 * s2.sqrt()).exp()).powi(2)
}
_ => unreachable!(),
};

let scales1 = &node_values[kinematics
.iter()
.position(|&kin| kin == Kinematics::Scale(idx1))
// UNWRAP: this should be guaranteed by `Grid::new`
.unwrap_or_else(|| unreachable!())];
let scales2 = &node_values[kinematics
.iter()
.position(|&kin| kin == Kinematics::Scale(idx2))
// UNWRAP: this should be guaranteed by `Grid::new`
.unwrap_or_else(|| unreachable!())];

Cow::Owned(
scales1
.iter()
.copied()
.cartesian_product(scales2.iter().copied())
.map(calc_scale)
.collect(),
)
}
}
}

/// TODO
pub fn idx(&self, indices: &[usize]) -> usize {
pub fn idx(&self, indices: &[usize], scale_dims: &[usize]) -> usize {
match self.clone() {
Self::NoScale => unreachable!(),
Self::Scale(index) => indices[index],
Self::QuadraticSum(_, _) => todo!(),
Self::QuadraticSum(idx1, idx2)
| Self::QuadraticMean(idx1, idx2)
| Self::QuadraticSumOver4(idx1, idx2)
| Self::LinearMean(idx1, idx2)
| Self::LinearSum(idx1, idx2)
| Self::ScaleMax(idx1, idx2)
| Self::ScaleMin(idx1, idx2)
| Self::Prod(idx1, idx2)
| Self::S2plusS1half(idx1, idx2)
| Self::Pow4Sum(idx1, idx2)
| Self::WgtAvg(idx1, idx2)
| Self::S2plusS1fourth(idx1, idx2)
| Self::ExpProd2(idx1, idx2) => indices[idx1] * scale_dims[1] + indices[idx2],
}
}
}
Expand Down Expand Up @@ -105,6 +192,18 @@ impl Scales {
.iter()
.any(|&kin| kin == Kinematics::Scale(index)) => {}
ScaleFuncForm::QuadraticSum(idx1, idx2)
| ScaleFuncForm::QuadraticMean(idx1, idx2)
| ScaleFuncForm::QuadraticSumOver4(idx1, idx2)
| ScaleFuncForm::LinearMean(idx1, idx2)
| ScaleFuncForm::LinearSum(idx1, idx2)
| ScaleFuncForm::ScaleMax(idx1, idx2)
| ScaleFuncForm::ScaleMin(idx1, idx2)
| ScaleFuncForm::Prod(idx1, idx2)
| ScaleFuncForm::S2plusS1half(idx1, idx2)
| ScaleFuncForm::Pow4Sum(idx1, idx2)
| ScaleFuncForm::WgtAvg(idx1, idx2)
| ScaleFuncForm::S2plusS1fourth(idx1, idx2)
| ScaleFuncForm::ExpProd2(idx1, idx2)
if kinematics.iter().any(|&kin| kin == Kinematics::Scale(idx1))
&& kinematics.iter().any(|&kin| kin == Kinematics::Scale(idx2)) => {}
_ => return false,
Expand Down Expand Up @@ -656,6 +755,7 @@ macro_rules! channel {
#[cfg(test)]
mod tests {
use super::*;
use float_cmp::assert_approx_eq;

#[test]
fn order_from_str() {
Expand Down Expand Up @@ -908,4 +1008,29 @@ mod tests {
"PID tuples have different lengths"
);
}

#[test]
fn scale_func_form() {
let node_values = [vec![1.0, 2.0, 3.0], vec![4.0, 5.0]];
let kinematics = [Kinematics::Scale(0), Kinematics::Scale(1)];
let sff = ScaleFuncForm::QuadraticSum(0, 1);

let ref_calc = [5.0, 6.0, 6.0, 7.0, 7.0, 8.0];
let calc = sff.calc(&node_values, &kinematics).into_owned();

assert_eq!(calc.len(), ref_calc.len());

for (&calc, ref_calc) in calc.iter().zip(ref_calc) {
assert_approx_eq!(f64, calc, ref_calc, ulps = 2);
}

let scale_dims = [3, 2];

assert_eq!(sff.idx(&[0, 0, 1], &scale_dims), 0);
assert_eq!(sff.idx(&[0, 1, 1], &scale_dims), 1);
assert_eq!(sff.idx(&[1, 0, 1], &scale_dims), 2);
assert_eq!(sff.idx(&[1, 1, 1], &scale_dims), 3);
assert_eq!(sff.idx(&[2, 0, 1], &scale_dims), 4);
assert_eq!(sff.idx(&[2, 1, 1], &scale_dims), 5);
}
}
27 changes: 20 additions & 7 deletions pineappl/src/convolutions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ impl<'a> ConvolutionCache<'a> {
imu2: [const { Vec::new() }; SCALES_CNT],
scales: grid.scales().clone(),
ix: Vec::new(),
scale_dims: Vec::new(),
}
}

Expand All @@ -166,6 +167,7 @@ pub struct GridConvCache<'a, 'b> {
imu2: [Vec<usize>; SCALES_CNT],
scales: Scales,
ix: Vec<Vec<usize>>,
scale_dims: Vec<usize>,
}

impl GridConvCache<'_, '_> {
Expand Down Expand Up @@ -198,12 +200,14 @@ impl GridConvCache<'_, '_> {
let ConvCache1d { xfx, cache, conv } = &mut self.cache.caches[idx];

let (scale, scale_idx) = match conv.conv_type() {
ConvType::UnpolPDF | ConvType::PolPDF => {
(FAC_IDX, self.scales.fac.idx(indices_scales))
}
ConvType::UnpolFF | ConvType::PolFF => {
(FRG_IDX, self.scales.frg.idx(indices_scales))
}
ConvType::UnpolPDF | ConvType::PolPDF => (
FAC_IDX,
self.scales.fac.idx(indices_scales, &self.scale_dims),
),
ConvType::UnpolFF | ConvType::PolFF => (
FRG_IDX,
self.scales.frg.idx(indices_scales, &self.scale_dims),
),
};

let imu2 = self.imu2[scale][scale_idx];
Expand All @@ -216,7 +220,7 @@ impl GridConvCache<'_, '_> {
})
.product();
let alphas_powers = if as_order != 0 {
let ren_scale_idx = self.scales.ren.idx(indices_scales);
let ren_scale_idx = self.scales.ren.idx(indices_scales, &self.scale_dims);
self.cache.alphas_cache[self.imu2[REN_IDX][ren_scale_idx]].powi(as_order.into())
} else {
1.0
Expand Down Expand Up @@ -264,6 +268,15 @@ impl GridConvCache<'_, '_> {
.collect()
})
.collect();

self.scale_dims = grid
.kinematics()
.iter()
.zip(node_values)
.filter_map(|(kin, node_values)| {
matches!(kin, Kinematics::Scale(_)).then_some(node_values.len())
})
.collect();
}
}

Expand Down
12 changes: 10 additions & 2 deletions pineappl/src/evolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ fn ndarray_from_subgrid_orders_slice_many(
}

let node_values = subgrid.node_values();
let scale_dims: Vec<_> = grid
.kinematics()
.iter()
.zip(&node_values)
.filter_map(|(kin, node_values)| {
matches!(kin, Kinematics::Scale(_)).then_some(node_values.len())
})
.collect();

let x1_indices: Vec<Vec<_>> = kinematics
.iter()
Expand All @@ -318,8 +326,8 @@ fn ndarray_from_subgrid_orders_slice_many(

for (indices, value) in subgrid.indexed_iter() {
// TODO: implement evolution for non-zero fragmentation scales
let ren = rens[grid.scales().ren.idx(&indices)];
let fac = facs[grid.scales().fac.idx(&indices)];
let ren = rens[grid.scales().ren.idx(&indices, &scale_dims)];
let fac = facs[grid.scales().fac.idx(&indices, &scale_dims)];

if !approx_eq!(f64, xif * xif * fac, fac1, ulps = EVOLUTION_TOL_ULPS) {
continue;
Expand Down
24 changes: 12 additions & 12 deletions pineappl_cli/src/import/fastnlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,18 @@ fn convert_scale_functional_form(ff: EScaleFunctionalForm) -> ScaleFuncForm {
EScaleFunctionalForm::kScale1 => ScaleFuncForm::Scale(0),
EScaleFunctionalForm::kScale2 => ScaleFuncForm::Scale(1),
EScaleFunctionalForm::kQuadraticSum => ScaleFuncForm::QuadraticSum(0, 1),
EScaleFunctionalForm::kQuadraticMean => todo!(),
EScaleFunctionalForm::kQuadraticSumOver4 => todo!(),
EScaleFunctionalForm::kLinearMean => todo!(),
EScaleFunctionalForm::kLinearSum => todo!(),
EScaleFunctionalForm::kScaleMax => todo!(),
EScaleFunctionalForm::kScaleMin => todo!(),
EScaleFunctionalForm::kProd => todo!(),
EScaleFunctionalForm::kS2plusS1half => todo!(),
EScaleFunctionalForm::kPow4Sum => todo!(),
EScaleFunctionalForm::kWgtAvg => todo!(),
EScaleFunctionalForm::kS2plusS1fourth => todo!(),
EScaleFunctionalForm::kExpProd2 => todo!(),
EScaleFunctionalForm::kQuadraticMean => ScaleFuncForm::QuadraticMean(0, 1),
EScaleFunctionalForm::kQuadraticSumOver4 => ScaleFuncForm::QuadraticSumOver4(0, 1),
EScaleFunctionalForm::kLinearMean => ScaleFuncForm::LinearMean(0, 1),
EScaleFunctionalForm::kLinearSum => ScaleFuncForm::LinearSum(0, 1),
EScaleFunctionalForm::kScaleMax => ScaleFuncForm::ScaleMax(0, 1),
EScaleFunctionalForm::kScaleMin => ScaleFuncForm::ScaleMin(0, 1),
EScaleFunctionalForm::kProd => ScaleFuncForm::Prod(0, 1),
EScaleFunctionalForm::kS2plusS1half => ScaleFuncForm::S2plusS1half(0, 1),
EScaleFunctionalForm::kPow4Sum => ScaleFuncForm::Pow4Sum(0, 1),
EScaleFunctionalForm::kWgtAvg => ScaleFuncForm::WgtAvg(0, 1),
EScaleFunctionalForm::kS2plusS1fourth => ScaleFuncForm::S2plusS1fourth(0, 1),
EScaleFunctionalForm::kExpProd2 => ScaleFuncForm::ExpProd2(0, 1),
_ => unimplemented!(),
}
}
Expand Down
Loading

0 comments on commit d9b50e3

Please sign in to comment.