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 LHA VFNS SV benchmark 2 #219

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 3 additions & 4 deletions benchmarks/apfel_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def benchmark_sv(self, pto, svmode):
{
"PTO": [pto],
"XIR": [1 / np.sqrt(2.0)],
"fact_to_ren_scale_ratio": [np.sqrt(2.0)],
"XIF": [np.sqrt(2.0)],
"ModSV": [svmode],
"EScaleVar": [0],
"nfref": [4],
Expand Down Expand Up @@ -177,7 +177,7 @@ def benchmark_sv(self, pto, svmode):
{
"PTO": [pto],
"XIR": [np.sqrt(0.5)],
"fact_to_ren_scale_ratio": [np.sqrt(2.0)],
"XIF": [np.sqrt(2.0)],
"ModSV": [svmode],
"EScaleVar": [0],
}
Expand All @@ -188,7 +188,7 @@ def benchmark_sv(self, pto, svmode):
{
"PTO": [pto],
"XIR": [np.sqrt(2.0)],
"fact_to_ren_scale_ratio": [np.sqrt(0.5)],
"XIF": [np.sqrt(0.5)],
"ModSV": [svmode],
"EScaleVar": [0],
}
Expand All @@ -198,7 +198,6 @@ def benchmark_sv(self, pto, svmode):


if __name__ == "__main__":

# obj = BenchmarkVFNS()
obj = BenchmarkFFNS()

Expand Down
7 changes: 3 additions & 4 deletions benchmarks/lha_paper_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ def sv_theories(self, pto):
"""
low = self.theory.copy()
low["PTO"] = pto
low["fact_to_ren_scale_ratio"] = np.sqrt(1.0 / 2.0)
low["XIF"] = np.sqrt(1.0 / 2.0)
low["ModSV"] = "exponentiated"
high = self.theory.copy()
high["PTO"] = pto
high["fact_to_ren_scale_ratio"] = np.sqrt(2.0)
high["XIF"] = np.sqrt(2.0)
high["ModSV"] = "exponentiated"
return [high, low]
Expand Down Expand Up @@ -246,10 +244,11 @@ def run_lha(self, theory_updates):

if __name__ == "__main__":
# Benchmark to LHA
obj = BenchmarkFFNS_polarized()
# obj = BenchmarkFFNS_polarized()
# obj = BenchmarkFFNS()
obj = BenchmarkVFNS()
# obj.benchmark_plain(1)
obj.benchmark_sv(1)
obj.benchmark_sv(2)

# # VFNS benchmarks with LHA settings
# programs = ["LHA", "pegasus", "apfel"]
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/pegasus_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def benchmark_sv(self, pto, svmode):
th.update(
{
"PTO": [pto],
"fact_to_ren_scale_ratio": [np.sqrt(0.5), np.sqrt(2.0)],
"XIF": [np.sqrt(0.5), np.sqrt(2.0)],
"ModSV": [svmode],
}
)
Expand Down Expand Up @@ -141,7 +141,7 @@ def benchmark_sv(self, pto, svmode):
th.update(
{
"PTO": [pto],
"fact_to_ren_scale_ratio": [np.sqrt(0.5), np.sqrt(2.0)],
"XIF": [np.sqrt(0.5), np.sqrt(2.0)],
"ModSV": [svmode],
}
)
Expand All @@ -151,7 +151,6 @@ def benchmark_sv(self, pto, svmode):


if __name__ == "__main__":

# obj = BenchmarkVFNS()
obj = BenchmarkFFNS()
obj.benchmark_plain_pol(1)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def doit(self):
"QED": 0,
# "ModEv": "EXA",
# "XIR": 0.5,
# "fact_to_ren_scale_ratio": 2.0,
# "XIF": 2.0,
"Q0": 1.65, # np.sqrt(10),
# "Qref": 1.5,
# "alphas": 0.35,
Expand Down Expand Up @@ -116,7 +116,7 @@ def lha(self):
"FNS": "FFNS",
"NfFF": 4,
"ModEv": "EXA",
"fact_to_ren_scale_ratio": np.sqrt(2),
"XIF": np.sqrt(2),
"Q0": np.sqrt(2),
"kcThr": 0.0,
"kbThr": np.inf,
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 @@ -32,12 +32,12 @@ and environment. The benchmark settings are available at :mod:`banana.data.theor
``iterate-exact`` abbreviated with ``EXA``, ``decompose-exact``, ``perturbative-exact``,
``iterate-expanded`` abbreviated with ``EXP``, ``decompose-expanded``, ``perturbative-expanded``,
``truncated`` abbreviated with ``TRN``, ``ordered-truncated``.
* - ``fact_to_ren_scale_ratio``
* - ``XIF``
- :py:obj:`float`
- Factorization to renormalization scale ratio. ``1`` means no scale variation.
* - ``ModSV``
- :py:obj:`str`
- Scale variation method, used only if ``fact_to_ren_scale_ratio!=1``. Possible options are:
- Scale variation method, used only if ``XIF!=1``. Possible options are:
``expanded`` or ``exponentiated``.
* - ``Q0``
- :py:obj:`float`
Expand Down
1 change: 0 additions & 1 deletion extras/matching/check-matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"IC": 0,
"NfFF": 3,
"Qref": 1.4142135623730951,
"fact_to_ren_scale_ratio": 1.0,
"mb": 4.5,
"CKM": "0.97428 0.22530 0.003470 0.22520 0.97345 0.041000 0.00862 0.04030 0.999152",
"IB": 0,
Expand Down
38 changes: 14 additions & 24 deletions src/eko/evolution_operator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,35 +313,23 @@ def grid_size(self):
"""Return the grid size."""
return self.int_disp.xgrid.size

def sv_exponentiated_shift(self, q2):
"""Compute shifted renormalization scale.

Parameters
----------
q2 : float
factorization scale

Returns
-------
float
renormalization scale
"""
if self.sv_mode == sv.Modes.exponentiated:
return q2 / self.xif2
return q2

@property
def a_s(self):
"""Return the computed values for :math:`a_s`."""
sc = self.managers["strong_coupling"]
a0 = sc.a_s(
self.sv_exponentiated_shift(self.q2_from),
fact_scale=self.q2_from,
self.q2_from,
fact_scale=self.q2_from * self.xif2,
nf_to=self.nf,
)
a1 = sc.a_s(
self.sv_exponentiated_shift(self.q2_to),
fact_scale=self.q2_to,
self.q2_to
* (
self.xif2
if not self.is_threshold and self.sv_mode == sv.Modes.expanded
else 1.0
),
fact_scale=self.q2_to * self.xif2,
nf_to=self.nf,
)
return (a0, a1)
Expand Down Expand Up @@ -483,7 +471,9 @@ def compute(self):
# unless we have to do some scale variation
# TODO remove if K is factored out of here
if not (
self.sv_mode == sv.Modes.expanded and not np.isclose(self.xif2, 1.0)
self.sv_mode == sv.Modes.expanded
and not np.isclose(self.xif2, 1.0)
and not self.is_threshold
):
logger.info(
"%s: skipping unity operator at %e", self.log_label, self.q2_from
Expand All @@ -501,8 +491,8 @@ def compute(self):
logger.info(
"%s: µ_R^2 distance: %e -> %e",
self.log_label,
self.sv_exponentiated_shift(self.q2_from),
self.sv_exponentiated_shift(self.q2_to),
self.q2_from,
self.q2_to,
)
if self.sv_mode != sv.Modes.unvaried:
logger.info(
Expand Down
6 changes: 1 addition & 5 deletions src/eko/evolution_operator/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ def compute(self, q2grid=None):
# And now return the grid
grid_return = {}
for q2 in q2grid:
# shift path for expanded scheme
q2_gen = (
q2 * self.config["xif2"] if self.sv_mode == sv.Modes.expanded else q2
)
grid_return[q2] = self.generate(q2_gen)
grid_return[q2] = self.generate(q2)
return grid_return

def generate(self, q2):
Expand Down
4 changes: 1 addition & 3 deletions src/eko/evolution_operator/operator_matrix_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ def a_s(self):
Note that here you need to use :math:`a_s^{n_f+1}`
"""
sc = self.managers["strong_coupling"]
return sc.a_s(
self.sv_exponentiated_shift(self.q2_from), self.q2_from, nf_to=self.nf + 1
)
return sc.a_s(self.q2_from, self.q2_from * self.xif2, nf_to=self.nf + 1)

def compute(self):
"""Compute the actual operators (i.e. run the integrations)."""
Expand Down
1 change: 1 addition & 0 deletions src/eko/runner/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(
)

# strong coupling
new_theory.couplings.alphas.scale *= new_theory.xif
sc = Couplings(
couplings=new_theory.couplings,
order=new_theory.order,
Expand Down
5 changes: 3 additions & 2 deletions src/ekomark/benchmark/external/LHA_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@
]
)


# rotate basis
def rotate_data(raw, is_ffns_nnlo=False, rotate_to_evolution_basis=False):
"""Rotate data in flavor space.

Rotate either to flavor basis or evolution basis from the LHA basis, which is yet an other basis.

Parameters
Expand Down Expand Up @@ -140,7 +141,7 @@ def compute_LHA_data(theory, operators, rotate_to_evolution_basis=False):
with open(here / yaml_file, encoding="utf-8") as o:
data = yaml.safe_load(o)
fns = theory["FNS"]
xif = (theory["fact_to_ren_scale_ratio"]) ** 2
xif = (theory["XIF"]) ** 2
if order == 0 and xif != 1.0:
raise ValueError("LO LHA tables with scale variations are not available")
table = None
Expand Down
9 changes: 2 additions & 7 deletions src/ekomark/benchmark/external/pegasus_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def compute_pegasus_data(theory, operators, skip_pdfs, rotate_to_evolution_basis
raise ValueError("Initial scale Q0 must be equal to Qref in Pegasus.")

if operators["polarized"]:
pegasus.initpol(
imodev, theory["PTO"], ivfns, nf, theory["fact_to_ren_scale_ratio"] ** 2
)
pegasus.initpol(imodev, theory["PTO"], ivfns, nf, theory["XIF"] ** 2)
pegasus.initpinp(
theory["alphas"],
theory["Qref"] ** 2,
Expand All @@ -59,9 +57,7 @@ def compute_pegasus_data(theory, operators, skip_pdfs, rotate_to_evolution_basis
(theory["ktThr"] * theory["mt"]) ** 2,
)
else:
pegasus.initevol(
imodev, theory["PTO"], ivfns, nf, theory["fact_to_ren_scale_ratio"] ** 2
)
pegasus.initevol(imodev, theory["PTO"], ivfns, nf, theory["XIF"] ** 2)
pegasus.initinp(
theory["alphas"],
theory["Qref"] ** 2,
Expand All @@ -87,7 +83,6 @@ def compute_pegasus_data(theory, operators, skip_pdfs, rotate_to_evolution_basis
# run pegaus
out_tabs = {}
for q2 in operators["Q2grid"]:

tab = {}
for x in target_xgrid:
# last two numbers are the min and max pid to calculate,
Expand Down
36 changes: 26 additions & 10 deletions src/ekomark/navigator/navigator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""EKO Navigator."""
import os
import webbrowser

Expand Down Expand Up @@ -51,10 +52,9 @@ def fill_theories(self, theo, obj):
"Qref",
"alphas",
"XIF",
"XIR",
]:
obj[f] = theo[f]
obj["F/R"] = theo["fact_to_ren_scale_ratio"]
obj["XIF"] = theo["XIF"]
obj["mcThr"] = theo["mc"] * theo["kcThr"]
obj["mbThr"] = theo["mb"] * theo["kbThr"]
obj["mtThr"] = theo["mt"] * theo["ktThr"]
Expand Down Expand Up @@ -133,7 +133,7 @@ def fill_logs(self, lg, obj):

def check_log(self, doc_hash, perc_thr=1, abs_thr=1e-6):
"""
Check if the log passed the default assertions
Check if the log passed the default assertions.

Parameters
----------
Expand All @@ -154,12 +154,13 @@ def check_log(self, doc_hash, perc_thr=1, abs_thr=1e-6):

def plot_pdfs(self, doc_hash):
"""
Plots all PDFs at the final scale.
Plot all PDFs at the final scale.

Parameters
----------
doc_hash : hash
log hash
doc_hash : hash
log hash

"""
log = self.get(bnav.l, doc_hash)
dfd = log["log"]
Expand All @@ -175,7 +176,6 @@ def plot_pdfs(self, doc_hash):
print(f"Writing pdf plots to {path}")

with PdfPages(path) as pp:

# print setup
theory = self.get(bnav.t, log["t_hash"][: self.hash_len])
ops = self.get(bnav.o, log["o_hash"][: self.hash_len])
Expand All @@ -201,12 +201,13 @@ def plot_pdfs(self, doc_hash):

def display_pdfs(self, doc_hash):
"""
Display PDF generated by ekomark.navigator.navigator.plot_pdfs
Display PDF generated by ekomark.navigator.navigator.plot_pdfs.

Parameters
----------
doc_hash : hash
log hash
doc_hash : hash
log hash

"""
log = self.get(bnav.l, doc_hash)
directory = (
Expand All @@ -230,6 +231,21 @@ def display_pdfs(self, doc_hash):

@staticmethod
def is_valid_physical_object(name):
"""Identify physical objects.

Used to test names, in order to distinguish physical quantities from metadata.

Parameters
----------
name: str
name to test

Returns
-------
bool
test response

"""
return name in br.evol_basis or name in br.flavor_basis_names

def compare_external(self, dfd1, dfd2):
Expand Down
4 changes: 1 addition & 3 deletions tests/eko/evolution_operator/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ def test_mod_expanded(theory_card, theory_ffns, operator_card, tmp_path: pathlib
theory.order = (1, 0)
theory.num_flavs_init = nf0
theory.matching
theory.fact_to_ren = 1.0
path.unlink(missing_ok=True)
opgrid = legacy.Runner(theory, operator_card, path=path).op_grid
opg = opgrid.compute(3)
theory.fact_to_ren = 1.0 + epsilon
theory_update["fact_to_ren_scale_ratio"] = 1.0 + epsilon
theory_update["XIF"] = 1.0 + epsilon
path.unlink(missing_ok=True)
sv_opgrid = legacy.Runner(theory, operator_card, path=path).op_grid
sv_opg = sv_opgrid.compute(3)
Expand Down
1 change: 0 additions & 1 deletion tests/eko/evolution_operator/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def test_exponentiated(self, theory_ffns, operator_card, tmp_path):
g = r.op_grid
# setup objs
o = Operator(g.config, g.managers, 3, 2.0, 10.0)
np.testing.assert_allclose(o.sv_exponentiated_shift(40.0), 10.0)
o.compute()
self.check_lo(o)

Expand Down
Loading