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

correct sorting of level1 data #1757

Closed
wants to merge 83 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
cf8afeb
Add theories 398 397 to theory.db
niclaurenti May 22, 2023
df6371f
Allow Q_IN != 100
niclaurenti Jun 5, 2023
04ac7a8
Add theories 524, 525, 526
niclaurenti Jun 5, 2023
b425a69
Fix tests
niclaurenti Jun 6, 2023
cb59f2e
Upgrade to eko13
niclaurenti Jun 6, 2023
6a33baa
Use ev_op_iterations=30 for exact evolution
niclaurenti Jun 6, 2023
4c19a78
Add control on alphaem running in eko_utils
niclaurenti Jun 7, 2023
2b27cbc
Merge branch 'master' into different-qin
niclaurenti Jun 7, 2023
57f80a6
Merge branch 'master' into different-qin
niclaurenti Jun 8, 2023
78c31b4
add nf=3 option
scarlehoff Jun 9, 2023
fe60a68
load only .exportgrid files corresponding to the fit
scarlehoff Jun 9, 2023
135862e
create a separate Q,nf entry when crossing a threshold
scarlehoff Jun 9, 2023
d63bda0
add a default q0 grid for nf0=3 and associated tests
scarlehoff Jun 9, 2023
70458a3
Merge branch 'master' into QED-tests
niclaurenti Jun 12, 2023
88b17dc
fix bug due to pd.groupby alphabetical ordering
comane Jun 12, 2023
6e98bf8
Use _ for unused varibles
niclaurenti Jun 13, 2023
6bfc220
Merge pull request #1751 from NNPDF/different-qin
niclaurenti Jun 13, 2023
c6914a1
Merge branch 'master' into qed-tests
niclaurenti Jun 13, 2023
fcc3e8e
Add qed test in test_evolven3fit.py
niclaurenti Jun 13, 2023
5e7176e
Add qed test in test_fit
niclaurenti Jun 13, 2023
0af3004
Add qed test in test_fit 2
niclaurenti Jun 13, 2023
2256664
Refector QED tests
niclaurenti Jun 14, 2023
5a319fc
Fix test
niclaurenti Jun 14, 2023
9758018
Add fiatlux precision in the runcard
niclaurenti Jun 14, 2023
0a926fd
Rename abs_err -> eps_base
niclaurenti Jun 14, 2023
32e1a86
Use .json from linux machine
niclaurenti Jun 14, 2023
e2954ae
Fix very small bug in interp1d
niclaurenti Jun 14, 2023
3d1783d
Download theoryIDs
niclaurenti Jun 15, 2023
296e2d4
Add whitelines
niclaurenti Jun 16, 2023
22085f9
Merge branch 'qed-tests' of github.com:NNPDF/nnpdf into qed-tests
niclaurenti Jun 16, 2023
7585eea
Load theoryID from fit
niclaurenti Jun 16, 2023
57a5343
Use test theory in test_compute
niclaurenti Jun 16, 2023
077e2ed
Fix charm mass in test
niclaurenti Jun 16, 2023
388be7b
speed up photon computation in test
niclaurenti Jun 16, 2023
ddc57d3
Fix charm mass in test again
niclaurenti Jun 16, 2023
dba334a
Fix testing of alpha
niclaurenti Jun 16, 2023
3fa81ba
Fix test_compute
niclaurenti Jun 16, 2023
bb3a1fd
Add test on photon computation
niclaurenti Jun 16, 2023
3901ba5
Remove unused dependencies
niclaurenti Jun 16, 2023
f3de6b0
Polish test
niclaurenti Jun 16, 2023
7550e2d
Polish test again
niclaurenti Jun 16, 2023
98d919f
Pass test theory to test_structurefunctions.py
niclaurenti Jun 16, 2023
4b0ed9c
Run isort and black on test_structurefunctions.py
niclaurenti Jun 16, 2023
10dd7e2
modify the call to generate_block to make it compatible with eko 0.13.5
scarlehoff Jun 16, 2023
5ede6f4
Test init parameters of test_structurefunctions.py
niclaurenti Jun 16, 2023
52e9130
Run isort and black on test_structurefunctions.py
niclaurenti Jun 16, 2023
370d0dd
Use API to install pdfset
niclaurenti Jun 16, 2023
b97450d
Refactor test_structurefunctions.py and add docstrings
niclaurenti Jun 16, 2023
3e548a8
Small modification
niclaurenti Jun 16, 2023
b40db35
Use FIATLUX_DEFAULT from photon.compute
niclaurenti Jun 16, 2023
0958b08
Remove unused import
niclaurenti Jun 16, 2023
6a7ef27
Merge branch 'master' into fix_evolven3fit_for_nf=3
scarlehoff Jun 16, 2023
61c5bb9
Remove variable NNPDF40
niclaurenti Jun 19, 2023
53d7c73
Add comment
niclaurenti Jun 19, 2023
95f1e24
Allow categorical variables in smpdf plots
Zaharid Apr 17, 2023
ced3981
Add test and improve variables
Zaharid May 26, 2023
88a00f8
Remove figby in atlas total cross section
Zaharid May 26, 2023
9b861be
Improve comments
Zaharid Jun 19, 2023
e43cac7
Typo
Zaharid Jun 19, 2023
80a99fc
Leftover typo
Zaharid Jun 19, 2023
6089608
Update test image
Zaharid Jun 19, 2023
1e5f78e
Merge pull request #1754 from NNPDF/fix_evolven3fit_for_nf=3
niclaurenti Jun 19, 2023
502997f
Merge branch 'master' into qed-tests
niclaurenti Jun 19, 2023
d5a48f9
Check installation of error pdf in test
niclaurenti Jun 19, 2023
1e237da
Call black and isort
niclaurenti Jun 19, 2023
1e105cd
Fix last commit
niclaurenti Jun 19, 2023
dfc8892
Merge pull request #1715 from NNPDF/smpdfcategorical
Zaharid Jun 19, 2023
7eb0c4e
Merge pull request #1738 from NNPDF/qed-tests
niclaurenti Jun 19, 2023
d6392ba
Add luminosity channels (#1762)
Zaharid Jun 22, 2023
e868a23
ordering done with dictionary
comane Jun 22, 2023
acd0b06
Use function to generate fiatlux runcard in tests
niclaurenti Jun 22, 2023
40bc7bc
Call api inside tests
niclaurenti Jun 22, 2023
f579752
Merge pull request #1763 from NNPDF/fix-qed-tests
scarlehoff Jun 22, 2023
3254147
fix bug due to pd.groupby alphabetical ordering
comane Jun 12, 2023
58e3bba
ordering done with dictionary
comane Jun 22, 2023
7e28a83
tmp data_index for correct indexing
comane Jun 26, 2023
6bc4cad
data_index function for correct experiments_index
comane Jun 26, 2023
25d485a
closure tests use data_index for filtering of data. When running vp-s…
comane Jun 26, 2023
affebdd
Merge branch 'fix_bug_make_level1_data' of https://github.com/NNPDF/n…
comane Jun 26, 2023
f266993
fixed bug in make level1 data due to experiments_index
comane Jun 26, 2023
c538371
black for formatting
comane Jun 26, 2023
a9c88ab
black for formatting
comane Jun 26, 2023
b601a3d
Merge branch 'fix_bug_make_level1_data' of https://github.com/NNPDF/n…
comane Jun 27, 2023
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 conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ requirements:
- sphinxcontrib-bibtex
- curio >=1.0
- pineappl >=0.5.8
- eko >=0.13.4,<0.14
- eko >=0.13.5,<0.14
- banana-hep >=0.6.8
- fiatlux

Expand Down
3 changes: 2 additions & 1 deletion n3fit/runcards/examples/Basic_runcard_qed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ datacuts:

############################################################
theory:
theoryid: 522 # database id
theoryid: 523 # database id

############################################################
trvlseed: 1551864071
Expand Down Expand Up @@ -169,3 +169,4 @@ fiatlux:
luxset: NNPDF40_nnlo_as_01180
additional_errors: true # should be set to true only for the last iteration
luxseed: 1234567890
eps_base: 1e-2
89 changes: 50 additions & 39 deletions n3fit/src/evolven3fit_new/eko_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
}

EVOLVEN3FIT_CONFIGS_DEFAULTS_EXA = {
"ev_op_iterations": 10,
"ev_op_iterations": 30,
"ev_op_max_order": (1, 0),
"evolution_method": "iterate-exact",
"inversion_method": "exact",
"n_integration_cores": 1,
}

NFREF_DEFAULT = 5
NF0_DEFAULT = 4


def construct_eko_cards(
Expand Down Expand Up @@ -58,46 +57,77 @@ def construct_eko_cards(
theory = Loader().check_theoryID(theoryID).get_description()
theory.pop("FNS")
theory.update(theory_card_dict)
if "nfref" not in theory:
theory["nfref"] = NFREF_DEFAULT
if "nf0" not in theory:
theory["nf0"] = NF0_DEFAULT


# Prepare the thresholds according to MaxNfPdf
thresholds = {"c": theory["kcThr"], "b": theory["kbThr"], "t": theory["ktThr"]}
if theory["MaxNfPdf"] < 5:
thresholds["b"] = np.inf
if theory["MaxNfPdf"] < 6:
thresholds["t"] = np.inf


if "nfref" not in theory:
theory["nfref"] = NFREF_DEFAULT

# Set nf_0 according to the fitting scale unless set explicitly
mu0 = theory["Q0"]
if "nf0" not in theory:
if mu0 < theory["mc"] * thresholds["c"]:
theory["nf0"] = 3
elif mu0 < theory["mb"] * thresholds["b"]:
theory["nf0"] = 4
elif mu0 < theory["mt"] * thresholds["t"]:
theory["nf0"] = 5
else:
theory["nf0"] = 6

# Setting the thresholds in the theory card to inf if necessary
theory.update({"kbThr":thresholds["b"], "ktThr":thresholds["t"] })
theory.update({"kbThr": thresholds["b"], "ktThr": thresholds["t"]})

# 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

# construct operator card
# Generate the q2grid, if q_fin and q_points are None, use `nf0` to select a default
q2_grid = utils.generate_q2grid(
theory["Q0"],
mu0,
q_fin,
q_points,
{theory["mb"]: thresholds["b"], theory["mt"]: thresholds["t"]},
{
theory["mc"]: thresholds["c"],
theory["mb"]: thresholds["b"],
theory["mt"]: thresholds["t"],
},
theory["nf0"],
)

# construct operator card
op_card = default_op_card
masses = np.array([theory["mc"], theory["mb"], theory["mt"]]) ** 2
thresholds_ratios = np.array([thresholds["c"], thresholds["b"], thresholds["t"]]) ** 2

atlas = Atlas(
matching_scales=MatchingScales(masses * thresholds_ratios),
origin=(theory["Q0"] ** 2, theory["nf0"]),
)
op_card.update(
{
"mu0": theory["Q0"],
"mugrid": [(float(np.sqrt(q2)), int(nf_default(q2, atlas))) for q2 in q2_grid],
}
origin=(mu0**2, theory["nf0"]),
)

# Create the eko operator q2grid
# This is a grid which contains information on (q, nf)
# in VFNS values at the matching scales need to be doubled so that they are considered in both sides

ep = 1e-4
mugrid = []
for q2 in q2_grid:
q = float(np.sqrt(q2))
if nf_default(q2 + ep, atlas) != nf_default(q2 - ep, atlas):
nf_l = int(nf_default(q2 - ep, atlas))
nf_u = int(nf_default(q2 + ep, atlas))
mugrid.append((q, nf_l))
mugrid.append((q, nf_u))
else:
mugrid.append((q, int(nf_default(q2, atlas))))

op_card.update({"mu0": theory["Q0"], "mugrid": mugrid})

op_card["xgrid"] = x_grid
# Specific defaults for evolven3fit evolution
if theory["ModEv"] == "TRN":
Expand All @@ -116,22 +146,3 @@ def construct_eko_cards(

op_card = runcards.OperatorCard.from_dict(op_card)
return theory_card, op_card


def split_evolgrid(evolgrid):
"""Split the evolgrid in blocks according to the number of flavors and repeating the last entry of one block in the first entry of the next."""
evolgrid_index_list = []
evolgrid.sort()
starting_nf = evolgrid[0][1]
for evo_point in evolgrid:
current_nf = evo_point[1]
if current_nf != starting_nf:
evolgrid_index_list.append(evolgrid.index(evo_point))
starting_nf = current_nf
start_index = 0
evolgrid_list = []
for index in evolgrid_index_list:
evolgrid_list.append(evolgrid[start_index : index + 1])
start_index = index
evolgrid_list.append(evolgrid[start_index:])
return evolgrid_list
23 changes: 16 additions & 7 deletions n3fit/src/evolven3fit_new/evolve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
import logging
import pathlib
import sys
Expand Down Expand Up @@ -145,7 +146,7 @@ def load_fit(usr_path):
"""
nnfitpath = usr_path / "nnfit"
pdf_dict = {}
for yaml_file in nnfitpath.glob("replica_*/*.exportgrid"):
for yaml_file in nnfitpath.glob(f"replica_*/{usr_path.name}.exportgrid"):
data = yaml.safe_load(yaml_file.read_text(encoding="UTF-8"))
pdf_dict[yaml_file.parent.stem] = data
return pdf_dict
Expand Down Expand Up @@ -178,19 +179,27 @@ def evolve_exportgrid(exportgrid, eko, x_grid, qed):
# generate block to dump
targetgrid = eko.bases.targetgrid.tolist()

def ev_pdf(pid, x, Q2):
return x * evolved_pdf[Q2]["pdfs"][pid][targetgrid.index(x)]
# Finally separate by nf block (and order per nf/q)
by_nf = defaultdict(list)
for q, nf in sorted(eko.evolgrid, key=lambda ep: ep[1]):
by_nf[nf].append(q)
q2block_per_nf = {nf: sorted(qs) for nf, qs in by_nf.items()}

evolgrid_list = eko_utils.split_evolgrid(eko.evolgrid)
blocks = []
for evgrid in evolgrid_list:
for nf, q2grid in q2block_per_nf.items():

def pdf_xq2(pid, x, Q2):
x_idx = targetgrid.index(x)
return x * evolved_pdf[(Q2, nf)]["pdfs"][pid][x_idx]

block = genpdf.generate_block(
ev_pdf,
pdf_xq2,
xgrid=targetgrid,
evolgrid=evgrid,
sorted_q2grid=q2grid,
pids=basis_rotation.flavor_basis_pids,
)
blocks.append(block)

return blocks


Expand Down
74 changes: 69 additions & 5 deletions n3fit/src/evolven3fit_new/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from reportengine.compat import yaml
from validphys.pdfbases import PIDS_DICT

DEFAULT_Q2GRID = (
Q2GRID_Nf04 = (
np.array(
[
1.6500000e00,
Expand All @@ -22,7 +22,6 @@
3.8800751e00,
4.3584516e00,
4.9200000e00,
4.9200000e00,
5.5493622e00,
6.2897452e00,
7.1650687e00,
Expand Down Expand Up @@ -65,6 +64,62 @@
** 2
)

Q2GRID_Nf03 = (
np.array(
[
1.0000000e00,
1.0768843e00,
1.1642787e00,
1.2640247e00,
1.3783565e00,
1.5100000e00,
1.6573843e00,
1.8279487e00,
2.0263188e00,
2.2582323e00,
2.5308507e00,
2.8531703e00,
3.2365690e00,
3.6955380e00,
4.2486693e00,
4.9200000e00,
5.6571821e00,
6.5475141e00,
7.6300446e00,
8.9555329e00,
1.0590474e01,
1.2622686e01,
1.5169120e01,
1.8386905e01,
2.2489085e01,
2.7767274e01,
3.4624624e01,
4.3624282e01,
5.5561424e01,
7.1571582e01,
9.3295496e01,
1.2313315e02,
1.6464038e02,
2.2315640e02,
3.0681103e02,
4.2816505e02,
6.0692308e02,
8.7449251e02,
1.2817733e03,
1.9127020e03,
2.9082314e03,
4.5095982e03,
7.1379509e03,
1.1543948e04,
1.9094934e04,
3.2338760e04,
5.6137084e04,
1.0000000e05,
]
)
** 2
)


class LhapdfLike:
"""
Expand Down Expand Up @@ -123,15 +178,22 @@ def get_theoryID_from_runcard(usr_path):
return my_runcard["theory"]["theoryid"]


def generate_q2grid(Q0, Qfin, Q_points, match_dict):
def generate_q2grid(Q0, Qfin, Q_points, match_dict, nf0=None):
"""Generate the q2grid used in the final evolved pdfs or use the default grid if Qfin or Q_points is
not provided.

match_dict contains the couples (mass : factor) where factor is the number to be multiplied to mass
in order to obtain the relative matching scale.
"""
if Qfin is None and Q_points is None:
return DEFAULT_Q2GRID
if nf0 == 4:
return Q2GRID_Nf04
elif nf0 == 3:
return Q2GRID_Nf03
elif nf0 is None:
raise ValueError("In order to use a default grid, a value of nf0 must be provided")
else:
raise NotImplementedError(f"No default grid in Q available for {nf0=}")
elif Qfin is None or Q_points is None:
raise ValueError("q_fin and q_points must be specified either both or none of them")
else:
Expand All @@ -148,7 +210,9 @@ def generate_q2grid(Q0, Qfin, Q_points, match_dict):
frac_of_point = np.log(match_scale / Q_ini) / np.log(Qfin / Q0)
num_points = int(Q_points * frac_of_point)
num_points_list.append(num_points)
grids.append(np.geomspace(Q_ini**2, match_scale**2, num=num_points))
grids.append(
np.geomspace(Q_ini**2, match_scale**2, num=num_points, endpoint=False)
)
Q_ini = match_scale
num_points = Q_points - sum(num_points_list)
grids.append(np.geomspace(Q_ini**2, Qfin**2, num=num_points))
Expand Down
Loading