Skip to content

Commit a148573

Browse files
committed
Migrate most direct LHAPDF calls to new backend code
1 parent a788300 commit a148573

6 files changed

Lines changed: 108 additions & 95 deletions

File tree

pineappl_cli/src/analyze.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ pub struct CkfOpts {
6464
impl Subcommand for CkfOpts {
6565
fn run(&self, cfg: &GlobalConfiguration) -> Result<ExitCode> {
6666
let grid = helpers::read_grid(&self.input)?;
67-
let mut conv_funs = helpers::create_conv_funs(&self.conv_funs)?;
67+
let mut conv_funs =
68+
helpers::create_conv_funs_with_backend(&self.conv_funs, cfg.pdf_backend)?;
6869

6970
let orders_den = if self.orders_den.is_empty() {
7071
grid.orders()
@@ -84,7 +85,7 @@ impl Subcommand for CkfOpts {
8485
.map(|lumi| {
8586
let mut lumi_mask = vec![false; grid.channels().len()];
8687
lumi_mask[lumi] = true;
87-
helpers::convolve(
88+
helpers::convolve_with_backend(
8889
&grid,
8990
&mut conv_funs,
9091
&self.conv_funs.conv_types,
@@ -101,7 +102,7 @@ impl Subcommand for CkfOpts {
101102
.map(|lumi| {
102103
let mut lumi_mask = vec![false; grid.channels().len()];
103104
lumi_mask[lumi] = true;
104-
helpers::convolve(
105+
helpers::convolve_with_backend(
105106
&grid,
106107
&mut conv_funs,
107108
&self.conv_funs.conv_types,

pineappl_cli/src/channels.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ pub struct Opts {
6464
impl Subcommand for Opts {
6565
fn run(&self, cfg: &GlobalConfiguration) -> Result<ExitCode> {
6666
let grid = helpers::read_grid(&self.input)?;
67-
let mut conv_funs = helpers::create_conv_funs(&self.conv_funs)?;
67+
let mut conv_funs =
68+
helpers::create_conv_funs_with_backend(&self.conv_funs, cfg.pdf_backend)?;
6869

6970
let mut channels: Vec<_> = self.channels.iter().cloned().flatten().collect();
7071
channels.sort_unstable();
@@ -90,7 +91,7 @@ impl Subcommand for Opts {
9091
.map(|channel| {
9192
let mut channel_mask = vec![false; grid.channels().len()];
9293
channel_mask[channel] = true;
93-
helpers::convolve(
94+
helpers::convolve_with_backend(
9495
&grid,
9596
&mut conv_funs,
9697
&self.conv_funs.conv_types,

pineappl_cli/src/diff.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ impl Subcommand for Opts {
120120
bail!("channels differ");
121121
}
122122

123-
let mut conv_funs = helpers::create_conv_funs(&self.conv_funs)?;
123+
let mut conv_funs =
124+
helpers::create_conv_funs_with_backend(&self.conv_funs, cfg.pdf_backend)?;
124125

125126
let mut table = helpers::create_table();
126127
let mut title = Row::empty();
@@ -140,7 +141,7 @@ impl Subcommand for Opts {
140141

141142
table.set_titles(title);
142143

143-
let results1 = helpers::convolve(
144+
let results1 = helpers::convolve_with_backend(
144145
&grid1,
145146
&mut conv_funs,
146147
&self.conv_funs.conv_types,
@@ -151,7 +152,7 @@ impl Subcommand for Opts {
151152
ConvoluteMode::Normal,
152153
cfg,
153154
);
154-
let results2 = helpers::convolve(
155+
let results2 = helpers::convolve_with_backend(
155156
&grid2,
156157
&mut conv_funs,
157158
&self.conv_funs.conv_types,
@@ -206,7 +207,7 @@ impl Subcommand for Opts {
206207
let order_results1: Vec<Vec<f64>> = orders
207208
.iter()
208209
.map(|&order| {
209-
helpers::convolve(
210+
helpers::convolve_with_backend(
210211
&grid1,
211212
&mut conv_funs,
212213
&self.conv_funs.conv_types,
@@ -222,7 +223,7 @@ impl Subcommand for Opts {
222223
let order_results2: Vec<Vec<f64>> = orders
223224
.iter()
224225
.map(|&order| {
225-
helpers::convolve(
226+
helpers::convolve_with_backend(
226227
&grid2,
227228
&mut conv_funs,
228229
&self.conv_funs.conv_types,

pineappl_cli/src/evolve.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::helpers::{self, ConvFuns, ConvoluteMode};
2+
use super::pdf_backend::PdfBackend;
23
use super::{GlobalConfiguration, Subcommand};
34
use anyhow::{Result, anyhow};
45
use clap::{Parser, ValueHint};
5-
use lhapdf::Pdf;
66
use pineappl::fk_table::FkTable;
77
use pineappl::grid::Grid;
88
use std::path::{Path, PathBuf};
@@ -497,7 +497,7 @@ mod eko {
497497
fn evolve_grid(
498498
grid: &Grid,
499499
ekos: &[&Path],
500-
use_alphas_from: &Pdf,
500+
use_alphas_from: &dyn PdfBackend,
501501
orders: &[(u8, u8)],
502502
xir: f64,
503503
xif: f64,
@@ -531,7 +531,7 @@ fn evolve_grid(
531531
fn evolve_grid(
532532
_: &Grid,
533533
_: &[&Path],
534-
_: &Pdf,
534+
_: &dyn PdfBackend,
535535
_: &[(u8, u8)],
536536
_: f64,
537537
_: f64,
@@ -590,8 +590,9 @@ impl Subcommand for Opts {
590590
use prettytable::row;
591591

592592
let grid = helpers::read_grid(&self.input)?;
593-
let mut conv_funs = helpers::create_conv_funs(&self.conv_funs)?;
594-
let results = helpers::convolve_scales(
593+
let mut conv_funs =
594+
helpers::create_conv_funs_with_backend(&self.conv_funs, cfg.pdf_backend)?;
595+
let results = helpers::convolve_scales_with_backend(
595596
&grid,
596597
&mut conv_funs,
597598
&self.conv_funs.conv_types,
@@ -607,14 +608,14 @@ impl Subcommand for Opts {
607608
let fk_table = evolve_grid(
608609
&grid,
609610
&eko_paths,
610-
&conv_funs[cfg.use_alphas_from],
611+
&*conv_funs[cfg.use_alphas_from],
611612
&self.orders,
612613
self.xir,
613614
self.xif,
614615
self.xia,
615616
)?;
616617

617-
let evolved_results = helpers::convolve_scales(
618+
let evolved_results = helpers::convolve_scales_with_backend(
618619
fk_table.grid(),
619620
&mut conv_funs,
620621
&self.conv_funs.conv_types,

pineappl_cli/src/orders.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub struct Opts {
4141
impl Subcommand for Opts {
4242
fn run(&self, cfg: &GlobalConfiguration) -> Result<ExitCode> {
4343
let grid = helpers::read_grid(&self.input)?;
44-
let mut conv_funs = helpers::create_conv_funs(&self.conv_funs)?;
44+
let mut conv_funs =
45+
helpers::create_conv_funs_with_backend(&self.conv_funs, cfg.pdf_backend)?;
4546

4647
let mut orders: Vec<_> = grid
4748
.orders()
@@ -63,7 +64,7 @@ impl Subcommand for Opts {
6364
let results: Vec<Vec<f64>> = orders
6465
.iter()
6566
.map(|order| {
66-
helpers::convolve(
67+
helpers::convolve_with_backend(
6768
&grid,
6869
&mut conv_funs,
6970
&self.conv_funs.conv_types,

pineappl_cli/src/pull.rs

Lines changed: 84 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::helpers::{self, ConvFuns, ConvoluteMode};
2+
use super::pdf_backend::{PdfBackend, PdfSetBackend};
23
use super::{GlobalConfiguration, Subcommand};
34
use anyhow::{Error, Result};
45
use clap::{Parser, ValueHint};
5-
use lhapdf::{Pdf, PdfSet};
66
use prettytable::{Row, cell};
77
use rayon::{ThreadPoolBuilder, prelude::*};
88
use std::num::NonZeroUsize;
@@ -52,10 +52,16 @@ impl Subcommand for Opts {
5252
fn run(&self, cfg: &GlobalConfiguration) -> Result<ExitCode> {
5353
let grid = helpers::read_grid(&self.input)?;
5454

55-
let (set1, mut conv_funs1) =
56-
helpers::create_conv_funs_for_set(&self.conv_funs1, self.pull_from)?;
57-
let (set2, mut conv_funs2) =
58-
helpers::create_conv_funs_for_set(&self.conv_funs2, self.pull_from)?;
55+
let (set1, mut conv_funs1) = helpers::create_conv_funs_for_set_with_backend(
56+
&self.conv_funs1,
57+
self.pull_from,
58+
cfg.pdf_backend,
59+
)?;
60+
let (set2, mut conv_funs2) = helpers::create_conv_funs_for_set_with_backend(
61+
&self.conv_funs2,
62+
self.pull_from,
63+
cfg.pdf_backend,
64+
)?;
5965

6066
ThreadPoolBuilder::new()
6167
.num_threads(self.threads)
@@ -67,7 +73,7 @@ impl Subcommand for Opts {
6773
let results1: Vec<_> = conv_funs1
6874
.par_iter_mut()
6975
.map(|funs| {
70-
Ok::<_, Error>(helpers::convolve(
76+
Ok::<_, Error>(helpers::convolve_with_backend(
7177
&grid,
7278
funs,
7379
&self.conv_funs1.conv_types,
@@ -86,7 +92,7 @@ impl Subcommand for Opts {
8692
let results2: Vec<_> = conv_funs2
8793
.par_iter_mut()
8894
.map(|funs| {
89-
Ok::<_, Error>(helpers::convolve(
95+
Ok::<_, Error>(helpers::convolve_with_backend(
9096
&grid,
9197
funs,
9298
&self.conv_funs2.conv_types,
@@ -141,79 +147,81 @@ impl Subcommand for Opts {
141147
(diff / unc1.hypot(unc2), unc1, unc2)
142148
};
143149

144-
let channel_results =
145-
|conv_funs: &ConvFuns, pdfset: &mut [Vec<Pdf>], set: &PdfSet| -> Vec<f64> {
146-
if let Some(member) = conv_funs.members[self.pull_from] {
147-
(0..grid.channels().len())
148-
.map(|channel| {
149-
let mut channel_mask = vec![false; grid.channels().len()];
150-
channel_mask[channel] = true;
151-
match helpers::convolve(
152-
&grid,
153-
&mut pdfset[member],
154-
&conv_funs.conv_types,
155-
&self.orders,
156-
&[bin],
157-
&channel_mask,
158-
1,
159-
ConvoluteMode::Normal,
160-
cfg,
161-
)
162-
.as_slice()
163-
{
164-
[value] => *value,
165-
_ => unreachable!(),
166-
}
167-
})
168-
.collect()
169-
} else {
170-
let results: Vec<_> = pdfset
171-
.iter_mut()
172-
.flat_map(|fun| {
173-
(0..grid.channels().len())
174-
.map(|channel| {
175-
let mut channel_mask = vec![false; grid.channels().len()];
176-
channel_mask[channel] = true;
177-
match helpers::convolve(
178-
&grid,
179-
fun,
180-
&conv_funs.conv_types,
181-
&self.orders,
182-
&[bin],
183-
&channel_mask,
184-
1,
185-
ConvoluteMode::Normal,
186-
cfg,
187-
)
188-
.as_slice()
189-
{
190-
[value] => *value,
191-
_ => unreachable!(),
192-
}
193-
})
194-
.collect::<Vec<_>>()
195-
})
196-
.collect();
197-
198-
(0..grid.channels().len())
199-
.map(|channel| {
200-
let central: Vec<_> = results
201-
.iter()
202-
.skip(channel)
203-
.step_by(grid.channels().len())
204-
.copied()
205-
.collect();
206-
set.uncertainty(&central, self.cl, false).unwrap().central
207-
})
208-
.collect()
209-
}
210-
};
150+
let channel_results = |conv_funs: &ConvFuns,
151+
pdfset: &mut [Vec<Box<dyn PdfBackend>>],
152+
set: &dyn PdfSetBackend|
153+
-> Vec<f64> {
154+
if let Some(member) = conv_funs.members[self.pull_from] {
155+
(0..grid.channels().len())
156+
.map(|channel| {
157+
let mut channel_mask = vec![false; grid.channels().len()];
158+
channel_mask[channel] = true;
159+
match helpers::convolve_with_backend(
160+
&grid,
161+
&mut pdfset[member],
162+
&conv_funs.conv_types,
163+
&self.orders,
164+
&[bin],
165+
&channel_mask,
166+
1,
167+
ConvoluteMode::Normal,
168+
cfg,
169+
)
170+
.as_slice()
171+
{
172+
[value] => *value,
173+
_ => unreachable!(),
174+
}
175+
})
176+
.collect()
177+
} else {
178+
let results: Vec<_> = pdfset
179+
.iter_mut()
180+
.flat_map(|fun| {
181+
(0..grid.channels().len())
182+
.map(|channel| {
183+
let mut channel_mask = vec![false; grid.channels().len()];
184+
channel_mask[channel] = true;
185+
match helpers::convolve_with_backend(
186+
&grid,
187+
fun,
188+
&conv_funs.conv_types,
189+
&self.orders,
190+
&[bin],
191+
&channel_mask,
192+
1,
193+
ConvoluteMode::Normal,
194+
cfg,
195+
)
196+
.as_slice()
197+
{
198+
[value] => *value,
199+
_ => unreachable!(),
200+
}
201+
})
202+
.collect::<Vec<_>>()
203+
})
204+
.collect();
205+
206+
(0..grid.channels().len())
207+
.map(|channel| {
208+
let central: Vec<_> = results
209+
.iter()
210+
.skip(channel)
211+
.step_by(grid.channels().len())
212+
.copied()
213+
.collect();
214+
set.uncertainty(&central, self.cl, false).unwrap().central
215+
})
216+
.collect()
217+
}
218+
};
211219

212220
let mut pull_tuples = if self.limit == 0 {
213221
Vec::new()
214222
} else {
215-
let channel_results1 = channel_results(&self.conv_funs1, &mut conv_funs1, &set1);
216-
let channel_results2 = channel_results(&self.conv_funs2, &mut conv_funs2, &set2);
223+
let channel_results1 = channel_results(&self.conv_funs1, &mut conv_funs1, &*set1);
224+
let channel_results2 = channel_results(&self.conv_funs2, &mut conv_funs2, &*set2);
217225

218226
let pull_tuples: Vec<_> = channel_results2
219227
.iter()

0 commit comments

Comments
 (0)