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

Refactor benchmark workflow #52

Merged
merged 27 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b97d999
Removed test_files
andreab1997 Oct 19, 2022
1401621
Update gitignore
andreab1997 Oct 19, 2022
2fcfd60
Remove cache and change poetry install
andreab1997 Oct 19, 2022
36a86ab
Separate script and remove lhapdf.conf
andreab1997 Oct 20, 2022
764aa67
Temporary test
andreab1997 Oct 20, 2022
027ff5e
Remove apt-get
andreab1997 Oct 20, 2022
40230d4
Move download script
andreab1997 Oct 20, 2022
b62cc00
Replace benchmark container
alecandido Oct 22, 2022
4f77f37
Standardize usage of github token
alecandido Oct 22, 2022
8ddaf53
Update EKO and pineappl dependencies
alecandido Oct 23, 2022
3778e1d
Update eko version to 0.11
andreab1997 Oct 24, 2022
8750279
Fix some compatibility problem
andreab1997 Oct 24, 2022
d763111
Update EKO to v0.11.1
alecandido Oct 24, 2022
4e59c1f
Fix check grid and eko compatible
andreab1997 Oct 24, 2022
51f6a9d
Fix coupling problem
andreab1997 Oct 24, 2022
e01e95e
Add None to argument of evolve_grid in convolute
andreab1997 Oct 24, 2022
9f736db
Fix convolute
andreab1997 Oct 25, 2022
428eef7
Add test for new info in operator card
andreab1997 Oct 26, 2022
9623bd3
Add test for eko computation
andreab1997 Oct 26, 2022
fb6a25c
Add compatibility layer to account for new EKO layout
alecandido Oct 26, 2022
5cce067
Convert xgrid objects to raw numpy arrays
alecandido Oct 26, 2022
2aac6cb
Fix wrong access for eko version, now an attribute
alecandido Oct 26, 2022
393a877
Update operator card to new format
alecandido Oct 26, 2022
6b4d63b
Start fixing missing thcard
alecandido Oct 27, 2022
d35fef7
Fix opcard subcommand
alecandido Oct 27, 2022
b5eb520
Fix bench evolve
alecandido Oct 27, 2022
1cd3c83
Propagate theory card requirement to TheoryBuilder
alecandido Oct 27, 2022
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
42 changes: 18 additions & 24 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,27 @@ jobs:
runs-on: ubuntu-latest

container:
image: ghcr.io/n3pdf/bench-evol:latest
image: ghcr.io/n3pdf/lhapdf:v2
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ github.token }}

steps:
- uses: actions/checkout@v2
with:
# tags needed for dynamic versioning
fetch-depth: 0
- name: Install and configure Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
# update path for this and the other steps
export PATH=$HOME/.local/bin:$PATH
echo "$HOME/.local/bin" >> $GITHUB_PATH
# prevent poetry environments
# in order to access container pre-installed packages
poetry config virtualenvs.create false
# log all configurations
poetry config --list
- name: Cache Poetry virtualenv
uses: actions/cache@v2
id: cache
uses: snok/install-poetry@v1
with:
path: ~/.virtualenvs
key: ${{ runner.os }}-py-${{ steps.setup-python.outputs.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Install version management tool
run: |
# same poetry env
PIP="$(head -n1 $(which poetry) | cut -c 3-) -m pip"
${PIP} install poetry-dynamic-versioning
virtualenvs-create: false
installer-parallel: true
- name: Install dependencies
run: poetry install --no-interaction --no-root --with test ${{ inputs.poetry-extras }}
if: steps.cache.outputs.cache-hit != 'true'
- name: Install project
run: poetry install --no-interaction
# it is required to repeat extras, otherwise they will be removed from
# the environment
run: poetry install --no-interaction ${{ inputs.poetry-extras }}
- name: Install task runner
run: pip install poethepoet
- name: Lint with pylint
Expand All @@ -53,6 +37,16 @@ jobs:
poe lint
# For warnings instead return always zero
poe lint-warnings
- name: Get data files
id: cache-data-files
uses: actions/cache@v3
with:
path: data_files
key: data_files-v2
- name: Download data files
if: steps.cache-data_files.outputs.cache-hit != 'true'
run: |
sh download_test_data.sh
- name: Test with pytest
run: |
poe bench
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ dmypy.json

# Pyre type checker
.pyre/

# Benchmark files
benchmarks/data_files
benchmarks/fakepdfs
6 changes: 4 additions & 2 deletions benchmarks/bench_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ def benchmark_check_grid_and_eko_compatible(test_files):
wrong_grid = pineappl.grid.Grid.read(
test_files / "data/grids/208/NUTEV_CC_NU_FE_SIGMARED.pineappl.lz4"
)
ekoop = eko.output.Output.load_tar(
ekoop = eko.output.legacy.load_tar(
test_files / "data/ekos/208/HERA_CC_318GEV_EM_SIGMARED.tar"
)
with pytest.raises(ValueError):
pineko.check.check_grid_and_eko_compatible(wrong_grid, ekoop, 1.0)
pineko.check.check_grid_and_eko_compatible(grid, ekoop, 1.0)
ekoop.xgrid_reshape(targetgrid=[0.0001, 0.001, 0.1, 0.5, 1.0])
eko.output.manipulate.xgrid_reshape(
ekoop, targetgrid=eko.interpolation.XGrid([0.0001, 0.001, 0.1, 0.5, 1.0])
)
with pytest.raises(ValueError):
pineko.check.check_grid_and_eko_compatible(grid, ekoop, 1.0)
11 changes: 9 additions & 2 deletions benchmarks/bench_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pathlib

import pytest
from click.testing import CliRunner

from pineko.cli._base import command
Expand Down Expand Up @@ -59,10 +58,18 @@ def benchmark_opcard_cli(tmp_path, test_files):
test_files / "data/grids/208/LHCB_DY_13TEV_DIMUON.pineappl.lz4"
)
default_card_path = pathlib.Path(test_files / "data/operator_cards/_template.yaml")
thcard_path = pathlib.Path(test_files / "data" / "theory_cards" / "208.yaml")
target_path = pathlib.Path(tmp_path / "test_ope_card.yaml")
runner = CliRunner()
result = runner.invoke(
command, ["opcard", str(grid_path), str(default_card_path), str(target_path)]
command,
[
"opcard",
str(grid_path),
str(default_card_path),
str(thcard_path),
str(target_path),
],
)
assert "Success" in result.output

Expand Down
71 changes: 65 additions & 6 deletions benchmarks/bench_evolve.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,102 @@
import pathlib

import eko
import eko.compatibility
import eko.output.legacy
import numpy as np
import pineappl
import pytest
import yaml
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")
x_grid, q2_grid = pineko.evolve.write_operator_card_from_file(
pine_path, default_path, target_path, 1.0

# Load the theory card
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_path
)

# Load the operator card
myopcard = yaml.safe_load(target_path.read_text(encoding="utf-8"))
# Check if it contains all the information for eko
assert np.allclose(myopcard["rotations"]["xgrid"], x_grid)
assert np.allclose(myopcard["rotations"]["targetgrid"], x_grid)
assert np.allclose(myopcard["rotations"]["inputgrid"], x_grid)
assert np.allclose(myopcard["rotations"]["inputpids"], pineko.evolve.DEFAULT_PIDS)
assert np.allclose(myopcard["rotations"]["targetpids"], pineko.evolve.DEFAULT_PIDS)

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
_ = pineko.evolve.write_operator_card_from_file(
wrong_pine_path, default_path, target_path, 1.0, tcard_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 = 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 = np.geomspace(1e-3, 1.0, 5)
small_q2_grid = [100.0]
myopcard["xgrid"] = small_x_grid
myopcard["targetgrid"] = small_x_grid
myopcard["inputgrid"] = small_x_grid
myopcard["Q2grid"] = small_q2_grid

# upgrade cards layout
newtcard, newocard = eko.compatibility.update(tcard, myopcard)

# 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):
pine_path = test_files / "data/grids/208/HERA_CC_318GEV_EM_SIGMARED.pineappl.lz4"
pinegrid = pineappl.grid.Grid.read(pine_path)
eko_path = test_files / "data/ekos/208/HERA_CC_318GEV_EM_SIGMARED.tar"
eko_op = eko.output.Output.load_tar(eko_path)
eko_op = eko.output.legacy.load_tar(eko_path)
target_path = pathlib.Path(tmp_path / "test_fktable.pineappl.lz4")
max_as = 1
max_al = 0
base_configs = pineko.configs.load(test_files)
pineko.configs.configs = pineko.configs.defaults(base_configs)
tcard = pineko.theory_card.load(208)
new_tcard = eko.compatibility.update_theory(tcard)
astrong = sc.Couplings.from_dict(new_tcard)
assumptions = pineko.theory_card.construct_assumptions(tcard)
with lhapdf_path(test_pdf):
pineko.evolve.evolve_grid(
pinegrid,
eko_op,
target_path,
astrong,
max_as,
max_al,
1.0,
Expand Down
23 changes: 18 additions & 5 deletions benchmarks/bench_theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import pathlib

import pineko
import pineko.configs
import pineko.theory
import pineko.theory_card

theory_obj = pineko.theory.TheoryBuilder(208, ["LHCB_Z_13TEV_DIMUON"])
theory_obj_hera = pineko.theory.TheoryBuilder(208, ["HERACOMBCCEM"])
Expand Down Expand Up @@ -71,12 +74,15 @@ def benchmark_inherit_ekos(test_files):
folder_path.rmdir()


def benchmark_opcard(test_files):
def benchmark_opcard(test_files, test_configs):
th_path = pineko.theory_card.path(208)

grid_name = "LHCB_DY_13TEV_DIMUON"
theory_obj.opcard(
grid_name,
pathlib.Path(test_files / "data/grids/208/LHCB_DY_13TEV_DIMUON.pineappl.lz4"),
1.0,
th_path,
)
op_path = pathlib.Path(
test_files / theory_obj.operator_cards_path / "LHCB_DY_13TEV_DIMUON.yaml"
Expand All @@ -85,14 +91,17 @@ def benchmark_opcard(test_files):
grid_name,
pathlib.Path(test_files / "data/grids/208/LHCB_DY_13TEV_DIMUON.pineappl.lz4"),
1.0,
th_path,
)
if os.path.exists(op_path):
os.remove(op_path)
else:
raise ValueError("operator card not found")


def benchmark_eko(test_files):
def benchmark_eko(test_files, test_configs):
th_path = pineko.theory_card.path(208)

grid_name = "LHCB_DY_13TEV_DIMUON"
grid_path = pathlib.Path(theory_obj.grids_path() / (grid_name + ".pineappl.lz4"))
base_configs = pineko.configs.load(test_files)
Expand All @@ -103,7 +112,7 @@ def benchmark_eko(test_files):
"208-LHCB_DY_13TEV_DIMUON.log",
["208-LHCB_DY_13TEV_DIMUON.log"],
)
theory_obj.opcard(grid_name, pathlib.Path(test_files / grid_path), 1.0)
theory_obj.opcard(grid_name, pathlib.Path(test_files / grid_path), 1.0, th_path)

theory_obj.eko(grid_name, grid_path, tcard)

Expand Down Expand Up @@ -135,7 +144,9 @@ def benchmark_activate_logging(test_files):
raise ValueError("log file not found")


def benchmark_fk(test_files):
def benchmark_fk(test_files, test_configs):
th_path = pineko.theory_card.path(208)

grid_name = "HERA_CC_318GEV_EM_SIGMARED"
grid_path = pathlib.Path(
theory_obj_hera.grids_path() / (grid_name + ".pineappl.lz4")
Expand All @@ -148,7 +159,9 @@ def benchmark_fk(test_files):
"208-HERA_CC_318GEV_EM_SIGMARED.log",
["208-HERA_CC_318GEV_EM_SIGMARED.log"],
)
theory_obj_hera.opcard(grid_name, pathlib.Path(test_files / grid_path), 1.0)
theory_obj_hera.opcard(
grid_name, pathlib.Path(test_files / grid_path), 1.0, th_path
)

theory_obj_hera.fk(grid_name, grid_path, tcard, pdf=None)
# test overwrite function
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
31 changes: 0 additions & 31 deletions benchmarks/fakepdfs/NNPDF40_nlo_as_01180/NNPDF40_nlo_as_01180.info

This file was deleted.

Loading