From dd2cb069040a918baa8faf5e2e0936e4c8824167 Mon Sep 17 00:00:00 2001 From: Eva Groenendijk Date: Fri, 23 May 2025 17:18:34 +0200 Subject: [PATCH 1/6] Introduction of template.py to contain constants and xgrid --- src/pineko/template.py | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/pineko/template.py diff --git a/src/pineko/template.py b/src/pineko/template.py new file mode 100644 index 00000000..aeea8802 --- /dev/null +++ b/src/pineko/template.py @@ -0,0 +1,102 @@ +"""Default settings and interpolation xgrid (previously in _template.yaml).""" + +from eko.interpolation import XGrid + +# Define the interpolation x-grid as previously defined as 'xgrid' in _template.yaml +INTERPOLATION_XGRID = 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] + ) + +# Define some default parameters + +CONSTANTS = { + "configs": { + "ev_op_iterations": 1, + "ev_op_max_order": (10,1), + "evolution_method": iterate-exact, + "interpolation_is_log": true, + "interpolation_polynomial_degree": 4, + "inversion_method": expanded, + "n_integration_cores": 1, + "polarized": false, + "scvar_method": null, + "time_like": false + }, + "debug": { + "skip_non_singlet": false, + "skip_singlet": false + }, + "eko_version": 0.14.2, + "mu0": 0, +} + + + + + + + + + + + + + + + + + + + + + + From 51eb28bf7cb11ff27d39461c09815df589357eb8 Mon Sep 17 00:00:00 2001 From: Eva Groenendijk Date: Fri, 23 May 2025 17:25:43 +0200 Subject: [PATCH 2/6] Introduction of template.py to contain constants and xgrid --- src/pineko/template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pineko/template.py b/src/pineko/template.py index aeea8802..68b31b74 100644 --- a/src/pineko/template.py +++ b/src/pineko/template.py @@ -56,7 +56,7 @@ 1] ) -# Define some default parameters +# Define default constants CONSTANTS = { "configs": { From 756be45d2b9caef8ffff9cc6b81fa6a7396c7c3d Mon Sep 17 00:00:00 2001 From: Eva Groenendijk Date: Thu, 19 Jun 2025 12:00:03 +0200 Subject: [PATCH 3/6] Removal of need of _template.yaml --- src/pineko/evolve.py | 31 +++++++++++++------------------ src/pineko/template.py | 30 +++++++++++++++++------------- src/pineko/theory.py | 2 -- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/pineko/evolve.py b/src/pineko/evolve.py index ca6c1784..c84bd811 100644 --- a/src/pineko/evolve.py +++ b/src/pineko/evolve.py @@ -22,7 +22,7 @@ from pineappl.fk_table import PyFkAssumptions from pineappl.grid import PyOperatorSliceInfo, PyPidBasis -from . import check, comparator, version +from . import check, comparator, version, template logger = logging.getLogger(__name__) @@ -95,7 +95,6 @@ def check_convolution_types(grid, operators1, operators2): def write_operator_card_from_file( pineappl_path: os.PathLike, - default_card_path: os.PathLike, card_path: os.PathLike, tcard, ): @@ -105,8 +104,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 @@ -124,10 +121,7 @@ def write_operator_card_from_file( if not pathlib.Path(pineappl_path).exists(): raise FileNotFoundError(pineappl_path) pineappl_grid = pineappl.grid.Grid.read(pineappl_path) - 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, operators_card, conv_type, suffix=False): @@ -160,15 +154,13 @@ def dump_card(card_path, operators_card, conv_type, suffix=False): ) -def write_operator_card(pineappl_grid, default_card, card_path, tcard): +def write_operator_card(pineappl_grid, card_path, tcard): """Generate operator card for this grid. Parameters ---------- pineappl_grid : pineappl.grid.Grid grid to evolve - default_card : dict - base operator card card_path : str or os.PathLike target path tcard: dict @@ -195,16 +187,17 @@ def write_operator_card(pineappl_grid, default_card, card_path, tcard): # ... 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) # Make sure that we are using the theory Q0 and fail if the template has a different one operators_card["mu0"] = tcard["Q0"] - if default_card.get("mu0") is not None and default_card["mu0"] != tcard["Q0"]: - raise ValueError("Template declares a value of Q0 different from theory") +# if template.CONSTANTS["mu0"] is not None and template.CONSTANTS["mu0"] != tcard["Q0"]: +# raise ValueError("Q0 from theory differs from standard Q0") q2_grid = (xif * xif * muf2_grid).tolist() masses = np.array([tcard["mc"], tcard["mb"], tcard["mt"]]) ** 2 @@ -228,6 +221,8 @@ def write_operator_card(pineappl_grid, default_card, card_path, tcard): 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 @@ -257,17 +252,17 @@ def write_operator_card(pineappl_grid, default_card, card_path, tcard): ) # 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 index 68b31b74..fe75fbaa 100644 --- a/src/pineko/template.py +++ b/src/pineko/template.py @@ -1,9 +1,9 @@ """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 -INTERPOLATION_XGRID = XGrid( +xgrid = ( [1.9999999999999954e-07, 3.034304765867952e-07, 4.6035014748963906e-07, @@ -56,32 +56,36 @@ 1] ) -# Define default constants +mugrid = [(4.6,4),(5.1,5),(5.6,5)] CONSTANTS = { "configs": { "ev_op_iterations": 1, "ev_op_max_order": (10,1), - "evolution_method": iterate-exact, - "interpolation_is_log": true, + "evolution_method": "iterate-exact", + "interpolation_is_log": True, "interpolation_polynomial_degree": 4, - "inversion_method": expanded, + "inversion_method": "expanded", "n_integration_cores": 1, - "polarized": false, - "scvar_method": null, - "time_like": false + "polarized": False, + "scvar_method": "null", + "time_like": False }, "debug": { - "skip_non_singlet": false, - "skip_singlet": false + "skip_non_singlet": False, + "skip_singlet": False }, - "eko_version": 0.14.2, + "eko_version": "0.14.2", "mu0": 0, } +operator_card = {} +operator_card["mugrid"] = mugrid - +card_path = "./test.yaml" +with open(card_path, "w", encoding="UTF-8") as f: + yaml.safe_dump(operator_card, f) diff --git a/src/pineko/theory.py b/src/pineko/theory.py index fa58d169..b5b39bb9 100644 --- a/src/pineko/theory.py +++ b/src/pineko/theory.py @@ -271,8 +271,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, ) From ed25c7dc1e823b035e71ba6a5d86424de5a3a69e Mon Sep 17 00:00:00 2001 From: Eva Groenendijk Date: Thu, 19 Jun 2025 12:18:59 +0200 Subject: [PATCH 4/6] Remove test that checks q0 from theory card & _template.py --- tests/test_evolve.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/tests/test_evolve.py b/tests/test_evolve.py index f529b80b..facc3dde 100644 --- a/tests/test_evolve.py +++ b/tests/test_evolve.py @@ -46,26 +46,3 @@ def key_values(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 mu0, all ok - t["Q0"] = 5.0 - o["mu0"] = 5.0 - _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["mu0"], t["Q0"]) - # 2. Q0 only in theory, all ok - o.pop("mu0") - _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["mu0"], t["Q0"]) - # 3. op is different, raises error - o["mu0"] = 11.0 - with pytest.raises(ValueError): - _xs, _mu2s = pineko.evolve.write_operator_card(g, o, p, t) From b0350dcf68509534f56682dfd9330c19b69e1769 Mon Sep 17 00:00:00 2001 From: Eva Groenendijk Date: Thu, 19 Jun 2025 17:30:26 +0200 Subject: [PATCH 5/6] Remove unnecessary stuff from template.py --- src/pineko/template.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/src/pineko/template.py b/src/pineko/template.py index fe75fbaa..44ae5f0f 100644 --- a/src/pineko/template.py +++ b/src/pineko/template.py @@ -56,51 +56,15 @@ 1] ) -mugrid = [(4.6,4),(5.1,5),(5.6,5)] - CONSTANTS = { "configs": { "ev_op_iterations": 1, - "ev_op_max_order": (10,1), "evolution_method": "iterate-exact", - "interpolation_is_log": True, - "interpolation_polynomial_degree": 4, "inversion_method": "expanded", - "n_integration_cores": 1, "polarized": False, "scvar_method": "null", "time_like": False }, - "debug": { - "skip_non_singlet": False, - "skip_singlet": False - }, "eko_version": "0.14.2", - "mu0": 0, } - -operator_card = {} -operator_card["mugrid"] = mugrid - -card_path = "./test.yaml" -with open(card_path, "w", encoding="UTF-8") as f: - yaml.safe_dump(operator_card, f) - - - - - - - - - - - - - - - - - - From 22d9ac289ede86059236ab2e917ca7a3abba45fc Mon Sep 17 00:00:00 2001 From: Eva Groenendijk Date: Fri, 20 Jun 2025 17:16:13 +0200 Subject: [PATCH 6/6] Forgot to add template.py --- src/pineko/template.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pineko/template.py b/src/pineko/template.py index 44ae5f0f..dc6ed952 100644 --- a/src/pineko/template.py +++ b/src/pineko/template.py @@ -65,6 +65,7 @@ "scvar_method": "null", "time_like": False }, + "init": (1.65, 4), "eko_version": "0.14.2", }