Skip to content

Commit

Permalink
check for error raising
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed May 2, 2024
1 parent 24d74af commit ef295c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/pineko/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ def write_operator_card(pineappl_grid, default_card, card_path, tcard):
opconf["ev_op_iterations"] = 1
elif tcard["ModEv"] == "EXA":
opconf["evolution_method"] = "iterate-exact"
opconf["ev_op_iterations"] = tcard["IterEv"]
if "IterEv" in tcard:
opconf["ev_op_iterations"] = tcard["IterEv"]
elif "ev_op_iterations" not in default_card["configs"]:
raise ValueError(
"EXA used but IterEv not found in the theory card and not ev_op_iterations set in the template"
)

# If the information was also in the template _and it is different_, warn
for key in ["evolution_method", "ev_op_iterations"]:
Expand Down
16 changes: 8 additions & 8 deletions tests/test_evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ def test_write_operator_card_q0(tmp_path):
"""Checks https://github.com/NNPDF/pineko/issues/146"""
p = tmp_path / "q0.yaml"
g = FakePine()
# 1. defaults
t = copy.deepcopy(default_card)
o = copy.deepcopy(example.raw_operator())
# 1. Same Q0 and mu0, all ok
t["Q0"] = 5.0
o["mu0"] = 5.0
_xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t)
with open(p, encoding="utf8") as f:
oo = yaml.safe_load(f)
np.testing.assert_allclose(oo["mu0"], t["Q0"])
# 2. overwriting from theory side
t["Q0"] = 10.0
# 2. Q0 only in theory, all ok
o.pop("mu0")
_xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t)
with open(p, encoding="utf8") as f:
oo = yaml.safe_load(f)
np.testing.assert_allclose(oo["mu0"], t["Q0"])
# 3. op template is ignored
# 3. op is different, raises error
o["mu0"] = 11.0
_xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t)
with open(p, encoding="utf8") as f:
oo = yaml.safe_load(f)
np.testing.assert_allclose(oo["mu0"], t["Q0"])
with pytest.raises(ValueError):
_xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t)

0 comments on commit ef295c0

Please sign in to comment.