Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix condition to new damping convention #142

Merged
merged 8 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
hooks:
- id: pycln
args: [--config=pyproject.toml]
- repo: https://github.com/psf/black
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black
Expand Down
1 change: 0 additions & 1 deletion benchmarks/bench_fonll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
import pytest
import yaml

Expand Down
23 changes: 14 additions & 9 deletions src/pineko/fonll.py
andreab1997 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ def __init__(
"ffns5til": ffns5til,
"ffns5bar": ffns5bar,
}
actually_existing_paths = [p for p in self.paths if self.paths[p] is not None]
actually_existing_paths = [p for p, g in self.paths.items() if g is not None]
for p in self.paths:
if p not in actually_existing_paths:
logger.warning(
f"Warning! FK table for {p} does not exist and thus is being skipped."
"Warning! FK table for %s does not exist and thus is being skipped.",
p,
)

@property
def fk_paths(self):
"""Returns the list of the FK table paths needed to produce FONLL predictions."""
return {p: Path(self.paths[p]) for p in self.paths if self.paths[p] is not None}
return {p: Path(self.paths[p]) for p, g in self.paths.items() if g is not None}

@property
def fks(self):
Expand Down Expand Up @@ -106,8 +107,11 @@ def Q2grid(self):


def update_fk_theorycard(combined_fk, input_theorycard_path):
"""Update theorycard entries for the combined fktable by reading the yamldb of the original theory."""
with open(input_theorycard_path) as f:
"""Update theorycard entries for the combined FK table.

Update by reading the yamldb of the original theory.
"""
with open(input_theorycard_path, encoding="utf-8") as f:
final_theorycard = yaml.safe_load(f)
theorycard = json.loads(combined_fk.key_values()["theory"])
theorycard["FNS"] = final_theorycard["FNS"]
Expand Down Expand Up @@ -147,8 +151,8 @@ def combine(fk_dict, dampings=None):
sign = -1 if fk in FK_WITH_MINUS else 1
fk_dict[fk].scale(sign)
if dampings is not None:
for mass in FK_TO_DAMP:
if fk in FK_TO_DAMP[mass]:
for mass, fks in FK_TO_DAMP.items():
if fk in fks:
fk_dict[fk].scale_by_bin(dampings[mass])
fk_dict[fk].write_lz4(tmpfile_path)
combined_fk.merge_from_file(tmpfile_path)
Expand Down Expand Up @@ -235,7 +239,7 @@ def collect_updates(fonll_fns, damp):
"""Produce the different theory cards according to which FONLL is asked for."""
updates = []
is_mixed = fonll_fns in MIXED_ORDER_FNS
is_damped = damp != 0
is_damped = damp == 1
giacomomagni marked this conversation as resolved.
Show resolved Hide resolved
base_pto = FNS_BASE_PTO[fonll_fns]
cfgs = MIXED_FNS_CONFIG if is_mixed or is_damped else FNS_CONFIG
for cfg in cfgs:
Expand All @@ -260,7 +264,8 @@ def collect_updates(fonll_fns, damp):
def dump_tcards(tcard, tcard_parent_path, theoryid):
"""Produce the seven FONLL theory cards from the original one.

The produced theory cards are dumped in `tcard_parent_path` with names from '{theoryid}00.yaml' to '{theoryid}06.yaml'.
The produced theory cards are dumped in `tcard_parent_path` with names
from '{theoryid}00.yaml' to '{theoryid}06.yaml'.
"""
updates = collect_updates(tcard["FNS"], tcard["DAMP"])
andreab1997 marked this conversation as resolved.
Show resolved Hide resolved
n_theory = len(updates)
Expand Down
Loading