Skip to content

Commit

Permalink
Merge branch 'master' into fix-macos-cli-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Apr 23, 2024
2 parents 40d962a + b323985 commit 4f7a3cd
Show file tree
Hide file tree
Showing 35 changed files with 336 additions and 279 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- changed the official name of the CLI subcommand `convolute` to `convolve`,
because the latter is the proper verb of 'convolution'. The old name
`convolute` is now an alias of `convolve`, which means both can be used. The
methods `Grid::convolute*` are left unchanged and will be renamed in later
version
- changed switch `--silence-lhapdf` to `--lhapdf-banner` and suppress LHAPDF's
banners by default, unless `--lhapdf-banner` is given
- `Grid::evolve` has now been marked deprecated
- switched from `lhapdf` to `managed-lhapdf` crate which automatically
downloads PDF sets when they are needed
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 47 additions & 18 deletions install-capi.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/sh

# WARNING: do not commit changes to this file unless you've checked it against
# `shellcheck` (https://www.shellcheck.net/); run `shellcheck install-capi.sh`
# to make sure this script is POSIX shell compatible; we cannot rely on bash
# being present

set -eu

prefix=
Expand Down Expand Up @@ -51,21 +56,26 @@ if [ -z ${target+x} ]; then
target=x86_64-unknown-linux-gnu;;
*)
echo "Error: unknown target, uname = '$(uname -a)'"
exit 1;;
esac
fi

# if no prefix is given, prompt for one
if [ -z ${prefix} ]; then
if [ -z "${prefix}" ]; then
# read from stdin (`<&1`), even if piped into a shell
read -p "Enter installation path: " <&1 prefix
printf "Enter installation path: "
read -r <&1 prefix
echo
fi

if [ ! -d "${prefix}" ]; then
mkdir -p "${prefix}"
fi
# we need the absolute path; use `eval` to expand possible tilde `~`
eval mkdir -p "${prefix}"
eval cd "${prefix}"
prefix=$(pwd)
cd - >/dev/null

# if no version is given, use the latest version
if [ -z ${version} ]; then
if [ -z "${version}" ]; then
version=$(curl -s https://api.github.com/repos/NNPDF/pineappl/releases/latest | \
sed -n 's/[ ]*"tag_name"[ ]*:[ ]*"v\([^"]*\)"[ ]*,[ ]*$/\1/p')
fi
Expand All @@ -76,27 +86,46 @@ echo "prefix: ${prefix}"
echo "target: ${target}"
echo "version: ${version}"

# we need the absolute path
cd "${prefix}"
prefix=$(pwd)
cd - >/dev/null

curl -s -LJ "${base_url}"/v${version}/pineappl_capi-${target}.tar.gz \
curl -s -LJ "${base_url}/v${version}/pineappl_capi-${target}.tar.gz" \
| tar xzf - -C "${prefix}"

# instead of `sed` and `mv` we could use `sed -i`, but on Mac it doesn't work as expected from GNU sed
sed s:prefix=/:prefix=${prefix}: "${prefix}"/lib/pkgconfig/pineappl_capi.pc > \
sed "s:prefix=/:prefix=${prefix}:" "${prefix}"/lib/pkgconfig/pineappl_capi.pc > \
"${prefix}"/lib/pkgconfig/pineappl_capi.pc.new
mv "${prefix}"/lib/pkgconfig/pineappl_capi.pc.new "${prefix}"/lib/pkgconfig/pineappl_capi.pc

pcbin=

if command -v pkg-config >/dev/null; then
if ! pkg-config --libs pineappl_capi >/dev/null; then
pcbin=$(command -v pkg-config)
elif command -v pkgconf >/dev/null; then
pcbin=$(command -v pkgconf)
else
echo
echo "Warning: neither \`pkg-config\` nor \`pkgconf\` not found. At least one is needed for the CAPI to be found"
exit 1
fi

# check whether the library can be found
if "${pcbin}" --libs pineappl_capi >/dev/null 2>/dev/null; then
prefix_lib=$(cd "${prefix}"/lib && pwd)
found_lib=$("${pcbin}" --keep-system-libs --libs-only-L pineappl_capi | sed 's/-L[[:space:]]*//')

if [ "${prefix_lib}" != "${found_lib}" ]; then
echo
echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set. Try adding"
echo " export PKG_CONFIG_PATH=${prefix}/lib/pkgconfig"
echo "to your shell configuration file"
echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set."
echo "It appears a different installation of PineAPPL is found:"
echo
echo " ${found_lib}"
echo
echo "Remove this installation or reorder your PKG_CONFIG_PATH"
fi
else
echo
echo "Warning: \`pkg-config\` binary not found. Without it the CAPI may not be found."
echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set."
echo "Try adding"
echo
echo " export PKG_CONFIG_PATH=${prefix}/lib/pkgconfig${PKG_CONFIG_PATH:+:\"\${PKG_CONFIG_PATH\}\"}"
echo
echo "to your shell configuration file"
fi
35 changes: 35 additions & 0 deletions pineappl/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,41 @@ impl Grid {
}
}

/// Deletes channels with the corresponding `channel_indices`. Repeated indices and indices
/// larger or equal than the number of channels are ignored.
pub fn delete_channels(&mut self, channel_indices: &[usize]) {
let mut channel_indices: Vec<_> = channel_indices
.iter()
.copied()
// ignore indices corresponding to bin that don't exist
.filter(|&index| index < self.lumi().len())
.collect();

// sort and remove repeated indices
channel_indices.sort_unstable();
channel_indices.dedup();
let channel_indices = channel_indices;

let mut channel_ranges: Vec<Range<_>> = Vec::new();

// convert indices into consecutive ranges
for &channel_index in &channel_indices {
match channel_ranges.last_mut() {
Some(range) if range.end == channel_index => range.end += 1,
_ => channel_ranges.push(channel_index..(channel_index + 1)),
}
}

// reverse order so we don't invalidate indices
channel_ranges.reverse();
let channel_ranges = channel_ranges;

for range in channel_ranges.into_iter() {
self.lumi.drain(range.clone());
self.subgrids.slice_axis_inplace(Axis(2), range.into());
}
}

pub(crate) fn rewrite_lumi(&mut self, add: &[(i32, i32)], del: &[i32]) {
self.lumi = self
.lumi
Expand Down
6 changes: 3 additions & 3 deletions pineappl_cli/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ impl Subcommand for CkfOpts {
};

let limit = grid.lumi().len().min(self.limit);
let limits = helpers::convolute_limits(&grid, &[], ConvoluteMode::Normal);
let limits = helpers::convolve_limits(&grid, &[], ConvoluteMode::Normal);
let results: Vec<_> = (0..grid.lumi().len())
.map(|lumi| {
let mut lumi_mask = vec![false; grid.lumi().len()];
lumi_mask[lumi] = true;
helpers::convolute(
helpers::convolve(
&grid,
&mut pdf,
&[self.order],
Expand All @@ -101,7 +101,7 @@ impl Subcommand for CkfOpts {
.map(|lumi| {
let mut lumi_mask = vec![false; grid.lumi().len()];
lumi_mask[lumi] = true;
helpers::convolute(
helpers::convolve(
&grid,
&mut pdf,
&orders_den,
Expand Down
4 changes: 2 additions & 2 deletions pineappl_cli/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Subcommand for Opts {
} else {
limit.min(lumis.len())
};
let limits = helpers::convolute_limits(
let limits = helpers::convolve_limits(
&grid,
&[],
if self.integrated {
Expand All @@ -87,7 +87,7 @@ impl Subcommand for Opts {
.map(|lumi| {
let mut lumi_mask = vec![false; grid.lumi().len()];
lumi_mask[lumi] = true;
helpers::convolute(
helpers::convolve(
&grid,
&mut pdf,
&self.orders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::process::ExitCode;

/// Convolutes a PineAPPL grid with a PDF set.
#[derive(Parser)]
#[command(alias = "convolute")]
pub struct Opts {
/// Path of the input grid.
#[arg(value_hint = ValueHint::FilePath)]
Expand Down Expand Up @@ -51,7 +52,7 @@ impl Subcommand for Opts {
let mut pdf = helpers::create_pdf(&self.pdfsets[0])?;
let bins: Vec<_> = self.bins.iter().cloned().flatten().collect();

let results = helpers::convolute(
let results = helpers::convolve(
&grid,
&mut pdf,
&self.orders,
Expand All @@ -65,7 +66,7 @@ impl Subcommand for Opts {
},
cfg,
);
let limits = helpers::convolute_limits(
let limits = helpers::convolve_limits(
&grid,
&bins,
if self.integrated {
Expand All @@ -80,7 +81,7 @@ impl Subcommand for Opts {
.iter()
.flat_map(|pdfset| {
let mut pdf = helpers::create_pdf(pdfset).unwrap();
helpers::convolute(
helpers::convolve(
&grid,
&mut pdf,
&self.orders,
Expand Down
14 changes: 7 additions & 7 deletions pineappl_cli/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Subcommand for Opts {
title.add_cell(cell);
}

let limits1 = helpers::convolute_limits(&grid1, &[], ConvoluteMode::Normal);
let limits1 = helpers::convolve_limits(&grid1, &[], ConvoluteMode::Normal);

if self.ignore_orders {
let mut cell = cell!(c->"diff");
Expand All @@ -146,7 +146,7 @@ impl Subcommand for Opts {

table.set_titles(title);

let results1 = helpers::convolute(
let results1 = helpers::convolve(
&grid1,
&mut pdf,
&orders1,
Expand All @@ -156,7 +156,7 @@ impl Subcommand for Opts {
ConvoluteMode::Normal,
cfg,
);
let results2 = helpers::convolute(
let results2 = helpers::convolve(
&grid2,
&mut pdf,
&orders2,
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Subcommand for Opts {
row.add_cell(cell!(r->format!("{:.*e}", self.digits_abs, result1)));
row.add_cell(cell!(r->format!("{:.*e}", self.digits_abs, result2)));
row.add_cell(cell!(r->format!("{:.*e}", self.digits_rel,
if result1 == result2 { 0.0 } else { result1 / result2 - 1.0 })));
if result1 == result2 { 0.0 } else { result2 / result1 - 1.0 })));
}
} else {
let orders = orders1;
Expand All @@ -202,7 +202,7 @@ impl Subcommand for Opts {
let order_results1: Vec<Vec<f64>> = orders
.iter()
.map(|&order| {
helpers::convolute(
helpers::convolve(
&grid1,
&mut pdf,
&[order],
Expand All @@ -217,7 +217,7 @@ impl Subcommand for Opts {
let order_results2: Vec<Vec<f64>> = orders
.iter()
.map(|&order| {
helpers::convolute(
helpers::convolve(
&grid2,
&mut pdf,
&[order],
Expand Down Expand Up @@ -245,7 +245,7 @@ impl Subcommand for Opts {
row.add_cell(cell!(r->format!("{:.*e}", self.digits_abs, result1)));
row.add_cell(cell!(r->format!("{:.*e}", self.digits_abs, result2)));
row.add_cell(cell!(r->format!("{:.*e}", self.digits_rel,
if result1 == result2 { 0.0 } else { result1 / result2 - 1.0 })));
if result1 == result2 { 0.0 } else { result2 / result1 - 1.0 })));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pineappl_cli/src/evolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ impl Subcommand for Opts {

let grid = helpers::read_grid(&self.input)?;
let mut pdf = helpers::create_pdf(&self.pdfset)?;
let results = helpers::convolute_scales(
let results = helpers::convolve_scales(
&grid,
&mut pdf,
&self.orders,
Expand All @@ -563,7 +563,7 @@ impl Subcommand for Opts {
self.xif,
self.use_old_evolve,
)?;
let evolved_results = helpers::convolute_scales(
let evolved_results = helpers::convolve_scales(
fk_table.grid(),
&mut pdf,
&[],
Expand Down
2 changes: 1 addition & 1 deletion pineappl_cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Subcommand for Opts {
println!("file was converted, but we cannot check the conversion for this type");
} else {
let mut pdf = helpers::create_pdf(&self.pdfset)?;
let reference_results = helpers::convolute(
let reference_results = helpers::convolve(
&grid,
&mut pdf,
&orders,
Expand Down
10 changes: 5 additions & 5 deletions pineappl_cli/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub enum ConvoluteMode {
Normal,
}

pub fn convolute_scales(
pub fn convolve_scales(
grid: &Grid,
lhapdf: &mut Pdf,
orders: &[(u32, u32)],
Expand Down Expand Up @@ -210,7 +210,7 @@ pub fn convolute_scales(
}
}

pub fn convolute(
pub fn convolve(
grid: &Grid,
lhapdf: &mut Pdf,
orders: &[(u32, u32)],
Expand All @@ -220,7 +220,7 @@ pub fn convolute(
mode: ConvoluteMode,
cfg: &GlobalConfiguration,
) -> Vec<f64> {
convolute_scales(
convolve_scales(
grid,
lhapdf,
orders,
Expand All @@ -232,7 +232,7 @@ pub fn convolute(
)
}

pub fn convolute_limits(grid: &Grid, bins: &[usize], mode: ConvoluteMode) -> Vec<Vec<(f64, f64)>> {
pub fn convolve_limits(grid: &Grid, bins: &[usize], mode: ConvoluteMode) -> Vec<Vec<(f64, f64)>> {
let limits: Vec<_> = grid
.bin_info()
.limits()
Expand All @@ -247,7 +247,7 @@ pub fn convolute_limits(grid: &Grid, bins: &[usize], mode: ConvoluteMode) -> Vec
}
}

pub fn convolute_subgrid(
pub fn convolve_subgrid(
grid: &Grid,
lhapdf: &mut Pdf,
order: usize,
Expand Down
Loading

0 comments on commit 4f7a3cd

Please sign in to comment.