Skip to content

Commit

Permalink
add compatibility layer for theory and operator cards
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomomagni committed Nov 12, 2024
1 parent 2b1fa1e commit b55fb05
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/eko/io/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import yaml

from .. import interpolation
from . import exceptions, raw
from . import exceptions, raw, v1
from .access import AccessConfigs
from .inventory import Inventory
from .items import Evolution, Matching, Operator, Recipe, Target
Expand Down Expand Up @@ -132,16 +132,20 @@ def evolgrid(self) -> List[EPoint]:
@property
def theory_card(self):
"""Provide theory card, retrieving from the dump."""
return TheoryCard.from_dict(
yaml.safe_load(self.paths.theory_card.read_text(encoding="utf-8"))
)
raw_th = yaml.safe_load(self.paths.theory_card.read_text(encoding="utf-8"))
if self.metadata.data_version in [1, 2]:
raw_th = v1.update_theory(raw_th)
return TheoryCard.from_dict(raw_th)

@property
def operator_card(self):
"""Provide operator card, retrieving from the dump."""
return OperatorCard.from_dict(
yaml.safe_load(self.paths.operator_card.read_text(encoding="utf-8"))
)
raw_op = yaml.safe_load(self.paths.operator_card.read_text(encoding="utf-8"))
if self.metadata.data_version in [1, 2]:
# here we need to read also the theory card
raw_th = yaml.safe_load(self.paths.theory_card.read_text(encoding="utf-8"))
raw_op = v1.update_operator(raw_op, raw_th)
return OperatorCard.from_dict(raw_op)

# persistency control
# -------------------
Expand Down
50 changes: 49 additions & 1 deletion src/eko/io/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .paths import InternalPaths


def update_metadata(paths: InternalPaths, raw: dict) -> dict:
def update_metadata(_paths: InternalPaths, raw: dict) -> dict:
"""Modify the raw metadata to the new format.
Parameters
Expand All @@ -22,4 +22,52 @@ def update_metadata(paths: InternalPaths, raw: dict) -> dict:
dict
compatible raw yaml content
"""
raw["data_version"] = 1
raw["xgrid"] = raw["bases"]["xgrid"]
del raw["bases"]
return raw


def update_theory(raw: dict) -> dict:
"""Modify the raw theory card to the new format.
Parameters
----------
raw:
raw yaml content
Returns
-------
dict
compatible raw yaml content
"""
raw["couplings"]["ref"] = (
raw["couplings"]["scale"],
raw["couplings"]["num_flavs_ref"],
)
# adjust couplings
for key in ["num_flavs_ref", "max_num_flavs", "scale"]:
del raw["couplings"][key]
# adjust heavy
for key in ["intrinsic_flavors", "num_flavs_init", "num_flavs_max_pdf"]:
del raw["heavy"][key]
return raw


def update_operator(raw_op: dict, raw_th) -> dict:
"""Modify the raw operator card to the new format.
Parameters
----------
raw_op:
raw operator yaml content
raw_th:
raw theory yaml content
Returns
-------
dict
compatible raw yaml content
"""
raw_op["init"] = (raw_op["mu0"], raw_th["heavy"]["num_flavs_init"])
del raw_op["mu0"]
return raw_op

0 comments on commit b55fb05

Please sign in to comment.