diff --git a/src/pineko/evolve.py b/src/pineko/evolve.py index 79b6cca0..f259f65a 100644 --- a/src/pineko/evolve.py +++ b/src/pineko/evolve.py @@ -22,7 +22,7 @@ from eko.matchings import Atlas, nf_default from eko.quantities import heavy_quarks -from . import check, comparator, version +from . import check, comparator, version, template logger = logging.getLogger(__name__) @@ -76,7 +76,6 @@ def get_convolution_suffix(convolution: pineappl.convolutions.Conv) -> str: def write_operator_card_from_file( pineappl_path: os.PathLike, - default_card_path: os.PathLike, card_path: os.PathLike, tcard: dict, ): @@ -86,8 +85,6 @@ def write_operator_card_from_file( ---------- pineappl_path : str or os.PathLike path to grid to evolve - default_card : str or os.PathLike - base operator card card_path : str or os.PathLike target path tcard: dict @@ -106,12 +103,7 @@ def write_operator_card_from_file( raise FileNotFoundError(pineappl_path) pineappl_grid = pineappl.grid.Grid.read(pineappl_path) pineappl_grid.optimize() - default_card = yaml.safe_load( - pathlib.Path(default_card_path).read_text(encoding="utf-8") - ) - - return write_operator_card(pineappl_grid, default_card, card_path, tcard) - + return write_operator_card(pineappl_grid, card_path, tcard) def dump_card( card_path: Union[str, os.PathLike], @@ -148,7 +140,6 @@ def dump_card( def write_operator_card( pineappl_grid: pineappl.grid.Grid, - default_card: dict, card_path: Union[str, os.PathLike], tcard: dict, ): @@ -158,8 +149,6 @@ def write_operator_card( ---------- pineappl_grid : pineappl.grid.Grid grid to evolve - default_card : dict - base operator card card_path : str or os.PathLike target path tcard: dict @@ -186,18 +175,19 @@ def write_operator_card( # ... to get the x and muF grids for the eko evol_info = pineappl_grid.evolve_info(order_mask) muf2_grid = evol_info.fac1 - operators_card = copy.deepcopy(default_card) + operators_card = {} + operators_card["configs"] = {} sv_method = sv_scheme(tcard) xif = 1.0 if sv_method is not None else tcard["XIF"] # update scale variation method - operators_card["configs"]["scvar_method"] = sv_method + operators_card["configs"]["scvar_method"] = sv_scheme(tcard) operators_card["init"] = (tcard["Q0"], tcard["nf0"]) - if default_card.get("init") is not None and default_card["init"] != [ + if template.CONSTANTS["init"] is not None and template.CONSTANTS["init"] != ( tcard["Q0"], tcard["nf0"], - ]: - raise ValueError("Template declares a value of Q0, nf0 different from theory") + ): + raise ValueError("Q0, nf0 from theory different than default") q2_grid = (xif * xif * muf2_grid).tolist() masses = np.array([tcard["mc"], tcard["mb"], tcard["mt"]]) ** 2 @@ -221,6 +211,8 @@ def write_operator_card( x_grid = np.append(x_grid, 1.0) operators_card["configs"]["interpolation_polynomial_degree"] = 1 operators_card["xgrid"] = x_grid.tolist() + else: + operators_card["xgrid"] = template.xgrid # Add the version of eko and pineko to the operator card # using importlib.metadata.version to get the correct tag in editable mode @@ -242,17 +234,17 @@ def write_operator_card( ) # If the evolution method is defined in the template and it is different, fail - template_method = default_card["configs"].get("evolution_method") + template_method = template.CONSTANTS["configs"]["evolution_method"] if ( template_method is not None and template_method != opconf["evolution_method"] ): raise ValueError( - f"The template and the theory have different evolution method ({template_method} vs {opconf['key']})" + f"Your theory has a different evolution method than the default({template_method} vs {opconf['key']})" ) # If the change is on the number of iterations, take the template value but warn the user - template_iter = default_card["configs"].get("ev_op_iterations") + template_iter = template.CONSTANTS["configs"]["ev_op_iterations"] if template_iter is not None and template_method != opconf["ev_op_iterations"]: opconf["ev_op_iterations"] = template_iter logger.warning( diff --git a/src/pineko/template.py b/src/pineko/template.py new file mode 100644 index 00000000..dc6ed952 --- /dev/null +++ b/src/pineko/template.py @@ -0,0 +1,71 @@ +"""Default settings and interpolation xgrid (previously in _template.yaml).""" +import yaml +from eko.interpolation import XGrid + +# Define the interpolation x-grid as previously defined as 'xgrid' in _template.yaml +xgrid = ( + [1.9999999999999954e-07, + 3.034304765867952e-07, + 4.6035014748963906e-07, + 6.984208530700364e-07, + 1.0596094959101024e-06, + 1.607585498470808e-06, + 2.438943292891682e-06, + 3.7002272069854957e-06, + 5.613757716930151e-06, + 8.516806677573355e-06, + 1.292101569074731e-05, + 1.9602505002391748e-05, + 2.97384953722449e-05, + 4.511438394964044e-05, + 6.843744918967896e-05, + 0.00010381172986576898, + 0.00015745605600841445, + 0.00023878782918561914, + 0.00036205449638139736, + 0.0005487795323670796, + 0.0008314068836488144, + 0.0012586797144272762, + 0.0019034634022867384, + 0.0028738675812817515, + 0.004328500638820811, + 0.006496206194633799, + 0.009699159574043398, + 0.014375068581090129, + 0.02108918668378717, + 0.030521584007828916, + 0.04341491741702269, + 0.060480028754447364, + 0.08228122126204893, + 0.10914375746330703, + 0.14112080644440345, + 0.17802566042569432, + 0.2195041265003886, + 0.2651137041582823, + 0.31438740076927585, + 0.3668753186482242, + 0.4221667753589648, + 0.4798989029610255, + 0.5397572337880445, + 0.601472197967335, + 0.6648139482473823, + 0.7295868442414312, + 0.7956242522922756, + 0.8627839323906108, + 0.9309440808717544, + 1] + ) + +CONSTANTS = { + "configs": { + "ev_op_iterations": 1, + "evolution_method": "iterate-exact", + "inversion_method": "expanded", + "polarized": False, + "scvar_method": "null", + "time_like": False + }, + "init": (1.65, 4), + "eko_version": "0.14.2", +} + diff --git a/src/pineko/theory.py b/src/pineko/theory.py index 0bf87a21..58d52e2c 100644 --- a/src/pineko/theory.py +++ b/src/pineko/theory.py @@ -273,8 +273,6 @@ def opcard(self, name, grid, tcard): return _x_grid, q2_grid = evolve.write_operator_card_from_file( grid, - self.operator_cards_path - / configs.configs["paths"]["operator_card_template_name"], opcard_path, tcard, ) diff --git a/tests/test_evolve.py b/tests/test_evolve.py index 477e7731..91fb56a9 100644 --- a/tests/test_evolve.py +++ b/tests/test_evolve.py @@ -52,26 +52,3 @@ def metadata(self): return {"convolution_particle_1": 2212, "convolution_particle_2": 11} -def test_write_operator_card_q0(tmp_path): - """Checks https://github.com/NNPDF/pineko/issues/146""" - p = tmp_path / "q0.yaml" - g = FakePine() - t = copy.deepcopy(default_card) - o = copy.deepcopy(example.raw_operator()) - # 1. Same Q0 and init, all ok - t["Q0"] = 5.0 - o["init"] = [5.0, 4] - _xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t) - with open(p, encoding="utf8") as f: - oo = yaml.safe_load(f) - np.testing.assert_allclose(oo["init"][0], t["Q0"]) - # 2. Q0 only in theory, all ok - o.pop("init") - _xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t) - with open(p, encoding="utf8") as f: - oo = yaml.safe_load(f) - np.testing.assert_allclose(oo["init"][0], t["Q0"]) - # 3. op is different, raises error - o["init"] = [11.0, 3] - with pytest.raises(ValueError): - _xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t)