Skip to content

Commit

Permalink
Merge pull request #105 from NNPDF/feature/composite-output
Browse files Browse the repository at this point in the history
Composite Output
  • Loading branch information
felixhekhorn authored Oct 10, 2022
2 parents 72b3a34 + 47e30e5 commit 1c27efc
Show file tree
Hide file tree
Showing 69 changed files with 3,559 additions and 1,685 deletions.
42 changes: 29 additions & 13 deletions benchmarks/eko/benchmark_evol_to_unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from eko.couplings import Couplings
from eko.evolution_operator import Operator
from eko.evolution_operator.grid import OperatorGrid
from eko.interpolation import InterpolatorDispatcher
from eko.interpolation import InterpolatorDispatcher, XGrid
from eko.thresholds import ThresholdsAtlas

# from eko.matching_conditions.operator_matrix_element import OperatorMatrixElement
Expand Down Expand Up @@ -43,24 +43,34 @@ class BenchmarkBackwardForward:
operators_card = {
"Q2grid": [10],
# here you need a very dense grid
"interpolation_xgrid": np.linspace(1e-1, 1, 30),
# "interpolation_xgrid": make_grid(30,30, x_min=1e-3),
"interpolation_polynomial_degree": 1,
"interpolation_is_log": True,
"debug_skip_singlet": False,
"debug_skip_non_singlet": False,
"ev_op_max_order": 1,
"ev_op_iterations": 1,
"backward_inversion": "exact",
"n_integration_cores": 1,
"xgrid": np.linspace(1e-1, 1, 30),
# "xgrid": make_grid(30,30, x_min=1e-3),
"configs": {
"interpolation_polynomial_degree": 1,
"interpolation_is_log": True,
"ev_op_max_order": (2, 0),
"ev_op_iterations": 1,
"backward_inversion": "exact",
"n_integration_cores": 1,
},
"debug": {
"skip_singlet": False,
"skip_non_singlet": False,
},
}
new_theory, new_operators = compatibility.update(theory_card, operators_card)
g = OperatorGrid.from_dict(
new_theory,
new_operators,
ThresholdsAtlas.from_dict(new_theory),
Couplings.from_dict(new_theory),
InterpolatorDispatcher.from_dict(new_operators),
InterpolatorDispatcher(
XGrid(
new_operators["xgrid"],
log=new_operators["configs"]["interpolation_is_log"],
),
new_operators["configs"]["interpolation_polynomial_degree"],
),
)

def test_operator_grid(
Expand All @@ -72,7 +82,13 @@ def test_operator_grid(
self.new_operators,
ThresholdsAtlas.from_dict(self.new_theory),
Couplings.from_dict(self.new_theory),
InterpolatorDispatcher.from_dict(self.new_operators),
InterpolatorDispatcher(
XGrid(
self.new_operators["xgrid"],
log=self.new_operators["configs"]["interpolation_is_log"],
),
self.new_operators["configs"]["interpolation_polynomial_degree"],
),
)
q20 = 30
q21 = 50
Expand Down
40 changes: 7 additions & 33 deletions benchmarks/ekobox/benchmark_evol_pdf.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# -*- coding: utf-8 -*-
import pathlib

import lhapdf
import numpy as np
import pytest

from eko import basis_rotation as br
from eko import output
from ekobox import evol_pdf as ev_p
from ekobox import gen_op as g_o
from ekobox import gen_theory as g_t
from ekobox import operators_card as oc
from ekobox import theory_card as tc
from ekobox.genpdf import load

test_pdf = pathlib.Path(__file__).parent / "fakepdf"
lhapdf = pytest.importorskip("lhapdf")


@pytest.mark.isolated
Expand All @@ -22,8 +21,8 @@ def benchmark_evolve_single_member(tmp_path, cd, lhapdf_path):
100.0,
10000.0,
]
op = g_o.gen_op_card(q2grid)
theory = g_t.gen_theory_card(
op = oc.generate(q2grid)
theory = tc.generate(
0,
5.0,
update={
Expand Down Expand Up @@ -80,10 +79,10 @@ def benchmark_evolve_single_member(tmp_path, cd, lhapdf_path):

@pytest.mark.isolated
def benchmark_evolve_more_members(tmp_path, cd, lhapdf_path):
op = g_o.gen_op_card(
op = oc.generate(
[10, 100], update={"interpolation_xgrid": [1e-7, 0.01, 0.1, 0.2, 0.3]}
)
theory = g_t.gen_theory_card(0, 1.0)
theory = tc.generate(0, 1.0)
with lhapdf_path(test_pdf):
pdfs = lhapdf.mkPDFs("myMSTW2008nlo90cl")
d = tmp_path / "sub"
Expand All @@ -102,28 +101,3 @@ def benchmark_evolve_more_members(tmp_path, cd, lhapdf_path):
for x in [1e-7, 0.01, 0.1, 0.2, 0.3]:
for pid in [21, 1, 2]:
assert new_pdf_1.xfxQ2(pid, x, Q2) != new_pdf_2.xfxQ2(pid, x, Q2)


@pytest.mark.isolated
def benchmark_gen_and_dump_out(tmp_path):
op = g_o.gen_op_card(
[100.0], update={"interpolation_xgrid": [1e-7, 0.01, 0.1, 0.2, 0.3]}
)
theory = g_t.gen_theory_card(0, 1.0)

out = ev_p.gen_out(theory, op, path=tmp_path)

ops_id = f"o{op['hash'][:6]}_t{theory['hash'][:6]}"
outpath = f"{tmp_path}/{ops_id}.tar"
loaded_out = output.Output.load_tar(outpath)
for el, load_el in zip(
out["interpolation_xgrid"], loaded_out["interpolation_xgrid"]
):
assert el == load_el
for el, load_el in zip(
out["Q2grid"][100.0]["operators"], loaded_out["Q2grid"][100.0]["operators"]
):
np.testing.assert_allclose(
out["Q2grid"][100.0]["operators"],
loaded_out["Q2grid"][100.0]["operators"],
)
30 changes: 0 additions & 30 deletions benchmarks/ekobox/benchmark_gen_theory.py

This file was deleted.

50 changes: 0 additions & 50 deletions benchmarks/ekobox/benchmark_utils.py

This file was deleted.

88 changes: 0 additions & 88 deletions benchmarks/ekobox/genpdf/benchmark_flavors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,6 @@
lhapdf = pytest.importorskip("lhapdf")


@pytest.mark.isolated
def benchmark_is_evolution():
assert genpdf.flavors.is_evolution_labels(["V", "T3"])
assert not genpdf.flavors.is_evolution_labels(["21", "2"])


@pytest.mark.isolated
def benchmark_is_pids():
assert not genpdf.flavors.is_pid_labels(["V", "T3"])
assert not genpdf.flavors.is_pid_labels(["35", "9"])
assert not genpdf.flavors.is_pid_labels({})
assert genpdf.flavors.is_pid_labels([21, 2])


@pytest.mark.isolated
def benchmark_flavors_pid_to_flavor():
flavs = genpdf.flavors.pid_to_flavor([1, 2, 21, -3])
for f in flavs:
for g in flavs:
if not np.allclose(f, g):
assert f @ g == 0


@pytest.mark.isolated
def benchmark_flavors_evol_to_flavor():
flavs = genpdf.flavors.evol_to_flavor(["S", "g", "T3", "V8"])
for f in flavs:
for g in flavs:
if not np.allclose(f, g):
assert f @ g == 0


@pytest.mark.isolated
def benchmark_flavors_pids_ct14(tmp_path, cd):
with cd(tmp_path):
Expand Down Expand Up @@ -101,59 +69,3 @@ def benchmark_flavors_evol_ct14(tmp_path, cd):
np.testing.assert_allclose(
pdf.xfxQ2(21, x, Q2), gonly.xfxQ2(21, x, Q2)
)


@pytest.mark.isolated
def benchmark_flavors_evol_raw():
blocks = [
{
"Q2grid": np.array([1, 2]),
"xgrid": np.array([0.1, 1.0]),
"pids": np.array([-1, 21, 1]),
"data": np.array([[0.1, 0.2, 0.1]] * 4),
}
]
gonly = genpdf.flavors.project(blocks, genpdf.flavors.evol_to_flavor(["g"]))
assert len(gonly) == 1
np.testing.assert_allclose(
gonly[0]["data"],
np.array(
[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] * 4
),
)
Sonly = genpdf.flavors.project(blocks, genpdf.flavors.evol_to_flavor(["S"]))
assert len(Sonly) == 1
for i in [0, 1, 2, 3]:
# g and gamma are zero
np.testing.assert_allclose(Sonly[0]["data"][i][7], 0)
np.testing.assert_allclose(Sonly[0]["data"][i][0], 0)
# quark are all equal and equal to anti-quarks
for pid in [2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13]:
np.testing.assert_allclose(Sonly[0]["data"][i][pid], Sonly[0]["data"][i][1])


@pytest.mark.isolated
def benchmark_flavors_evol_nodata():
# try with a block without data
blocks = [
{
"Q2grid": np.array([1, 2]),
"xgrid": np.array([0.1, 1.0]),
"pids": np.array([-1, 21, 1]),
"data": np.array([]),
},
{
"Q2grid": np.array([1, 2]),
"xgrid": np.array([0.1, 1.0]),
"pids": np.array([-1, 21, 1]),
"data": np.array([[0.1, 0.2, 0.1]] * 4),
},
]
gonly = genpdf.flavors.project(blocks, genpdf.flavors.evol_to_flavor(["g"]))
assert len(gonly) == 2
np.testing.assert_allclose(
gonly[1]["data"],
np.array(
[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] * 4
),
)
26 changes: 0 additions & 26 deletions benchmarks/ekobox/genpdf/benchmark_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,6 @@
lhapdf = pytest.importorskip("lhapdf")


@pytest.mark.isolated
def benchmark_genpdf_exceptions(tmp_path, cd):
# using a wrong label and then a wrong parent pdf
with cd(tmp_path):
with pytest.raises(TypeError):
genpdf.generate_pdf(
"test_genpdf_exceptions1",
["f"],
{
21: lambda x, Q2: 3.0 * x * (1.0 - x),
2: lambda x, Q2: 4.0 * x * (1.0 - x),
},
)
with pytest.raises(ValueError):
genpdf.generate_pdf(
"test_genpdf_exceptions2",
["g"],
10,
)
with pytest.raises(FileExistsError):
genpdf.install_pdf("foo")

with pytest.raises(TypeError):
genpdf.generate_pdf("debug", [21], info_update=(10, 15, 20))


@pytest.mark.isolated
def benchmark_genpdf_no_parent_and_install(tmp_path, cd):
with cd(tmp_path):
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/lha_paper_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ def benchmark_sv(self, pto):
obj = BenchmarkVFNS()
# obj = BenchmarkFFNS()

# obj.benchmark_plain(0)
obj.benchmark_sv(2)
obj.benchmark_plain(0)
# obj.benchmark_sv(2)

# # VFNS benchmarks with LHA settings
# programs = ["LHA", "pegasus", "apfel"]
Expand Down
2 changes: 1 addition & 1 deletion doc/source/code/IO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ The ``Q2grid`` values are the actual tensor for the requested :math:`Q^2`. Each
- ``operators`` a :py:obj:`dict` with all evolution kernel operators where the key indicates which distribution is generated by which other one
and the value represents the eko in matrix representation - this can either be the plain list representation or the binary representation
(as provided by :py:meth:`numpy.ndarray.tobytes`)
- ``operator_errors`` a :py:obj:`dict` with the integration errors associated to the respective operators following the same conventions as
- ``errors`` a :py:obj:`dict` with the integration errors associated to the respective operators following the same conventions as
the ``operator`` dictionary

Each element (|EKO|) is a rank-4 tensor with the indices ordered in the following way: ``EKO[pid_out][x_out][pid_in][x_in]`` where ``pid_out`` and ``x_out``
Expand Down
3 changes: 3 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None

# Criterion to sort class members
autodoc_member_order = "bysource"

# A string to be included at the beginning of all files
shared = here / "shared"
rst_prolog = "\n".join(
Expand Down
Loading

0 comments on commit 1c27efc

Please sign in to comment.