Skip to content

Commit 829626d

Browse files
committed
Add --repair switch to the CLI's write
1 parent 5533f4c commit 829626d

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- added `Grid::repair` to repair bugs that survived by writing bugged grids to
13-
disk, for example <https://github.com/NNPDF/pineappl/issues/338>
13+
disk, for example <https://github.com/NNPDF/pineappl/issues/338>. The CLI
14+
offers this functionality via `pineappl write --repair`
1415

1516
## [1.1.0] - 08/07/2025
1617

pineappl_cli/src/write.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum OpsArg {
4141
MulBinNorm(f64),
4242
Optimize(bool),
4343
OptimizeFkTable(FkAssumptions),
44+
Repair(bool),
4445
RewriteChannel((usize, Channel)),
4546
RewriteOrder((usize, Order)),
4647
RotatePidBasis(PidBasis),
@@ -85,7 +86,7 @@ impl FromArgMatches for MoreArgs {
8586
});
8687
}
8788
}
88-
"merge_channel_factors" | "optimize" | "split_channels" | "upgrade" => {
89+
"merge_channel_factors" | "optimize" | "repair" | "split_channels" | "upgrade" => {
8990
let arguments: Vec<Vec<_>> = matches
9091
.remove_occurrences(&id)
9192
.unwrap()
@@ -98,6 +99,7 @@ impl FromArgMatches for MoreArgs {
9899
args[index] = Some(match id.as_str() {
99100
"merge_channel_factors" => OpsArg::MergeChannelFactors(arg[0]),
100101
"optimize" => OpsArg::Optimize(arg[0]),
102+
"repair" => OpsArg::Repair(arg[0]),
101103
"split_channels" => OpsArg::SplitChannels(arg[0]),
102104
"upgrade" => OpsArg::Upgrade(arg[0]),
103105
_ => unreachable!(),
@@ -394,6 +396,17 @@ impl Args for MoreArgs {
394396
.try_map(|s| s.parse::<FkAssumptions>()),
395397
),
396398
)
399+
.arg(
400+
Arg::new("repair")
401+
.action(ArgAction::Append)
402+
.default_missing_value("true")
403+
.help("Repair bugs saved in the grid")
404+
.long("repair")
405+
.num_args(0..=1)
406+
.require_equals(true)
407+
.value_name("ENABLE")
408+
.value_parser(clap::value_parser!(bool)),
409+
)
397410
.arg(
398411
Arg::new("rewrite_channel")
399412
.action(ArgAction::Append)
@@ -583,6 +596,9 @@ impl Subcommand for Opts {
583596
// UNWRAP: this cannot fail because we only modify the normalizations
584597
.unwrap();
585598
}
599+
OpsArg::Repair(true) => {
600+
grid.repair();
601+
}
586602
OpsArg::RewriteChannel((index, new_channel)) => {
587603
// TODO: check that `index` is valid
588604
grid.channels_mut()[*index] = new_channel.clone();
@@ -618,6 +634,7 @@ impl Subcommand for Opts {
618634
OpsArg::SplitChannels(true) => grid.split_channels(),
619635
OpsArg::Upgrade(true) => grid.upgrade(),
620636
OpsArg::MergeChannelFactors(false)
637+
| OpsArg::Repair(false)
621638
| OpsArg::Optimize(false)
622639
| OpsArg::SplitChannels(false)
623640
| OpsArg::Upgrade(false) => {}

pineappl_cli/tests/write.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Options:
2424
--mul-bin-norm <NORM> Multiply all bin normalizations with the given factor
2525
--optimize[=<ENABLE>] Optimize internal data structure to minimize memory and disk usage [possible values: true, false]
2626
--optimize-fk-table <OPTIMI> Optimize internal data structure of an FkTable to minimize memory and disk usage [possible values: Nf6Ind, Nf6Sym, Nf5Ind, Nf5Sym, Nf4Ind, Nf4Sym, Nf3Ind, Nf3Sym]
27+
--repair[=<ENABLE>] Repair bugs saved in the grid [possible values: true, false]
2728
--rewrite-channel <IDX> <CHAN> Rewrite the definition of the channel with index IDX
2829
--rewrite-order <IDX> <ORDER> Rewrite the definition of the order with index IDX
2930
--rotate-pid-basis <BASIS> Rotate the PID basis for this grid [possible values: PDG, EVOL]
@@ -876,6 +877,23 @@ fn multiple_arguments() {
876877
.stdout(MULTIPLE_ARGUMENTS_STR);
877878
}
878879

880+
#[test]
881+
fn repair() {
882+
let output = NamedTempFile::new("repaired-grid.pineappl.lz4").unwrap();
883+
884+
Command::cargo_bin("pineappl")
885+
.unwrap()
886+
.args([
887+
"write",
888+
"--repair",
889+
"../test-data/LHCB_WP_7TEV_opt.pineappl.lz4",
890+
output.path().to_str().unwrap(),
891+
])
892+
.assert()
893+
.success()
894+
.stdout("");
895+
}
896+
879897
#[test]
880898
fn rewrite_channels() {
881899
let output = NamedTempFile::new("ckm_channels.pineappl.lz4").unwrap();

0 commit comments

Comments
 (0)