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 IO for LHA bot #238

Merged
merged 3 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 benchmarks/lha_paper_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def run_lha(self, theory_updates):
theory_updates,
[
{
"Q2grid": [1e4],
"mugrid": [1e2],
"ev_op_iterations": 10,
"interpolation_xgrid": lambertgrid(60).tolist(),
"polarized": True,
Expand Down
4 changes: 2 additions & 2 deletions doc/source/code/IO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ The benchmark settings are available at :mod:`ekomark.data.operators`.
* - ``interpolation_xgrid``
- :py:obj:`list(float)`
- x-grid at which the |EKO| is computed.
* - ``Q2grid``
* - ``mugrid``
- :py:obj:`list(float)`
- Q2-grid at which the |EKO| is computed (in GeV^2).
- target grid at which the |EKO| is computed (in GeV).
* - ``interpolation_is_log``
- :py:obj:`bool`
- If ``True`` use logarithmic interpolation.
Expand Down
29 changes: 14 additions & 15 deletions src/eko/io/runcards.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,33 +288,32 @@ def new_theory(self):

new["order"] = [old["PTO"] + 1, old["QED"]]
alphaem = self.fallback(old.get("alphaqed"), old.get("alphaem"), default=0.0)
if "QrefQED" not in old:
qedref = nan
else:
qedref = old["QrefQED"]
new["couplings"] = dict(
alphas=(old["alphas"], old["Qref"]),
alphaem=(alphaem, qedref),
alphas=old["alphas"],
alphaem=alphaem,
scale=old["Qref"],
num_flavs_ref=old["nfref"],
max_num_flavs=old["MaxNfAs"],
)
new["num_flavs_init"] = old["nf0"]
new["num_flavs_max_pdf"] = old["MaxNfPdf"]
new["heavy"] = {
"num_flavs_init": old["nf0"],
"num_flavs_max_pdf": old["MaxNfPdf"],
"matching_ratios": self.heavies("k%sThr", old),
"masses_scheme": old["HQ"],
}
intrinsic = []
for idx, q in enumerate(hq.FLAVORS):
if old.get(f"i{q}".upper()) == 1:
intrinsic.append(idx + 4)
new["intrinsic_flavors"] = intrinsic
new["matching"] = self.heavies("k%sThr", old)
new["quark_masses_scheme"] = old["HQ"]
new["heavy"]["intrinsic_flavors"] = intrinsic
ms = self.heavies("m%s", old)
mus = self.heavies("Qm%s", old)
if old["HQ"] == "POLE":
new["quark_masses"] = [[m, nan] for m in ms]
new["heavy"]["masses"] = [[m, nan] for m in ms]
elif old["HQ"] == "MSBAR":
new["quark_masses"] = [[m, mu] for m, mu in zip(ms, mus)]
new["heavy"]["masses"] = [[m, mu] for m, mu in zip(ms, mus)]
else:
raise ValueError()
raise ValueError(f"Unknown mass scheme '{old['HQ']}'")

new["xif"] = old["XIF"]

Expand Down Expand Up @@ -409,4 +408,4 @@ def flavored_mugrid(mugrid: list, masses: list, matching_ratios: list):
masses=(np.array(masses) ** 2).tolist(),
thresholds_ratios=(np.array(matching_ratios) ** 2).tolist(),
)
return [(mu, tc.nf(mu**2)) for mu in mugrid]
return [(mu, int(tc.nf(mu**2))) for mu in mugrid]
2 changes: 1 addition & 1 deletion src/ekomark/benchmark/external/LHA_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def compute_LHA_data(theory, operators, rotate_to_evolution_basis=False):

"""
polarized = operators["polarized"]
mu2grid = operators["mu2grid"]
mu2grid = np.power(operators["mugrid"], 2.0)
if not np.allclose(mu2grid, [1e4]):
raise ValueError("mu2grid has to be [1e4]")
order = theory["PTO"]
Expand Down
2 changes: 1 addition & 1 deletion src/ekomark/navigator/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def fill_operators(self, op, obj):
+ f"{'log' if op['interpolation_is_log'] else 'x'}"
+ f"^{op['interpolation_polynomial_degree']}"
)
obj["Q2grid"] = op["Q2grid"]
obj["mugrid"] = op["mugrid"]
obj["max_ord"] = op["ev_op_max_order"]
obj["iters"] = op["ev_op_iterations"]
obj["skip_ns"] = op["debug_skip_non_singlet"]
Expand Down
29 changes: 29 additions & 0 deletions tests/eko/io/test_runcards.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import copy
from dataclasses import fields
from io import StringIO

import numpy as np
import pytest
import yaml
from banana.data.theories import default_card as theory_card

from eko import interpolation
from eko.io import runcards as rc
from ekomark.data.operators import default_card as operator_card


class TestRotations:
Expand Down Expand Up @@ -50,3 +55,27 @@ def test_flavored_mu2grid():

flavored = rc.flavored_mugrid(mugrid, masses, ratios)
assert pytest.approx([flav for _, flav in flavored]) == [3, 3, 4, 4, 5, 5, 6, 6]

# check we can dump
stream = StringIO()
ser = yaml.safe_dump(flavored, stream)
stream.seek(0)
deser = yaml.safe_load(stream)
assert len(flavored) == len(deser)
# after deserialization on is now list instead of tuple
for t, l in zip(flavored, deser):
assert len(t) == len(l)
assert t == tuple(l)


def test_runcards_ekomark():
# check conversion
tc = copy.deepcopy(theory_card)
oc = copy.deepcopy(operator_card)
nt, no = rc.update(tc, oc)
assert isinstance(nt, rc.TheoryCard)
assert isinstance(no, rc.OperatorCard)
# check is idempotent
nnt, nno = rc.update(nt, no)
assert nnt == nt
assert nno == no