From d5f63fe7ac995fd9d0d38dba48f2a7969de01c28 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 16 Jul 2024 14:53:40 +0300 Subject: [PATCH] Lift scale check for LHAPDF --- src/ekobox/evol_pdf.py | 19 ++++++++++++++++--- src/ekobox/info_file.py | 13 ++----------- tests/ekobox/test_evol_pdf.py | 16 ++++++++++++++++ tests/ekobox/test_info_file.py | 20 ++------------------ 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/ekobox/evol_pdf.py b/src/ekobox/evol_pdf.py index 0045cdd28..abdb2ec6a 100644 --- a/src/ekobox/evol_pdf.py +++ b/src/ekobox/evol_pdf.py @@ -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 @@ -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) @@ -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: diff --git a/src/ekobox/info_file.py b/src/ekobox/info_file.py index c9ac88b0c..fc5c17f1d 100644 --- a/src/ekobox/info_file.py +++ b/src/ekobox/info_file.py @@ -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( @@ -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(): diff --git a/tests/ekobox/test_evol_pdf.py b/tests/ekobox/test_evol_pdf.py index 54bce6623..141787b49 100644 --- a/tests/ekobox/test_evol_pdf.py +++ b/tests/ekobox/test_evol_pdf.py @@ -1,4 +1,5 @@ import numpy as np +import pytest from banana import toy import eko @@ -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" diff --git a/tests/ekobox/test_info_file.py b/tests/ekobox/test_info_file.py index f7267fbd4..acf3f7272 100644 --- a/tests/ekobox/test_info_file.py +++ b/tests/ekobox/test_info_file.py @@ -1,7 +1,6 @@ import math import numpy as np -import pytest from ekobox import cards, info_file @@ -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]) @@ -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)