Skip to content

Commit

Permalink
Merge pull request #2226 from NNPDF/update_ruamel
Browse files Browse the repository at this point in the history
unpin ruamel.yaml version
  • Loading branch information
RoyStegeman authored Dec 4, 2024
2 parents 3298b56 + 2e4096d commit 08e9384
Show file tree
Hide file tree
Showing 41 changed files with 264 additions and 320 deletions.
2 changes: 1 addition & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ requirements:
- joblib
- sphinx_rtd_theme >0.5
- sphinxcontrib-bibtex
- ruamel.yaml <0.18
- ruamel.yaml >=0.15

test:
requires:
Expand Down
4 changes: 2 additions & 2 deletions extra_tests/regression_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest

from n3fit.tests.test_fit import EXE, check_fit_results
from reportengine.compat import yaml
from validphys.utils import yaml_safe

REGRESSION_FOLDER = pathlib.Path(__file__).with_name("regression_fits")

Expand Down Expand Up @@ -37,7 +37,7 @@ def test_regression_fit(tmp_path, runcard, replica, regenerate):
runcard_file = REGRESSION_FOLDER / runcard_name
shutil.copy(runcard_file, tmp_path)

runcard_info = yaml.load(runcard_file.read_text())
runcard_info = yaml_safe.load(runcard_file.read_text())
if (wname := runcard_info.get("load")) is not None:
shutil.copy(REGRESSION_FOLDER / wname, tmp_path)

Expand Down
4 changes: 2 additions & 2 deletions n3fit/src/evolven3fit/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import eko
from eko import basis_rotation, runner
from reportengine.compat import yaml
from validphys.utils import yaml_safe

from . import eko_utils, utils

Expand Down Expand Up @@ -164,7 +164,7 @@ def load_fit(usr_path):
nnfitpath = usr_path / "nnfit"
pdf_dict = {}
for yaml_file in nnfitpath.glob(f"replica_*/{usr_path.name}.exportgrid"):
data = yaml.safe_load(yaml_file.read_text(encoding="UTF-8"))
data = yaml_safe.load(yaml_file.read_text(encoding="UTF-8"))
pdf_dict[yaml_file.parent.stem] = data
return pdf_dict

Expand Down
8 changes: 3 additions & 5 deletions n3fit/src/evolven3fit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np
from scipy.interpolate import interp1d

from reportengine.compat import yaml
from validphys.pdfbases import PIDS_DICT
from validphys.utils import yaml_safe

from .q2grids import Q2GRID_DEFAULT, Q2GRID_NNPDF40

Expand Down Expand Up @@ -57,7 +57,7 @@ def hasFlavor(self, pid):

def read_runcard(usr_path):
"""Read the runcard and return the relevant information for evolven3fit"""
return yaml.safe_load((usr_path / "filter.yml").read_text(encoding="UTF-8"))
return yaml_safe.load((usr_path / "filter.yml").read_text(encoding="UTF-8"))


def get_theoryID_from_runcard(usr_path):
Expand Down Expand Up @@ -99,9 +99,7 @@ def generate_q2grid(Q0, Qfin, Q_points, match_dict, nf0=None, legacy40=False):
frac_of_point = np.log(match_scale / Q_ini) / np.log(Qfin / Q0)
num_points = int(Q_points * frac_of_point)
num_points_list.append(num_points)
grids.append(
np.geomspace(Q_ini**2, match_scale**2, num=num_points, endpoint=False)
)
grids.append(np.geomspace(Q_ini**2, match_scale**2, num=num_points, endpoint=False))
Q_ini = match_scale
num_points = Q_points - sum(num_points_list)
grids.append(np.geomspace(Q_ini**2, Qfin**2, num=num_points))
Expand Down
4 changes: 2 additions & 2 deletions n3fit/src/n3fit/io/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import n3fit
from n3fit import vpinterface
from reportengine.compat import yaml
import validphys
from validphys.utils import yaml_safe

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -622,4 +622,4 @@ def storefit(pdf_object, replica, out_path, theory):
}

with open(out_path, "w") as fs:
yaml.dump(data, fs)
yaml_safe.dump(data, fs)
16 changes: 5 additions & 11 deletions n3fit/src/n3fit/scripts/n3fit_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import re
import shutil
import sys
import warnings

from ruamel.yaml import error

from reportengine import colors
from reportengine.compat import yaml
from reportengine.namespaces import NSList
from validphys.app import App
from validphys.config import Config, ConfigError, Environment, EnvironmentError_
from validphys.core import FitSpec
from validphys.utils import yaml_safe

N3FIT_FIXED_CONFIG = dict(use_cuts='internal', use_t0=True, actions_=[])

Expand Down Expand Up @@ -108,15 +109,8 @@ class N3FitConfig(Config):
@classmethod
def from_yaml(cls, o, *args, **kwargs):
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore", yaml.error.MantissaNoDotYAML1_1Warning)
# We need to specify the older version 1.1 to support the
# older configuration files, which liked to use on/off for
# booleans.
# The floating point parsing yields warnings everywhere, which
# we suppress.
file_content = yaml.safe_load(o, version="1.1")
except yaml.error.YAMLError as e:
file_content = yaml_safe.load(o)
except error.YAMLError as e:
raise ConfigError(f"Failed to parse yaml file: {e}")
if not isinstance(file_content, dict):
raise ConfigError(
Expand Down
16 changes: 5 additions & 11 deletions n3fit/src/n3fit/scripts/vp_setupfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
import re
import shutil
import sys
import warnings

from ruamel.yaml import error

from reportengine import colors
from reportengine.compat import yaml
from validphys.app import App
from validphys.config import Config, ConfigError, Environment, EnvironmentError_
from validphys.utils import yaml_safe

SETUPFIT_FIXED_CONFIG = dict(
actions_=[
Expand Down Expand Up @@ -131,15 +132,8 @@ class SetupFitConfig(Config):
@classmethod
def from_yaml(cls, o, *args, **kwargs):
try:
with warnings.catch_warnings():
warnings.simplefilter('ignore', yaml.error.MantissaNoDotYAML1_1Warning)
# We need to specify the older version 1.1 to support the
# older configuration files, which liked to use on/off for
# booleans.
# The floating point parsing yields warnings everywhere, which
# we suppress.
file_content = yaml.safe_load(o, version='1.1')
except yaml.error.YAMLError as e:
file_content = yaml_safe.load(o)
except error.YAMLError as e:
raise ConfigError(f"Failed to parse yaml file: {e}")
if not isinstance(file_content, dict):
raise ConfigError(
Expand Down
4 changes: 2 additions & 2 deletions n3fit/src/n3fit/tests/test_evolven3fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import pytest

from eko import EKO, runner
from reportengine.compat import yaml
from validphys.api import API
from validphys.pdfbases import PIDS_DICT
from validphys.utils import yaml_safe

REGRESSION_FOLDER = pathlib.Path(__file__).with_name("regressions")
log = logging.getLogger(__name__)
Expand All @@ -24,7 +24,7 @@ def assert_sorted(arr, title):

def check_lhapdf_info(info_path):
"""Check the LHAPDF info file is correct"""
info = yaml.load(info_path.open("r", encoding="utf-8"))
info = yaml_safe.load(info_path.open("r", encoding="utf-8"))

alphas_qs = info["AlphaS_Qs"]
alphas = info["AlphaS_Vals"]
Expand Down
4 changes: 2 additions & 2 deletions n3fit/src/n3fit/tests/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import pytest

import n3fit
from reportengine.compat import yaml
from validphys.n3fit_data import replica_mcseed, replica_nnseed, replica_trvlseed
from validphys.utils import yaml_safe

log = logging.getLogger(__name__)
REGRESSION_FOLDER = pathlib.Path(__file__).with_name("regressions")
Expand All @@ -45,7 +45,7 @@ def _load_json(info_file):

def _load_exportgrid(exportgrid_file):
"""Loads the exportgrid file"""
return yaml.safe_load(exportgrid_file.read_text())
return yaml_safe.load(exportgrid_file.read_text())


def test_initialize_seeds():
Expand Down
7 changes: 3 additions & 4 deletions nnpdf_data/nnpdf_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from functools import lru_cache
import pathlib

import ruamel.yaml as yaml

from ._version import __version__
import yaml

path_vpdata = pathlib.Path(__file__).parent
path_commondata = path_vpdata / "commondata"
Expand All @@ -12,7 +10,8 @@
_path_legacy_mapping = path_commondata / "dataset_names.yml"
theory_cards = path_vpdata / "theory_cards"

_legacy_to_new_mapping_raw = yaml.YAML().load(_path_legacy_mapping)
with open(_path_legacy_mapping) as file:
_legacy_to_new_mapping_raw = yaml.load(file, yaml.Loader)
# Convert strings into a dictionary
legacy_to_new_mapping = {
k: ({"dataset": v} if isinstance(v, str) else v) for k, v in _legacy_to_new_mapping_raw.items()
Expand Down
3 changes: 0 additions & 3 deletions nnpdf_data/nnpdf_data/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
"""

import dataclasses
from functools import lru_cache
import logging
from typing import Literal, Optional

from .utils import parse_yaml_inp

DEPRECATED_KEYS = ["MaxNfAs", "SxRes", "SxOrd" "EScaleVar", "Qedref", "global_nx"]

log = logging.getLogger(__name__)
Expand Down
10 changes: 6 additions & 4 deletions nnpdf_data/nnpdf_data/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pathlib

import ruamel.yaml as yaml
from ruamel.yaml import YAML
from validobj import ValidationError, parse_input
import yaml

yaml_rt = YAML(typ="rt")
try:
Loader = yaml.CLoader
except AttributeError:
Expand All @@ -22,14 +24,14 @@ def parse_yaml_inp(input_yaml, spec):
return parse_input(inp, spec)
except ValidationError as e:
current_exc = e
# In order to provide a more complete error information, use round_trip_load
# In order to provide a more complete error information, use round trip
# to read the .yaml file again (insetad of using the CLoader)
current_inp = yaml.round_trip_load(input_yaml.open("r", encoding="utf-8"))
current_inp = yaml_rt.load(input_yaml.open("r", encoding="utf-8"))
error_text_lines = []
while current_exc:
if hasattr(current_exc, 'wrong_field'):
wrong_field = current_exc.wrong_field
# Mappings compping from ``round_trip_load`` have an
# Mappings compping from yaml_rt have an
# ``lc`` attribute that gives a tuple of
# ``(line_number, column)`` for a given item in
# the mapping.
Expand Down
2 changes: 1 addition & 1 deletion nnpdf_data/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include = [

[tool.poetry.dependencies]
python = "^3.9"
"ruamel.yaml" = "<0.18"
"ruamel.yaml" = "*"
# Required to run filters: `filter_files_dependencies`
pandas = {version = "*", optional = true}
numpy = {version = "*", optional = true}
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ matplotlib = "^3.9"
pineappl = "^0.8.2"
pandas = "*"
numpy = "*"
"ruamel.yaml" = "*"
validobj = "*"
prompt_toolkit = "*"
# Reportengine needs to be installed from git
Expand Down
Loading

0 comments on commit 08e9384

Please sign in to comment.