Skip to content

Commit

Permalink
Replace the old runner in solve
Browse files Browse the repository at this point in the history
With the not yet implemented one
  • Loading branch information
alecandido committed Mar 31, 2023
1 parent e73481d commit 5058333
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
23 changes: 12 additions & 11 deletions src/eko/runner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""Manage steps to DGLAP solution, and operator creation."""
import os
from pathlib import Path
from typing import Union

from ..io import runcards
from ..io.runcards import OperatorCard, TheoryCard
from ..io.types import RawCard
from . import legacy
from . import managed


# TODO: drop this altogether, replacing just with managed.solve
# it is currently kept not to break the interface, but the runcards upgrade and
# path conversion should be done by the caller, here we just clearly declare
# which types we expect
def solve(
theory_card: Union[RawCard, TheoryCard],
operators_card: Union[RawCard, OperatorCard],
Expand All @@ -26,18 +32,13 @@ def solve(
to the solution of the |DGLAP| equation itself, and determine the resulting
operator features.
Parameters
----------
theory_card :
theory parameters and related settings
operator_card :
solution configurations, and further EKO options
path :
path where to store the computed operator
Note
----
For further information about EKO inputs and output see :doc:`/code/IO`
"""
legacy.Runner(theory_card, operators_card, path).compute()
# TODO: drop this
# legacy.Runner(theory_card, operators_card, path).compute()

new_theory, new_operator = runcards.update(theory_card, operators_card)
managed.solve(new_theory, new_operator, Path(path))
29 changes: 29 additions & 0 deletions src/eko/runner/managed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Fully managed runner.
This is an automated runner, mainly suggested for small EKOs computations.
The primitives used here to compute the various pieces are part of the public
interface, and should be directly used to manage a more complex run for a
considebaly large operator.
Thus, parallelization and multi-node execution is possible using EKO primitives,
but not automatically performed.
"""

from pathlib import Path

from ..io.runcards import OperatorCard, TheoryCard
from ..io.struct import EKO
from . import recipes


def solve(theory: TheoryCard, operator: OperatorCard, path: Path):
"""Solve DGLAP equations in terms of evolution kernel operators (EKO)."""
with EKO.create(path) as builder:
eko = builder.load_cards(theory, operator).build()

recipes.create(eko)

# for recipe in eko.recipes:
# pass
17 changes: 2 additions & 15 deletions src/eko/runner/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

from .. import EKO
from .. import scale_variations as sv
from ..io import runcards
from ..io.dictlike import DictLike
from ..io.types import SquaredScale
from ..thresholds import ThresholdsAtlas
from . import commons


@dataclass
Expand Down Expand Up @@ -35,19 +34,7 @@ class MatchingRecipe(Recipe):

def create(eko: EKO):
"""Create all associated recipes."""
_ = eko.theory_card.matching

masses = runcards.masses(
eko.theory_card, eko.operator_card.configs.evolution_method
)

tc = ThresholdsAtlas(
masses=masses,
q2_ref=eko.operator_card.mu20,
nf_ref=eko.theory_card.num_flavs_init,
thresholds_ratios=None,
max_nf=eko.theory_card.num_flavs_max_pdf,
)
tc = commons.threshold_atlas(eko.theory_card, eko.operator_card)

for mu2 in eko.mu2grid:
expanded = eko.operator_card.configs.scvar_method is sv.Modes.expanded
Expand Down
6 changes: 5 additions & 1 deletion tests/eko/runner/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ def compute(self):
self.path.write_text("output", encoding="utf-8")


def mock_solve(th, op, path):
return MockRunner(th, op, path).compute()


def test_run(monkeypatch, tmp_path: pathlib.Path):
# just test, that it is a shortcut to 'compute'
path = tmp_path / "eko.tar"
monkeypatch.setattr(eko.runner.legacy, "Runner", MockRunner)
monkeypatch.setattr(eko, "solve", mock_solve)
eko.solve({}, {}, path=path)
out = path.read_text(encoding="utf-8")
assert out == "output"

0 comments on commit 5058333

Please sign in to comment.