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

Scale Variations - NLO #33

Merged
merged 7 commits into from
Apr 23, 2020
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
1 change: 1 addition & 0 deletions benchmarks/aux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PDFs
17 changes: 15 additions & 2 deletions benchmarks/aux/apfel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def load_apfel(par):
apfel.SetRenFacRatio(par.get("XIR") / par.get("XIF"))
apfel.SetRenQRatio(par.get("XIR"))
apfel.SetFacQRatio(par.get("XIF"))
# Scale Variations
# consistent with Evolution (0) or DIS only (1)
# look at SetScaleVariationProcedure.f
apfel.SetScaleVariationProcedure(par.get("EScaleVar"))

# Small-x resummation
apfel.SetSmallxResummation(par.get("SxRes"), par.get("SxOrd"))
Expand Down Expand Up @@ -145,7 +149,8 @@ def get_apfel_data(theory_path, dis_observables_path):
raise FileNotFoundError("Missing runcards.")

# get last edit for runcards
input_mtime = max(theory_p.stat().st_mtime, obs_p.stat().st_mtime)
dependencies = [theory_p, obs_p, pathlib.Path(__file__)]
input_mtime = max([p.stat().st_mtime for p in dependencies])

cache_path = cache_location / f"{theory_p.stem}-{obs_p.stem}.yaml"

Expand Down Expand Up @@ -184,7 +189,15 @@ def get_apfel_data(theory_path, dis_observables_path):
Q2 = kinematics["Q2"]
x = kinematics["x"]

apfel.ComputeStructureFunctionsAPFEL(np.sqrt(Q2), np.sqrt(Q2))
# disable APFEL evolution: we are interested in the pure DIS part
#
# setting initial scale to muF (sqrt(Q2)*xiF) APFEL is going to:
# - take the PDF at the scale of muF (exactly as we are doing)
# - evolve from muF to muF because the final scale is the second
# argument times xiF (internally), so actually it's not evolving
apfel.ComputeStructureFunctionsAPFEL(
np.sqrt(Q2) * theory["XIF"], np.sqrt(Q2)
)
value = apfel_FX(x)

res_tab[FX].append(dict(x=x, Q2=Q2, value=value))
Expand Down
110 changes: 110 additions & 0 deletions benchmarks/aux/generatePDF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import pathlib

import numpy as np

from jinja2 import Environment, FileSystemLoader

# ==========
# globals
# ==========


here = pathlib.Path(__file__).parent.absolute()
env = Environment(loader=FileSystemLoader(str(here / "templatePDF")))


def stringify(ls, fmt="%.6e"):
return " ".join([fmt % x for x in ls])


def stringify2(ls):
table = ""
for line in ls:
table += ("% .8e " % line[0]) + stringify(line[1:], fmt="%.8e") + "\n"
return table


# ==========
# dump
# ==========


def dump_pdf(name, xgrid, Q2grid, pids, pdf_table):
# collect data

data = dict(
xgrid=stringify(xgrid),
Q2grid=stringify(Q2grid),
pids=stringify(pids, fmt="%d"),
pdf_table=stringify2(pdf_table),
)

# ===========
# apply template

templatePDF = env.get_template("templatePDF.dat")
stream = templatePDF.stream(data)
stream.dump(str(here / "PDFs" / name / f"{name}_0000.dat"))


def dump_info(name, description, pids):
# collect data

data = dict(description=description, pids=pids,)

# ===========
# apply template

templatePDF = env.get_template("templatePDF.info")
stream = templatePDF.stream(data)
stream.dump(str(here / "PDFs" / name / f"{name}.info"))


# ==========
# PDFs
# ==========


def uonly():
name = "uonly"
(here / "PDFs" / name).mkdir(exist_ok=True)

# make PDF.dat

xgrid = np.logspace(-9, 0, 100)
Q2grid = np.logspace(0.3, 5, 20)
pids = [-3, -2, -1, 1, 2, 3, 21]
antis = antiu = antid = d = s = g = [0.0 for x in xgrid for Q2 in Q2grid]
u = [(1.0 - x) * x for x in xgrid for Q2 in Q2grid]
pdf_table = np.array([antis, antiu, antid, d, u, s, g]).T
# pdf_table = np.vstack([np.array(pdf_table_Q2).T for i in range(len(Q2grid))])
dump_pdf(name, xgrid, Q2grid, pids, pdf_table)

# make PDF.info
description = "'up quark only PDFset, for debug purpose'"
dump_info(name, description, pids)


def gonly():
name = "gonly"
(here / "PDFs" / name).mkdir(exist_ok=True)

# make PDF.dat

xgrid = np.logspace(-9, 0, 100)
Q2grid = np.logspace(0.3, 5, 20)
pids = [-3, -2, -1, 1, 2, 3, 21]
antis = antiu = antid = d = u = s = [0.0 for x in xgrid for Q2 in Q2grid]
g = [(1.0 - x) * x for x in xgrid for Q2 in Q2grid]
pdf_table = np.array([antis, antiu, antid, d, u, s, g]).T
# pdf_table = np.vstack([np.array(pdf_table_Q2).T for i in range(len(Q2grid))])
dump_pdf(name, xgrid, Q2grid, pids, pdf_table)

# make PDF.info
description = "'gluon only PDFset, for debug purpose'"
dump_info(name, description, pids)


if __name__ == "__main__":
# uonly()
gonly()
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ def rel_err(row):

if __name__ == "__main__":
# hard coded paths
F2light_LO = logs_dir / "theory_LO-F2light-F2light.csv"
# F2light_LO = logs_dir / "theory_LO-F2light-F2light.csv"
# F2light_NLO = logs_dir / "theory_NLO-F2light-F2light.csv"
# output_f = logs_dir / "theory_pNLO-F2light-F2light.csv"

# run subtraction
# subtract_tables(F2light_NLO, F2light_LO, output_f)

F2light_NLO = logs_dir / "theory_NLO-F2light-F2light.csv"
output_f = logs_dir / "theory_pNLO-F2light-F2light.csv"
F2light_NLO_SV = logs_dir / "theory_SV_NLO-F2light-F2light.csv"
output_f = logs_dir / "theory_pSV_NLO-F2light-F2light.csv"

# run subtraction
subtract_tables(F2light_NLO, F2light_LO, output_f)
subtract_tables(F2light_NLO_SV, F2light_NLO, output_f)
9 changes: 9 additions & 0 deletions benchmarks/aux/templatePDF/templatePDF.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{# vim: ft=jinja: -#}
PdfType: central
Format: lhagrid1
---
{{ xgrid }}
{{ Q2grid }}
{{ pids }}
{{ pdf_table -}}
---
29 changes: 29 additions & 0 deletions benchmarks/aux/templatePDF/templatePDF.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
SetDesc: {{ description }}
SetIndex: 13206
Authors: F. Hekhorn, A. Candido
Reference:
Format: lhagrid1
DataVersion: 1
NumMembers: 1
Particle: 2212
Flavors: {{ pids }}
ForcePositive: 1
OrderQCD: 0
FlavorScheme: variable
NumFlavors: 3
XMin: 1.000000e-09
XMax: 1
QMin: 1.295000e+00
QMax: 100000
MZ: 91.1876
MUp: 0
MDown: 0
MStrange: 0
MCharm: 1.3
MBottom: 4.75
MTop: 172
AlphaS_MZ: 0.118000
AlphaS_OrderQCD: 0
AlphaS_Type: ipol
AlphaS_Qs: [1.295000e+00, 1.475010e+00, 1.691180e+00, 1.952560e+00, 2.270860e+00, 2.661400e+00, 3.144360e+00, 3.746580e+00, 4.504060e+00, 5.465600e+00, 6.697950e+00, 8.293410e+00, 1.038100e+01, 1.314320e+01, 1.684110e+01, 2.185310e+01, 2.873440e+01, 3.831200e+01, 5.183410e+01, 7.121450e+01, 9.943320e+01, 1.412090e+02, 2.041420e+02, 3.007030e+02, 4.517430e+02, 6.928310e+02, 1.085930e+03, 1.741380e+03, 2.860290e+03, 4.818130e+03, 8.334020e+03, 1.482260e+04, 2.714580e+04, 5.126670e+04, 1.000000e+05]
AlphaS_Vals: [4.200710e-01, 3.895640e-01, 3.619420e-01, 3.368440e-01, 3.139670e-01, 2.930520e-01, 2.738810e-01, 2.562640e-01, 2.400390e-01, 2.250660e-01, 2.112210e-01, 1.983960e-01, 1.864960e-01, 1.754390e-01, 1.651500e-01, 1.555630e-01, 1.466190e-01, 1.382660e-01, 1.304560e-01, 1.231460e-01, 1.162990e-01, 1.098790e-01, 1.038540e-01, 9.819640e-02, 9.287940e-02, 8.787930e-02, 8.317410e-02, 7.874380e-02, 7.457000e-02, 7.063560e-02, 6.692520e-02, 6.342420e-02, 6.011950e-02, 5.699860e-02, 5.405020e-02]
15 changes: 13 additions & 2 deletions benchmarks/aux/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def load_runcards(theory_file, observables_file):
"""
Load runcards from ``yaml`` files.
Load runcards from ``yaml`` files.

Parameters
----------
Expand Down Expand Up @@ -43,7 +43,7 @@ def load_runcards(theory_file, observables_file):
def print_comparison_table(res_tab, log_path_template=None):
"""
Print and dump comparison table.

Parameters
----------
res_tab :
Expand All @@ -69,3 +69,14 @@ def print_comparison_table(res_tab, log_path_template=None):
log_path = log_path_template.parent / log_path_template.name.format(obs=FX)
with open(log_path, "w") as f:
print_tab.to_csv(f)


def get_package_modules(package_path):
modules = pathlib.Path(package_path).glob("**/*.py")
return modules


def get_most_recent_timestamp(paths):
most_recent = max([p.stat().st_mtime for p in paths])

return most_recent
47 changes: 30 additions & 17 deletions benchmarks/benchmark_against_apfel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,34 @@
]


def test_LO():
"""
Test the full LO order against APFEL's.
"""
theory_f = test_data_dir / "theory_LO.yaml"
def theory_test(theory_filename, obs_filter=None):
theory_f = test_data_dir / theory_filename
# iterate over observables - only F2light at LO
for obs in observables[:1]:
for obs in observables[:obs_filter]:
dis_observables_f = test_data_dir / f"{obs}.yaml"
run_against_apfel(theory_f, dis_observables_f)


def test_NLO():
"""
Test the full NLO order against APFEL's.
"""
theory_f = test_data_dir / "theory_NLO.yaml"
# iterate over observables
for obs in observables:
dis_observables_f = test_data_dir / f"{obs}.yaml"
run_against_apfel(theory_f, dis_observables_f)
class TestPlain:
def test_LO(self):
"""
Test the full LO order against APFEL's.
"""
theory_test("theory_LO.yaml", 1)

def test_NLO(self):
"""
Test the full NLO order against APFEL's.
"""
theory_test("theory_NLO.yaml")


class TestScaleVariations:
def test_LO(self):
theory_test("theory_SV_LO.yaml", 1)

def test_NLO(self):
theory_test("theory_SV_NLO.yaml")


def run_against_apfel(theory_f, dis_observables_f):
Expand Down Expand Up @@ -129,5 +137,10 @@ def run_against_apfel(theory_f, dis_observables_f):


if __name__ == "__main__":
test_LO()
test_NLO()
plain = TestPlain()
# plain.test_LO()
plain.test_NLO()

sv = TestScaleVariations()
# sv.test_LO()
sv.test_NLO()
2 changes: 2 additions & 0 deletions benchmarks/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apfel_cache
logs
19 changes: 0 additions & 19 deletions benchmarks/data/logs/theory_NLO-F2bottom-F2bottom.csv

This file was deleted.

36 changes: 18 additions & 18 deletions benchmarks/data/logs/theory_NLO-F2charm-F2charm.csv
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
,x,Q2,APFEL,yadism,yadism_error,rel_err[%]
0,0.001,90.0,0.10965288393948448,0.10960675176301525,2.877917246381121e-10,-0.04207110183686025
1,0.0025118864315095794,90.0,0.09513110882913686,0.09509164961873946,1.7852353516603296e-10,-0.04147876639204462
2,0.00630957344480193,90.0,0.07853386690607639,0.07850211775891267,1.6268737661818756e-10,-0.04042733207278992
3,0.01584893192461114,90.0,0.05889503767289785,0.05887219031441063,5.3549550376541414e-11,-0.03879335066244716
4,0.039810717055349734,90.0,0.036550894326652546,0.03653762258936367,1.1912109517642818e-10,-0.03631029427151322
5,0.1,90.0,0.015197447628881146,0.015195773613836207,1.5799709987371499e-10,-0.011015106521949924
6,0.15,90.0,0.008042310190163868,0.008041603001024212,7.522601199743832e-11,-0.008793358163694531
7,0.3,90.0,0.001246402058639585,0.0012461721781422388,4.33513130571585e-12,-0.018443526769928997
8,0.44999999999999996,90.0,0.00015275114971777704,0.00015264923963666,5.16683654374225e-13,-0.06671640855425709
9,0.6,90.0,1.0297188466679881e-05,1.0273565211361875e-05,7.364693986639687e-14,-0.2294146154015464
10,0.75,90.0,1.6360248447700337e-07,1.6181530590160656e-07,2.46082611757182e-15,-1.0923908528100768
11,0.9,90.0,2.1989710985770277e-12,-7.172192194063902e-11,3.1671770572772996e-17,-3361.6127600335844
12,0.1,31.622776601683793,0.010111193209721144,0.010102276901359362,5.4502788464877604e-11,-0.08818255350129256
13,0.1,50.11872336272722,0.012519405591379155,0.012515451717143994,1.374011667446539e-10,-0.031581964545368546
14,0.1,79.43282347242814,0.014656184922714179,0.014663261645297338,9.558480808504243e-11,0.04828488873793724
15,0.1,125.89254117941675,0.016530217739259438,0.01652324856400884,1.839248725088117e-10,-0.042160214466180346
16,0.1,199.52623149688787,0.01813133639245425,0.0181171607288461,1.2893268574653118e-10,-0.07818322544637102
17,0.1,316.22776601683796,0.01951187789009538,0.019483621437424874,3.187465318652547e-10,-0.14481667438503987
0,0.001,90.0,0.482194330155762,0.48200377014426904,1.7516510127506196e-09,-0.039519338900440015
1,0.0025118864315095794,90.0,0.2949738928822863,0.29485880782260354,7.764046538221991e-10,-0.03901533744503638
2,0.00630957344480193,90.0,0.16676440129382059,0.16669978103771915,4.988790372852483e-10,-0.03874943069389625
3,0.01584893192461114,90.0,0.08445605756321714,0.08442432822607195,1.0045464642548739e-10,-0.03756904840300779
4,0.039810717055349734,90.0,0.03685505687101987,0.03684357239590002,1.4328290081291117e-10,-0.031161192234874235
5,0.1,90.0,0.012464787390483,0.012467664202650594,1.388020659425804e-10,0.023079512529755597
6,0.15,90.0,0.00640829777490724,0.006409053236201352,6.108427808624384e-11,0.01178879822143486
7,0.3,90.0,0.000980511667275842,0.0009803386503471144,3.4443247338665307e-12,-0.01764557572359049
8,0.44999999999999996,90.0,0.0001147883136109572,0.0001147031184382837,3.9531792060603546e-13,-0.07421937825677904
9,0.6,90.0,7.028110138648811e-06,7.010616282857428e-06,5.2248896361671793e-14,-0.24891265854216638
10,0.75,90.0,9.536177996104654e-08,9.419455208312376e-08,1.4878290980596248e-15,-1.2239996761800986
11,0.9,90.0,9.610724773268507e-13,-7.280784529229407e-11,1.830036596818946e-17,-7675.687267083488
12,0.1,31.622776601683793,0.009109535759146291,0.009103594528316784,4.9080241402221714e-11,-0.06521990787008436
13,0.1,50.11872336272722,0.010762673823513392,0.010762434697834899,1.2428257944055725e-10,-0.0022218054956835154
14,0.1,79.43282347242814,0.012132448828274493,0.012142646286434342,8.262812664400941e-11,0.08405111205649352
15,0.1,125.89254117941675,0.013243094558420019,0.013242234308657225,1.6264671555251777e-10,-0.006495836445163938
16,0.1,199.52623149688787,0.014097699930161856,0.014091950174272486,1.0067376600336265e-10,-0.04078506364764145
17,0.1,316.22776601683796,0.014749471948042665,0.014733918678584305,2.77408765548048e-10,-0.10544966974511683
Loading