Skip to content

Commit

Permalink
Lift scale check for LHAPDF
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Jul 16, 2024
1 parent cb6953d commit d5f63fe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
19 changes: 16 additions & 3 deletions src/ekobox/evol_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pathlib

import numpy as np

from eko import basis_rotation as br
from eko.io import EKO
from eko.runner import managed
Expand Down Expand Up @@ -46,6 +48,18 @@ def evolve_pdfs(
info_update : dict
dict of info to add or update to default info file
"""
# separate by nf the evolgrid (and order per nf/q)
q2block_per_nf = regroup_evolgrid(operators_card.mugrid)

# check we have disjoint scale ranges
nfs = list(q2block_per_nf.keys())
for j in range(len(nfs) - 1):
# equal points are allowed by LHAPDF
if q2block_per_nf[nfs[j]][-1] > q2block_per_nf[nfs[j + 1]][0]:
raise ValueError(
f"Last scale point for nf={nfs[j]} is bigger than first in nf={nfs[j+1]}"
)

# update op and th cards
if path is not None:
eko_path = pathlib.Path(path)
Expand Down Expand Up @@ -79,9 +93,8 @@ def evolve_pdfs(
info_update=info_update,
)

# separate by nf the evolgrid (and order per nf/q)
q2block_per_nf = regroup_evolgrid(eko_output.evolgrid)

# in the eko scales are squared
q2block_per_nf = {nf: np.power(q2s, 2) for nf, q2s in q2block_per_nf.items()}
# write all replicas
all_member_blocks = []
for evolved_PDF in evolved_PDF_list:
Expand Down
13 changes: 2 additions & 11 deletions src/ekobox/info_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,8 @@ def build_alphas(
template_info = {}
template_info["AlphaS_MZ"] = theory_card.couplings.alphas
template_info["AlphaS_OrderQCD"] = theory_card.order[0] - 1

# check we have disjoint scale ranges
# prepare
evolgrid = regroup_evolgrid(operators_card.mugrid)
nfs = list(evolgrid.keys())
for j in range(len(nfs) - 1):
# equal points are allowed by LHAPDF
if evolgrid[nfs[j]][-1] > evolgrid[nfs[j + 1]][0]:
raise ValueError(
f"Last scale point for nf={nfs[j]} is bigger than first in nf={nfs[j+1]}"
)

# add actual values
evmod = couplings.couplings_mod_ev(operators_card.configs.evolution_method)
quark_masses = [(x.value) ** 2 for x in theory_card.heavy.masses]
sc = couplings.Couplings(
Expand All @@ -106,6 +96,7 @@ def build_alphas(
hqm_scheme=theory_card.heavy.masses_scheme,
thresholds_ratios=np.power(list(iter(theory_card.heavy.matching_ratios)), 2.0),
)
# add actual values
alphas_values = []
alphas_qs = []
for nf, mus in evolgrid.items():
Expand Down
16 changes: 16 additions & 0 deletions tests/ekobox/test_evol_pdf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest
from banana import toy

import eko
Expand Down Expand Up @@ -50,6 +51,21 @@ def test_evolve_pdfs_dump_path(fake_lhapdf, cd):
assert p.exists()


def test_evolve_pdfs_bad_scales(fake_lhapdf, cd):
"""Bad scale configurations."""
theory, op = init_cards()
n = "test_evolve_pdfs_bad_scales"
op = cards.example.operator()
op.mugrid = [(5.0, 3), (15.0, 4), (10.0, 5), (100.0, 5)]
with pytest.raises(ValueError, match="is bigger"):
with cd(fake_lhapdf):
ev_p.evolve_pdfs([toy.mkPDF("", 0)], theory, op, name=n, path=fake_lhapdf)
op.mugrid = [(5.0, 3), (10.0, 3), (10.0, 4), (15.0, 4), (10.0, 5)]
with pytest.raises(ValueError, match="is bigger"):
with cd(fake_lhapdf):
ev_p.evolve_pdfs([toy.mkPDF("", 0)], theory, op, name=n, path=fake_lhapdf)


def test_evolve_pdfs_dump_file(fake_lhapdf, cd):
theory, op = init_cards()
n = "test_evolve_pdfs_dump_file"
Expand Down
20 changes: 2 additions & 18 deletions tests/ekobox/test_info_file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math

import numpy as np
import pytest

from ekobox import cards, info_file

Expand Down Expand Up @@ -34,12 +33,12 @@ def test_build_alphas_good():
op = cards.example.operator()
op.mu0 = 1.0
# base case
op.mugrid = [(10.0, 5), (100.0, 5)]
op.mugrid = [(100.0, 5), (10.0, 5)]
info = info_file.build_alphas(theory, op)
assert len(info["AlphaS_Vals"]) == 2
np.testing.assert_allclose(info["AlphaS_Qs"], [10.0, 100.0])
# several nf
op.mugrid = [(1.0, 3), (5.0, 3), (5.0, 4), (10.0, 5), (10.0, 5), (100.0, 5)]
op.mugrid = [(5.0, 4), (10.0, 5), (1.0, 3), (5.0, 3), (10.0, 5), (100.0, 5)]
info = info_file.build_alphas(theory, op)
assert len(info["AlphaS_Vals"]) == 6
np.testing.assert_allclose(info["AlphaS_Qs"], [1.0, 5.0, 5.0, 10.0, 10.0, 100.0])
Expand All @@ -48,18 +47,3 @@ def test_build_alphas_good():
info = info_file.build_alphas(theory, op)
assert len(info["AlphaS_Vals"]) == 4
np.testing.assert_allclose(info["AlphaS_Qs"], [1.0, 10.0, 10.0, 100.0])


def test_build_alphas_bad():
"""Bad configurations."""
theory = cards.example.theory()
theory.order = (2, 0)
theory.couplings.alphas = 0.2
op = cards.example.operator()
op.mu0 = 1.0
op.mugrid = [(5.0, 3), (15.0, 4), (10.0, 5), (100.0, 5)]
with pytest.raises(ValueError, match="is bigger"):
info_file.build_alphas(theory, op)
op.mugrid = [(5.0, 3), (10.0, 3), (10.0, 4), (15.0, 4), (10.0, 5)]
with pytest.raises(ValueError, match="is bigger"):
info_file.build_alphas(theory, op)

0 comments on commit d5f63fe

Please sign in to comment.