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

Provide an unique truth for all theory cards #2028

Merged
merged 65 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7f6f54e
First minimal example
andreab1997 Mar 28, 2024
6e08087
Update nnpdf_data/theory.py
andreab1997 Mar 28, 2024
0f71abe
Remove unused parameters
andreab1997 Mar 28, 2024
9a40b96
Add use_fhmruvv and remove IB
andreab1997 Mar 28, 2024
1065a93
Remove Qedref
andreab1997 Apr 4, 2024
3a22aa6
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 8, 2024
90cb80f
Address review comment
andreab1997 Apr 8, 2024
0655ba5
Modify DAMPPOWERs
andreab1997 Apr 8, 2024
6fb5b6d
Add comments to parameters
andreab1997 Apr 8, 2024
9ccd33a
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
0808e9a
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
cb1c0cb
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
503b5c0
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
44f39cb
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
8c42f4d
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
ccda8f9
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
cacfb06
Address review comments
andreab1997 Apr 10, 2024
a5ea090
Remove Fact and Ren Scalevar'
andreab1997 Apr 10, 2024
c0d0ea7
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 11, 2024
7caa2c8
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 11, 2024
8e0652f
Put all the optional parameters at the end
andreab1997 Apr 11, 2024
fa1920b
First minimal example
andreab1997 Mar 28, 2024
8341ca2
Update nnpdf_data/theory.py
andreab1997 Mar 28, 2024
2307065
Remove unused parameters
andreab1997 Mar 28, 2024
74b91ca
Add use_fhmruvv and remove IB
andreab1997 Mar 28, 2024
72d7a5c
Remove Qedref
andreab1997 Apr 4, 2024
eadaae0
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 8, 2024
4a522a1
Address review comment
andreab1997 Apr 8, 2024
514c9a3
Modify DAMPPOWERs
andreab1997 Apr 8, 2024
9904beb
Add comments to parameters
andreab1997 Apr 8, 2024
31b39a4
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
da7ba20
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
6de4627
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
bbfa5ff
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
9a900da
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
f303c4a
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
42ac7d1
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 10, 2024
5f76e79
Address review comments
andreab1997 Apr 10, 2024
8529b53
Remove Fact and Ren Scalevar'
andreab1997 Apr 10, 2024
8a9a437
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 11, 2024
20d3f74
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 11, 2024
58faa65
Put all the optional parameters at the end
andreab1997 Apr 11, 2024
b689f26
update runcard and rebase with master
scarlehoff Apr 12, 2024
60c95fc
add parameters still requested by eko to evolven3fit ; photon module …
scarlehoff Apr 12, 2024
749ea42
remove theory 522
scarlehoff Apr 12, 2024
2526a63
raise exception only for new theories
scarlehoff Apr 13, 2024
b8e80d5
flip qed running, pre-commit touched files
scarlehoff Apr 13, 2024
e0d8e76
fix n3lo parameters
giacomomagni Apr 15, 2024
1aaf91a
add theorycard 41_000_000
RoyStegeman Apr 15, 2024
dbabec8
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 18, 2024
9cb8a06
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 18, 2024
6480755
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 18, 2024
c9acc6c
Merge branch 'single_truth' of github.com:NNPDF/nnpdf into single_truth
andreab1997 Apr 18, 2024
f4f14e5
Correct QED description
andreab1997 Apr 18, 2024
a40b954
Move HQ with default at the bottom
andreab1997 Apr 18, 2024
73a7db6
Add comment on CKM matrix
andreab1997 Apr 18, 2024
fb83970
Update nnpdf_data/nnpdf_data/theory.py
andreab1997 Apr 22, 2024
2a77e7c
Merge pull request #2048 from NNPDF/41_baseline_theory
andreab1997 Apr 22, 2024
be36283
add annotations and hints and a default for IterEv
scarlehoff Apr 24, 2024
490ee74
utilize the theory iterations by default ; fail inmediately with inco…
scarlehoff Apr 24, 2024
1d894af
add a default-depending-on-Q0 for nf0
scarlehoff Apr 25, 2024
8e4eb08
Merge pull request #2062 from NNPDF/add_default_for_itev
scarlehoff Apr 30, 2024
8f1be78
add alphas/alphaqed/qref to mandatory fields
scarlehoff Apr 30, 2024
cdb247c
Merge branch 'master' into single_truth
scarlehoff Apr 30, 2024
0e19aa1
Merge branch 'master' into single_truth
scarlehoff May 2, 2024
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
4 changes: 4 additions & 0 deletions n3fit/src/evolven3fit/eko_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def construct_eko_cards(
if "nf0" not in theory:
theory["nf0"] = find_nf(mu0, theory, thresholds)

# eko needs a value for Qedref and for max nf alphas
theory["Qedref"] = theory["Qref"]
theory["MaxNfAs"] = theory["MaxNfPdf"]

# The Legacy function is able to construct a theory card for eko starting from an NNPDF theory
legacy_class = runcards.Legacy(theory, {})
theory_card = legacy_class.new_theory
Expand Down
99 changes: 99 additions & 0 deletions nnpdf_data/nnpdf_data/theory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
This module provides an unique source and definition for all the possible parameters
scarlehoff marked this conversation as resolved.
Show resolved Hide resolved
that a theory card can contain.
"""

import dataclasses
import logging

DEPRECATED_KEYS = ["MaxNfAs", "SxRes", "SxOrd" "EScaleVar", "Qedref", "global_nx"]

log = logging.getLogger(__name__)


class TheoryCardError(Exception):
pass


@dataclasses.dataclass(frozen=True)
class TheoryCard:
ID: int # ID number of the theory
PTO: int # Perturbative order (0 = LO, 1 = NLO, 2 = NNLO ...)
FNS: str # Flavor number scheme (e.g. FONLL-C)
DAMP: int # Whether a damping function is applied or not for FONLL
IC: int # 0 = perturbative charm only , 1 = intrinsic charm allowed
ModEv: str # DGLAP evolution solution method (e.g. EXA or TRN)
XIR: float # Renormalization scale over the hard scattering scale ratio
XIF: float # Factorization scale over the hard scattering scale ratio
NfFF: int # Number of active flavors, only for FFNS or FFN0 schemes
QED: int # Max order of alpha_qed in the splitting functions
andreab1997 marked this conversation as resolved.
Show resolved Hide resolved
mc: float # [GeV] charm mass
Qmc: float # [GeV] MSbar mass reference scale of the charm
kcThr: float # Threshold ratio of the charm
mb: float # # [GeV] bottom mass
Qmb: float # [GeV] MSbar mass reference scale of the bottom
kbThr: float # Threshold ratio of the bottom
mt: float # # [GeV] top mass
Qmt: float # [GeV] MSbar mass reference scale of the top
ktThr: float # Threshold ratio of the top
CKM: list[float] # CKM matrix elements (running on the columns first, i.e. CKM_11 is CKM[0] and CKM_12 is CKM[1] and so on)
MZ: float # [GeV] Mass of Z
MW: float # [GeV] Mass of W
GF: float # Fermi constant
SIN2TW: float
TMC: int # Include target mass corrections: 0 = disabled, 1 = leading twist, 2 = higher twist approximated, 3 = higher twist exact
MP: float # [GeV] Mass of the proton
Comments: str # Comments on the theory
MaxNfPdf: int = 5 # Used by pineko and the photon module to define the thresholds
# Fit theory parameters default
nf0: int = 4 # Number of active flavors at the parametrization scale Q0
Q0: float = 1.65 # [GeV] Parametrization scale
nfref: int = 5 # Number of active flavors at Qref
Qref: float = 91.2 # [GeV] Reference scale for alphas and alphaqed
alphas: float = 0.118 # Value of alpha_s at the scale Qref
alphaqed: float = 0.007496252 # Values of alpha QED at the scale Qref
# Evolution parameters
HQ: str = "POLE" # Heavy quark mass scheme, POLE for pole masses (default), MSBAR for running masses (used currently only in eko).
IterEv: int = None # iterations for the evolution of the PDF. Defaults to 40 when ModEv = EXA
scarlehoff marked this conversation as resolved.
Show resolved Hide resolved
ModSV: str = None # Scale variations method in EKO (expanded or exponentiated)
DAMPPOWERc: int = None # Power of the damping factor in FONLL for the c
DAMPPOWERb: int = None # Power of the damping factor in FONLL for the b
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these can be moved below damp?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it here because it has a default?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default. damp can be given an IC-dependent default as well.

(the conference finished before I could merge this :'( )

# N3LO parameters
n3lo_ad_variation: list = dataclasses.field(
default_factory=lambda: 7 * [0]
) # N3LO anomalous dimension variations
n3lo_cf_variation: int = (
0 # N3LO coefficient functions variation: -1 = lower bound, 0 = central, 1 = upper bound
)
use_fhmruvv: bool = (
False # N3LO splitting functions approximation: if True use the FHMRUVV parametrization, otherwise use EKO parametrization.
)
###### Keys for compatibility with old NNPDF theories, their values will be dropped immediately after reading to avoid problems
###### they will be set to ``None`` immediately after loading the theory
MaxNfAs: int = None
SxRes: int = None
SxOrd: str = None
EScaleVar: int = None
Qedref: float = None
global_nx: int = None

def __post_init__(self):
"""Drop deprecated keys and apply some checks"""
if self.Qedref is not None and self.QED != 0:
# Check that nobody is trying to use this with a wrong Qedref!
if self.Qedref != self.Qref:
self._raise_or_warn(
f"Trying to use {self.ID} with {self.Qedref} != {self.Qref}. This is not supported!"
)

for key in DEPRECATED_KEYS:
object.__setattr__(self, key, None)

def _raise_or_warn(self, msg):
"""Raise an error for new theories and a warning for old ones"""
if self.ID >= 600:
raise TheoryCardError(msg)
log.warning(msg)

def asdict(self):
return dataclasses.asdict(self)
48 changes: 0 additions & 48 deletions nnpdf_data/nnpdf_data/theory_cards/522.yaml

This file was deleted.

48 changes: 3 additions & 45 deletions nnpdf_data/nnpdf_data/theorydbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,15 @@
low level utilities for querying the theory database file and representing the
data as a python object.
"""
from dataclasses import asdict, dataclass
from functools import lru_cache
from pathlib import Path

import pandas as pd

from .theory import TheoryCard
from .utils import parse_yaml_inp


@dataclass(frozen=True)
class _TheoryCard:
ID: int
PTO: int
FNS: str
DAMP: int
IC: int
ModEv: str
XIR: float
XIF: float
NfFF: int
MaxNfAs: int
MaxNfPdf: int
Q0: float
alphas: float
Qref: float
QED: int
alphaqed: float
Qedref: float
SxRes: int
SxOrd: str
HQ: str
mc: float
Qmc: float
kcThr: float
mb: float
Qmb: float
kbThr: float
mt: float
Qmt: float
ktThr: float
CKM: list[float]
MZ: float
MW: float
GF: float
SIN2TW: float
TMC: int
MP: float
Comments: str
global_nx: int
EScaleVar: int


class TheoryNotFoundInDatabase(Exception):
pass

Expand All @@ -67,7 +24,8 @@ def parse_theory_card(theory_card):
Returns the theory as a dictionary
"""
if theory_card.exists():
return asdict(parse_yaml_inp(theory_card, _TheoryCard))
tcard = parse_yaml_inp(theory_card, TheoryCard)
return tcard.asdict()
raise TheoryNotFoundInDatabase(f"Theory card {theory_card} not found")


Expand Down
7 changes: 6 additions & 1 deletion nnpdf_data/nnpdf_data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import ruamel.yaml as yaml
from validobj import ValidationError, parse_input

try:
Loader = yaml.CLoader
except AttributeError:
Loader = yaml.Loader


def parse_yaml_inp(input_yaml, spec):
"""
Expand All @@ -12,7 +17,7 @@ def parse_yaml_inp(input_yaml, spec):
https://validobj.readthedocs.io/en/latest/examples.html#yaml-line-numbers
"""
input_yaml = pathlib.Path(input_yaml)
inp = yaml.round_trip_load(input_yaml.open("r", encoding="utf-8"))
inp = yaml.load(input_yaml.read_text(encoding="utf-8"), Loader=Loader)
try:
return parse_input(inp, spec)
except ValidationError as e:
Expand Down
15 changes: 9 additions & 6 deletions validphys2/src/validphys/photon/alpha.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module that implements the alpha running"""

import numpy as np
from scipy.integrate import solve_ivp

Expand All @@ -10,6 +11,7 @@

class Alpha:
"""Class that solves the RGE for alpha_qed"""

def __init__(self, theory, q2max):
self.theory = theory
self.alpha_em_ref = theory["alphaqed"]
Expand All @@ -20,11 +22,11 @@ def __init__(self, theory, q2max):
self.thresh_c = self.theory["kcThr"] * self.theory["mc"]
self.thresh_b = self.theory["kbThr"] * self.theory["mb"]
self.thresh_t = self.theory["ktThr"] * self.theory["mt"]
if self.theory["MaxNfAs"] <= 5:
if self.theory["MaxNfPdf"] <= 5:
self.thresh_t = np.inf
if self.theory["MaxNfAs"] <= 4:
if self.theory["MaxNfPdf"] <= 4:
self.thresh_b = np.inf
if self.theory["MaxNfAs"] <= 3:
if self.theory["MaxNfPdf"] <= 3:
self.thresh_c = np.inf

if self.theory["ModEv"] == "TRN":
Expand Down Expand Up @@ -145,7 +147,7 @@ def alphaem_fixed_flavor_exa(self, q, alphaem_ref, qref, nf, nl):
# at LO in QED the TRN solution is exact
if self.qed_order == 1:
return self.alphaem_fixed_flavor_trn(q, alphaem_ref, qref, nf, nl)

u = 2 * np.log(q / qref)

# solve RGE
Expand Down Expand Up @@ -214,7 +216,7 @@ def compute_betas(self, regions):
for nf, nl in regions:
betas_qed[(nf, nl)] = [
beta.beta_qed_aem2(nf, nl) / (4 * np.pi),
beta.beta_qed_aem3(nf, nl) / (4 * np.pi) ** 2 if self.theory['QED'] == 2 else 0.,
beta.beta_qed_aem3(nf, nl) / (4 * np.pi) ** 2 if self.theory['QED'] == 2 else 0.0,
]
return betas_qed

Expand Down Expand Up @@ -249,6 +251,7 @@ def find_region(self, q):
def _rge(_t, alpha_t, beta_qed_vec):
"""RGEs for the running of alphaem"""
rge_qed = -(alpha_t**2) * (
beta_qed_vec[0] + np.sum([alpha_t ** (k + 1) * beta for k, beta in enumerate(beta_qed_vec[1:])])
beta_qed_vec[0]
+ np.sum([alpha_t ** (k + 1) * beta for k, beta in enumerate(beta_qed_vec[1:])])
)
return rge_qed
9 changes: 4 additions & 5 deletions validphys2/src/validphys/photon/compute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module that calls fiatlux to add the photon PDF."""

import logging
import tempfile

Expand Down Expand Up @@ -55,11 +56,9 @@ def __init__(self, theoryid, lux_params, replicas):

theory = theoryid.get_description()
fiatlux_runcard = FIATLUX_DEFAULT
fiatlux_runcard["qed_running"] = bool(np.isclose(theory["Qedref"], theory["Qref"]))
# cast explicitly from np.bool_ to bool otherwise problems in dumping it
# TODO: for the time being, we trigger alphaem running if Qedref=Qref.
# This is going to be changed in favor of a bool em_running
# in the runcard
# TODO: for the time being, Qedref=Qref and so alphaem running will always trigger
# This may be changed in the future in favor of a bool em_running in the runcard
fiatlux_runcard["qed_running"] = True
fiatlux_runcard["mproton"] = float(theory["MP"])

# precision on final integration of double integral
Expand Down
8 changes: 4 additions & 4 deletions validphys2/src/validphys/tests/photon/test_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_set_thresholds_alpha_em():

# test all the thresholds
np.testing.assert_almost_equal(alpha.alpha_em_ref, theory["alphaqed"])
np.testing.assert_almost_equal(alpha.thresh[(5, 3)], theory["Qedref"])
np.testing.assert_almost_equal(alpha.thresh[(5, 3)], theory["Qref"])
np.testing.assert_almost_equal(alpha.thresh[(4, 3)], theory["mb"])
np.testing.assert_almost_equal(alpha.thresh[(4, 2)], constants.MTAU)
np.testing.assert_almost_equal(alpha.thresh[(3, 2)], theory["mc"])
Expand All @@ -46,7 +46,7 @@ def test_set_thresholds_alpha_em():
np.testing.assert_almost_equal(alpha.alphaem_thresh[(5, 3)], theory["alphaqed"])
np.testing.assert_almost_equal(
alpha.alphaem_thresh[(4, 3)],
alpha.alphaem_fixed_flavor(theory["mb"], alpha_ref, theory["Qedref"], 5, 3),
alpha.alphaem_fixed_flavor(theory["mb"], alpha_ref, theory["Qref"], 5, 3),
)
np.testing.assert_almost_equal(
alpha.alphaem_thresh[(4, 2)],
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_couplings_exa():
alphaem=theory["alphaqed"],
scale=theory["Qref"],
num_flavs_ref=None,
max_num_flavs=theory["MaxNfAs"],
max_num_flavs=theory["MaxNfPdf"],
em_running=True,
)
)
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_couplings_exa():
np.testing.assert_allclose(
alpha.alpha_em(q), eko_alpha.a_em(q**2) * 4 * np.pi, rtol=5e-6
)
for nf in range(3, theory["MaxNfAs"]):
for nf in range(3, theory["MaxNfPdf"]):
np.testing.assert_allclose(
alpha.alphaem_thresh[(nf, 2 if nf == 3 else 3)],
eko_alpha.a_em(mass_list[nf - 3] ** 2, nf) * 4 * np.pi,
Expand Down
4 changes: 2 additions & 2 deletions validphys2/src/validphys/tests/photon/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from validphys.core import PDF as PDFset
from validphys.loader import FallbackLoader
from validphys.photon import structure_functions as sf
from validphys.photon.compute import FIATLUX_DEFAULT, Photon
from validphys.photon.alpha import Alpha
from validphys.photon.compute import FIATLUX_DEFAULT, Photon

from ..conftest import PDF, THEORY_QED

Expand Down Expand Up @@ -70,7 +70,7 @@ def test_photon():
# runcard
fiatlux_default = FIATLUX_DEFAULT.copy()
fiatlux_default['mproton'] = theory['MP']
fiatlux_default["qed_running"] = bool(np.isclose(theory["Qedref"], theory["Qref"]))
fiatlux_default["qed_running"] = False
fiatlux_default["q2_max"] = float(f2.q2_max)
fiatlux_default["eps_base"] = fiatlux_runcard["eps_base"]

Expand Down