Skip to content

Commit

Permalink
Fix bench evolve
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Oct 27, 2022
1 parent d35fef7 commit b5eb520
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 23 deletions.
35 changes: 25 additions & 10 deletions benchmarks/bench_evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
from eko import couplings as sc

import pineko
import pineko.evolve
import pineko.theory_card


def benchmark_write_operator_card_from_file(tmp_path, test_files):
def benchmark_write_operator_card_from_file(tmp_path, test_files, test_configs):
pine_path = test_files / "data/grids/208/HERA_CC_318GEV_EM_SIGMARED.pineappl.lz4"
default_path = test_files / "data/operator_cards/_template.yaml"
target_path = pathlib.Path(tmp_path / "test_operator.yaml")

# Load the theory card
tcard = pineko.theory_card.load(208)
tcard_path = pineko.theory_card.path(208)

x_grid, q2_grid = pineko.evolve.write_operator_card_from_file(
pine_path, default_path, target_path, 1.0, tcard
x_grid, _q2_grid = pineko.evolve.write_operator_card_from_file(
pine_path, default_path, target_path, 1.0, tcard_path
)

# Load the operator card
Expand All @@ -35,21 +37,31 @@ def benchmark_write_operator_card_from_file(tmp_path, test_files):

wrong_pine_path = test_files / "data/grids/208/HERA_CC_318GEV_EM_wrong.pineappl.lz4"
with pytest.raises(FileNotFoundError):
x_grid, q2_grid = pineko.evolve.write_operator_card_from_file(
wrong_pine_path, default_path, target_path, 1.0, tcard
_ = pineko.evolve.write_operator_card_from_file(
wrong_pine_path, default_path, target_path, 1.0, tcard_path
)


def benchmark_dglap(tmp_path):
def benchmark_dglap(tmp_path, test_files, test_configs):
pine_path = test_files / "data/grids/208/HERA_CC_318GEV_EM_SIGMARED.pineappl.lz4"
default_path = test_files / "data/operator_cards/_template.yaml"
target_path = pathlib.Path(tmp_path / "test_operator.yaml")

theory_id = 208
# In order to check if the operator card is enough for eko, let's compute the eko
tcard = pineko.theory_card.load(208)
tcard = eko.compatibility.update_theory(pineko.theory_card.load(theory_id))
if "ModSV" not in tcard:
tcard["ModSV"] = "expanded"

pineko.evolve.write_operator_card_from_file(
pine_path, default_path, target_path, 1.0, pineko.theory_card.path(theory_id)
)

# Load the opcard
myopcard = yaml.safe_load(target_path.read_text(encoding="utf-8"))

# I need smaller x and q grids in order to compute a small eko
small_x_grid = [1.0e-6, 1.0e-5, 1.0e-4, 1.0e-3, 1.0e-2, 1.0e-1, 1.0]
small_x_grid = np.geomspace(1e-3, 1.0, 5)
small_q2_grid = [100.0]
myopcard["xgrid"] = small_x_grid
myopcard["targetgrid"] = small_x_grid
Expand All @@ -59,7 +71,10 @@ def benchmark_dglap(tmp_path):
# upgrade cards layout
newtcard, newocard = eko.compatibility.update(tcard, myopcard)

_ = eko.run_dglap(theory_card=newtcard, operators_card=newocard)
# we are only interested in checking the configuration
# instatianting a runner is mostly sufficient
# TODO: speed up this step, and run a full run_dglap
_ = eko.runner.Runner(theory_card=newtcard, operators_card=newocard)


def benchmark_evolve_grid(tmp_path, lhapdf_path, test_files, test_pdf):
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/bench_theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pathlib

import pineko
import pineko.configs
import pineko.theory

theory_obj = pineko.theory.TheoryBuilder(208, ["LHCB_Z_13TEV_DIMUON"])
theory_obj_hera = pineko.theory.TheoryBuilder(208, ["HERACOMBCCEM"])
Expand Down
14 changes: 8 additions & 6 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import pytest

import pineko
import pineko.configs


@pytest.fixture
def test_configs(test_files):
config_path = pineko.configs.detect(test_files)
base_configs = pineko.configs.load(config_path)
return base_configs
def test_files():
return pathlib.Path(__file__).parents[0] / "data_files/"


@pytest.fixture
def test_files():
return pathlib.Path(__file__).parents[0] / "data_files/"
def test_configs(test_files):
config_path = pineko.configs.detect(test_files)
base_configs = pineko.configs.load(config_path)
pineko.configs.configs = pineko.configs.defaults(base_configs)
return pineko.configs.configs


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pineko = "pineko:command"
[tool.poe.tasks]
test = "pytest tests"
bench.cmd = "pytest benchmarks"
bench.env.NUMBA_DISABLE_JIT.default = "0"
bench.env.NUMBA_DISABLE_JIT.default = "1"
lint = "pylint src/**/*.py -E"
lint-warnings = "pylint src/**/*.py --exit-zero"
pineko = "pineko"
Expand Down
6 changes: 3 additions & 3 deletions src/pineko/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def write_operator_card(pineappl_grid, default_card, card_path, xif, tcard):
x_grid_int.append(1.0)
operators_card["interpolation_xgrid"] = list(x_grid_int)

def provide_if_missing(key, default):
if key not in operators_card:
operators_card[key] = default
def provide_if_missing(key, default, card=operators_card):
if key not in card:
card[key] = default

provide_if_missing("n_integration_cores", 1)
provide_if_missing("inputgrid", operators_card["interpolation_xgrid"])
Expand Down
26 changes: 23 additions & 3 deletions src/pineko/theory_card.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
"""Tools related to theory cards."""
import pathlib
from typing import Any, Dict

import yaml

from . import configs


def load(theory_id):
def path(theory_id: int) -> pathlib.Path:
"""Determine path to theory card.
Parameters
----------
theory_id : int
theory id
Returns
-------
pathlib.Path
theory card path
"""
return configs.configs["paths"]["theory_cards"] / f"{theory_id}.yaml"


def load(theory_id: int) -> Dict[str, Any]:
"""Load a theory card.
Parameters
Expand All @@ -16,9 +36,9 @@ def load(theory_id):
-------
theory_card : dict
theory card
"""
tcard_path = configs.configs["paths"]["theory_cards"] / f"{theory_id}.yaml"
with open(tcard_path, encoding="utf-8") as f:
with open(path(theory_id), encoding="utf-8") as f:
theory_card = yaml.safe_load(f)
return theory_card

Expand Down

0 comments on commit b5eb520

Please sign in to comment.