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

Support reading v0.13 and v0.14 files #417

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2,391 changes: 1,281 additions & 1,110 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ scipy = "^1.10.1"
PyYAML = "^6.0"
lz4 = "^4.0.2"
numba = "^0.59.0"
packaging = "^24.1"
# ekomark
banana-hep = { version = "^0.6.12", optional = true }
sqlalchemy = { version = "^1.4.21", optional = true }
Expand Down
3 changes: 3 additions & 0 deletions src/eko/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Evolution Kernel Operators."""

from . import io, version
from .io.runcards import OperatorCard, TheoryCard
from .io.struct import EKO
from .runner import solve

__version__ = version.__version__

__all__ = [
"io",
"OperatorCard",
"TheoryCard",
"EKO",
"solve",
]
199 changes: 0 additions & 199 deletions src/eko/io/legacy.py

This file was deleted.

20 changes: 15 additions & 5 deletions src/eko/io/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from typing import Optional

import yaml
from packaging.version import parse

from .. import version as vmod
from ..interpolation import XGrid
from . import v1, v2
from .dictlike import DictLike
from .paths import InternalPaths
from .types import EvolutionPoint as EPoint
Expand Down Expand Up @@ -55,13 +57,21 @@ def load(cls, path: os.PathLike):

Returns
-------
bool
Metadata
loaded metadata
"""
path = pathlib.Path(path)
content = cls.from_dict(
yaml.safe_load(InternalPaths(path).metadata.read_text(encoding="utf-8"))
)
paths = InternalPaths(path)
# read raw file first to catch version
raw = yaml.safe_load(paths.metadata.read_text(encoding="utf-8"))
version = parse(raw["version"])
# patch if necessary
if version.major == 0 and version.minor == 13:
raw = v1.update_metadata(paths, raw)
elif version.major == 0 and version.minor == 14:
raw = v2.update_metadata(paths, raw)
# now we are ready
content = cls.from_dict(raw)
content._path = path
return content

Expand All @@ -70,7 +80,7 @@ def update(self):
if self._path is None:
logger.info("Impossible to set metadata, no file attached.")
else:
with open(InternalPaths(self._path).metadata, "w") as fd:
with open(InternalPaths(self._path).metadata, "w", encoding="utf8") as fd:
yaml.safe_dump(self.raw, fd)

@property
Expand Down
25 changes: 25 additions & 0 deletions src/eko/io/v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Legacy interface to files created with v0.13.

Although the data version v1 was already before v0.13 we only support
that API version.
"""

from .paths import InternalPaths


def update_metadata(paths: InternalPaths, raw: dict) -> dict:
"""Modify the raw metadata to the new format.

Parameters
----------
paths:
base paths to the EKO
raw:
raw yaml content

Returns
-------
dict
compatible raw yaml content
"""
return raw
26 changes: 26 additions & 0 deletions src/eko/io/v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Legacy interface to files created with v0.14.

Although the data version v2 was never assigned to v0.14 we use it for
exactly that API version.
"""

from .paths import InternalPaths


def update_metadata(paths: InternalPaths, raw: dict) -> dict:
"""Modify the raw metadata to the new format.

Parameters
----------
paths:
base paths to the EKO
raw:
raw yaml content

Returns
-------
dict
compatible raw yaml content
"""
raw["data_version"] = 2
return raw
37 changes: 2 additions & 35 deletions src/eko/runner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
"""Manage steps to DGLAP solution, and operator creation."""

from pathlib import Path
from typing import Union

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


# 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],
path: Path,
):
r"""Solve DGLAP equations in terms of evolution kernel operators (EKO).

The EKO :math:`\mathbf E_{k,j}(a_s^1\leftarrow a_s^0)` is determined in order
to fullfill the following evolution

.. math::
\mathbf f(x_k,a_s^1) = \mathbf E_{k,j}(a_s^1\leftarrow a_s^0) \mathbf f(x_j,a_s^0)

The configuration is split between the theory settings, representing
Standard Model parameters and other defining features of the theory
calculation, and the operator settings, those that are more closely related
to the solution of the |DGLAP| equation itself, and determine the resulting
operator features.
from .managed import solve

Note
----
For further information about EKO inputs and output see :doc:`/code/IO`
"""
# TODO: drop this
legacy.Runner(theory_card, operators_card, path).compute()
__all__ = ["OperatorCard", "TheoryCard", "solve"]
Loading
Loading