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

Positivity #146

Merged
merged 15 commits into from
Sep 13, 2022
Merged
534 changes: 0 additions & 534 deletions .pylintrc

This file was deleted.

31 changes: 24 additions & 7 deletions benchmarks/runners/apfel_.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ def benchmark_pto(self, pto):
self.run([{"PTO": pto}], obs_update, ["ToyLH"])


class BenchmarkPositivity(ApfelBenchmark):
update = {
"NCPositivityCharge": ["up", "down", "strange", "all"],
felixhekhorn marked this conversation as resolved.
Show resolved Hide resolved
}

def benchmark_pto(self, pto):
obs_update = observables.build(
**(observables.default_config[pto]), update=self.update
)
self.run([{"PTO": pto}], obs_update, ["ToyLH"])


class BenchmarkPropagatorCorrection(ApfelBenchmark):
update = {
"prDIS": ["NC", "CC"],
Expand Down Expand Up @@ -262,21 +274,26 @@ def benchmark_nlo(self):


if __name__ == "__main__":
plain = BenchmarkPlain()
# plain.benchmark_lo()
# plain.benchmark_nlo()
# plain = BenchmarkPlain()
# plain.benchmark_pto(0)
# plain.benchmark_pto(1)

# proj = BenchmarkProjectile()
# proj.benchmark_pto(0)
# proj.benchmark_pto(1)

# proj = BenchmarkTMC()
# proj.benchmark_lo()
pos = BenchmarkPositivity()
pos.benchmark_pto(0)
pos.benchmark_pto(1)
felixhekhorn marked this conversation as resolved.
Show resolved Hide resolved

# ffns = BenchmarkICFFNS()
# ffns.benchmark_lo()
# ffns.benchmark_nlo()
# fonll = BenchmarkICFONLL()
# fonll.benchmark_nlo()

xs = BenchmarkXS()
xs.benchmark_pto(0)
# xs = BenchmarkXS()
# xs.benchmark_pto(0)

# def plain_assert_external(theory, obs, sf, yad):
# # APFEL has a discretization in Q2/m2
Expand Down
23 changes: 12 additions & 11 deletions benchmarks/runners/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

class Sandbox(Runner):

# external comparison program
# external comparison program
external = "APFEL"
# external = "xspace_bench"
# external = "QCDNUM"
# external = "void"
# external = "xspace_bench"
# external = "QCDNUM"
# external = "void"

# alphas_from_lhapdf = True

Expand Down Expand Up @@ -79,8 +79,8 @@ def generate_observables():
# "XSNUTEVCC_charm"
]
#update = {"prDIS": ["EM"],"interpolation_xgrid":[interpolation_xgrid], "interpolation_polynomial_degree": [4]}
#update = {"prDIS": ["EM"], "ProjectileDIS": ["electron"]}
update = {"prDIS": ["CC"], "ProjectileDIS": ["electron"]}
update = {"prDIS": ["EM"], "ProjectileDIS": ["electron"], "NCPositivityCharge": ["strange"]}
#update = {"prDIS": ["CC"], "ProjectileDIS": ["electron"]}
#update = {"prDIS": ["EM"], "ProjectileDIS": ["electron"], "TargetDIS":["lead"]}
#update= {}
# card["PropagatorCorrection"] = .999
Expand All @@ -95,7 +95,8 @@ def doit(self):
#{"PTO": 1, "FNS": "FFNS", "mc": 1.95, "mb": 1e6, "mt": 1e8, "NfFF": 3},
#{"PTO": 2, "FNS": "FFNS", "mc": 1.95, "mb": 1e6, "mt": 1e8, "NfFF": 4},
#{"PTO": 2, "FNS": "FONLL-C","NfFF":4,"IC":1,"mc":1.51,"Qmc":1.51,"mb":1e6,"mt":1e7,"ModEv":"TRN","MaxNfPdf":5,"MaxNfAs": 5, "Qmb":4.92,"Qmt":172.5,"alphas":0.118,"alphaqed":0.007496252,"Q0":1.65},
#{"PTO": 1, "FNS": "FONLL-A", "mc": 1.95, "mb": 1e6,"mt": 1e8, "NfFF": 4, "IC":0},
#{"PTO": 1, "FNS": "FONLL-A","IC":0},
{"PTO": 2, "FNS": "FONLL-C","IC":0},
#{"PTO": 2, "FNS": "FONLL-B", "mc": 1.51, "NfFF": 4, "kbThr": 100, "ktThr": 100, "alphas": .3, "Qref": 3},
#{"PTO": 2, "FNS": "FONLL-B", "mc": 1.95, "mb": 1e6, "mt": 1e8, "NfFF": 4},
#{"PTO": 2, "FNS": "FONLL-C", "mc": 1.95, "mb": 1e6, "mt": 1e8, "NfFF": 4},
Expand All @@ -108,20 +109,20 @@ def doit(self):
#{"PTO": 1, "IC": 1, "FNS": "FONLL-A", "NfFF": 4, "mc": 1.51, "mb": 1e6, "mt": 1e8},
#{"PTO": 1, "IC": 1, "FNS": "FFNS", "NfFF": 3, "mc": 1.51, "XIF": 1, "XIR": 1},
#{"PTO": 1, "IC": 1, "FNS": "FFNS", "NfFF": 3, "mc": 1.51, "XIF": 2, "XIR": 1},
{"PTO": 2, "FNS": "FFNS", "mc": 1.95, "mb": 1e6, "mt": 1e8, "NfFF": 3, "XIF": 2},
#{"PTO": 2, "FNS": "FFNS", "mc": 1.95, "mb": 1e6, "mt": 1e8, "NfFF": 3, "XIF": 2},
], self.generate_observables(), [
# "uonly",
# "ubaronly",
# "dbaronly",
# "donly",
# "conly",
# "toygonly",
# "toyuonly",
# "toyantichsing",
# "toyt3only",
# "conly",
"ToyLH",
# "ToyLH",
# "gonly",
# "NNPDF31_nnlo_as_0118",
"NNPDF31_nnlo_as_0118",
# "NN31g",
# "NN31u",
# "NN31c",
Expand Down
2 changes: 1 addition & 1 deletion extras/data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PY=python3

PACKAGE=machinery
OUTPUT=_runcards
IGNORE=Makefile ${PACKAGE} README.md ${OUTPUT} banana.yaml benchmark.db
IGNORE=Makefile ${PACKAGE} README.md ${OUTPUT} banana.yaml benchmark.db __pycache__
FOLDERS=$(filter-out ${IGNORE},$(wildcard *))

all:
Expand Down
2 changes: 2 additions & 0 deletions extras/data/POS_F2C/c.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NCPositivityCharge: all
felixhekhorn marked this conversation as resolved.
Show resolved Hide resolved
obs: F2_charm
6 changes: 6 additions & 0 deletions extras/data/POS_F2C/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
arxiv:
hepdata:
y_label: F2c
y_label_tex: $F_2^{c}$
description: DIS positivity for charm quark
nnpdf_id: POSF2C
2 changes: 2 additions & 0 deletions extras/data/POS_F2D/d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NCPositivityCharge: down
obs: F2_light
6 changes: 6 additions & 0 deletions extras/data/POS_F2D/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
arxiv:
hepdata:
y_label: F2d
y_label_tex: $F_2^{d}$
description: DIS positivity for down quark
nnpdf_id: POSF2DW
felixhekhorn marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions extras/data/POS_F2S/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
arxiv:
hepdata:
y_label: F2s
y_label_tex: $F_2^{s}$
description: DIS positivity for strange quark
nnpdf_id: POSF2S
2 changes: 2 additions & 0 deletions extras/data/POS_F2S/s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NCPositivityCharge: strange
obs: F2_light
6 changes: 6 additions & 0 deletions extras/data/POS_F2U/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
arxiv:
hepdata:
y_label: F2u
y_label_tex: $F_2^{u}$
description: DIS positivity for up quark
nnpdf_id: POSF2U
2 changes: 2 additions & 0 deletions extras/data/POS_F2U/u.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NCPositivityCharge: up
obs: F2_light
2 changes: 2 additions & 0 deletions extras/data/POS_FLL/g.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NCPositivityCharge: all
obs: FL_light
6 changes: 6 additions & 0 deletions extras/data/POS_FLL/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
arxiv:
hepdata:
y_label: FL_light
y_label_tex: $F_L^{light}$
description: DIS positivity for light longitudinal structure function
nnpdf_id: POSFLL
2 changes: 1 addition & 1 deletion extras/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
In order to generate `observable.yaml` run from this folder:

```sh
python -m parse <EXPERIMENT/subpath>
python -m machinery generate <EXPERIMENT/subpath>
```
1 change: 1 addition & 0 deletions extras/data/machinery/benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def main(args):
if args.lo:
print("LO comparison")
theory["PTO"] = 0
theory["TMC"] = 0
theory["FNS"] = "ZM-VFNS"

for folder in args.folders:
Expand Down
72 changes: 72 additions & 0 deletions extras/data/machinery/generate/POS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
"""Generator for positivity datasets."""
import copy

import yaml

from .utils import obs_template


def _make_kins():
"""Generate kinematics.

Routine is taken from https://github.com/NNPDF/nnpdf/blob/17952b40f02d23fc2b29a702ea93db6dc4e3b2fa/buildmaster/filters/POS.cc
and meta data from https://github.com/NNPDF/nnpdf/blob/17952b40f02d23fc2b29a702ea93db6dc4e3b2fa/buildmaster/meta/POSF2U.yaml .

Returns
-------
list
list of kinematics
"""
# from meta
fNData = 20

q2pos = 5.0 # GeV2
xmin = 5e-7
xmax = 0.9
xch = 0.1
nxposlog = fNData / 2
step = (xmax - xch) / (fNData - nxposlog)

xs = []
for j in range(fNData):
if j < nxposlog:
xs.append(xmin * pow(xch / xmin, j / (nxposlog - 1)))
else:
xs.append(xch + step * (1 + j - nxposlog))
return [{"Q2": q2pos, "x": x, "y": 1.0} for x in xs]


def dump(src_path, _target):
"""Compute positivity observables.

Parameters
----------
src_path : str
input path

Returns
-------
dict
observables dictionary, corresponding to the runcard
"""
obs = copy.deepcopy(obs_template)
with open(src_path, "r", encoding="utf-8") as f:
obs_update = yaml.safe_load(f)
obs["NCPositivityCharge"] = obs_update["NCPositivityCharge"]
obs["observables"][obs_update["obs"]] = _make_kins()
obs["prDIS"] = "EM"
obs["ProjectileDIS"] = "electron"
obs["TargetDIS"] = "proton"

return obs


# renaming
new_names = {
"u": "NNPDF_POS_F2U_40",
"d": "NNPDF_POS_F2D_40",
"s": "NNPDF_POS_F2S_40",
"c": "NNPDF_POS_F2C_40",
"g": "NNPDF_POS_FLL_40",
}
12 changes: 6 additions & 6 deletions extras/data/machinery/generate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
import argparse

from . import BCDMS, CHORUS, HERA, NMC, NUTEV, SLAC, utils
from . import BCDMS, CHORUS, HERA, NMC, NUTEV, POS, SLAC, utils

exps = {
getattr(m, "__name__").split(".")[-1]: m
for m in [CHORUS, HERA, NMC, NUTEV, SLAC, BCDMS]
getattr(m, "__name__").rsplit(".", maxsplit=1)[-1]: m
for m in [BCDMS, CHORUS, HERA, NMC, NUTEV, POS, SLAC]
}


Expand All @@ -27,7 +25,9 @@ def cli(subparsers):
def main(args):
for i in args.inputs:
path = utils.runcards.parent / i
exp = exps[list(filter(lambda e: e in path.parent.name, exps.keys()))[0]]
exp = exps[
list(filter(lambda e, path=path: e in path.parent.name, exps.keys()))[0]
]
try:
new_name = exp.new_names[path.stem]
except KeyError:
Expand Down
1 change: 1 addition & 0 deletions extras/data/machinery/generate/template/observable.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NCPositivityCharge: null
interpolation_polynomial_degree: 4
interpolation_xgrid: []
interpolation_is_log: true
Expand Down
59 changes: 4 additions & 55 deletions extras/data/machinery/generate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,12 @@
import numpy as np
import yaml

from yadmark.data import pineappl_xgrid

here = pathlib.Path(__file__).parent
template = here / "template"
runcards = here.parents[1] / "_runcards"

pineapple_xgrid = [
1.9999999999999954e-07,
3.034304765867952e-07,
4.6035014748963906e-07,
6.984208530700364e-07,
1.0596094959101024e-06,
1.607585498470808e-06,
2.438943292891682e-06,
3.7002272069854957e-06,
5.613757716930151e-06,
8.516806677573355e-06,
1.292101569074731e-05,
1.9602505002391748e-05,
2.97384953722449e-05,
4.511438394964044e-05,
6.843744918967896e-05,
0.00010381172986576898,
0.00015745605600841445,
0.00023878782918561914,
0.00036205449638139736,
0.0005487795323670796,
0.0008314068836488144,
0.0012586797144272762,
0.0019034634022867384,
0.0028738675812817515,
0.004328500638820811,
0.006496206194633799,
0.009699159574043398,
0.014375068581090129,
0.02108918668378717,
0.030521584007828916,
0.04341491741702269,
0.060480028754447364,
0.08228122126204893,
0.10914375746330703,
0.14112080644440345,
0.17802566042569432,
0.2195041265003886,
0.2651137041582823,
0.31438740076927585,
0.3668753186482242,
0.4221667753589648,
0.4798989029610255,
0.5397572337880445,
0.601472197967335,
0.6648139482473823,
0.7295868442414312,
0.7956242522922756,
0.8627839323906108,
0.9309440808717544,
1,
]


def load(path, skiprows, fields):
"""
Expand Down Expand Up @@ -88,7 +37,7 @@ def load(path, skiprows, fields):
# Load obs template
with open(template / "observable.yaml", encoding="utf-8") as o:
obs_template = yaml.safe_load(o)
obs_template["interpolation_xgrid"] = pineapple_xgrid
obs_template["interpolation_xgrid"] = pineappl_xgrid

# Load metadata template
with open(template / "metadata.yaml", encoding="utf-8") as m:
Expand All @@ -105,7 +54,7 @@ def dump(exp, path, new_name):
print(f"exp = {exp.__name__.split('.')[-1]}\tdataset = {path.stem}")
print(f"#bins = {bins}")
print(f"\tWriting: {path}\n\tto: {target.parent}")
with open(target, "w") as o:
with open(target, "w", encoding="utf-8") as o:
yaml.safe_dump(obs, o)
with open(target.with_name("metadata.txt"), "w", encoding="utf-8") as m:
for k, v in metadata(path, new_name).items():
Expand Down
15 changes: 0 additions & 15 deletions extras/data/navigator.py

This file was deleted.

Loading