From 0ebabf307a3ca715817b93beb0a4b60e8b2d54b0 Mon Sep 17 00:00:00 2001 From: andreab1997 Date: Fri, 4 Nov 2022 13:47:08 +0100 Subject: [PATCH 1/3] Remove rotations from get_output --- src/eko/runner.py | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/src/eko/runner.py b/src/eko/runner.py index 37f37a3e6..ddbacc4c3 100644 --- a/src/eko/runner.py +++ b/src/eko/runner.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -"""This file contains the main application class of eko.""" +"""Main application class of eko.""" import copy import logging from typing import Optional @@ -103,35 +103,4 @@ def get_output(self) -> EKO: for final_scale, op in self.op_grid.compute().items(): self.out[float(final_scale)] = Operator.from_dict(op) - def similar_to_none(name: str) -> Optional[np.ndarray]: - grid = self.post_process[name] - - default = self.out.xgrid.grid if "grid" in name else self.out.rotations.pids - if grid is None or ( - len(grid) == default.size and np.allclose(grid, default, atol=1e-12) - ): - return None - - return np.array(grid) - - # reshape xgrid - inputgrid = similar_to_none("inputgrid") - targetgrid = similar_to_none("targetgrid") - if inputgrid is not None or targetgrid is not None: - if inputgrid is not None: - inputgrid = interpolation.XGrid(inputgrid) - if targetgrid is not None: - targetgrid = interpolation.XGrid(targetgrid) - manipulate.xgrid_reshape( - self.out, targetgrid=targetgrid, inputgrid=inputgrid - ) - - # reshape flavors - inputpids = similar_to_none("inputpids") - targetpids = similar_to_none("targetpids") - if inputpids is not None or targetpids is not None: - manipulate.flavor_reshape( - self.out, targetpids=targetpids, inputpids=inputpids - ) - return copy.deepcopy(self.out) From 8d2b6e9aca40386347f137fb9c6ad53d3873e5cb Mon Sep 17 00:00:00 2001 From: andreab1997 Date: Mon, 7 Nov 2022 13:53:07 +0100 Subject: [PATCH 2/3] Remove last part of init --- src/eko/runner.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/eko/runner.py b/src/eko/runner.py index ddbacc4c3..ce5c929a5 100644 --- a/src/eko/runner.py +++ b/src/eko/runner.py @@ -75,13 +75,6 @@ def __init__(self, theory_card: dict, operators_card: dict): # setup operator grid self.op_grid = OperatorGrid.from_dict(new_theory, new_operators, tc, sc, bfd) - # save bases manipulations for a post processing step - rot = operators_card.get("rotations", {}) - self.post_process = {} - for key in ("inputgrid", "targetgrid", "inputpids", "targetpids"): - self.post_process[key] = rot.get(key, None) - new_operators["rotations"][key] = None - self.out = EKO.new(theory=theory_card, operator=new_operators) def get_output(self) -> EKO: From bd846e2c9c6699d9df4ff8edfed878cf1319f598 Mon Sep 17 00:00:00 2001 From: andreab1997 Date: Mon, 7 Nov 2022 17:04:03 +0100 Subject: [PATCH 3/3] Fix test_runner --- tests/eko/test_runner.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/eko/test_runner.py b/tests/eko/test_runner.py index c1d491022..fb73f703a 100644 --- a/tests/eko/test_runner.py +++ b/tests/eko/test_runner.py @@ -78,8 +78,14 @@ def test_targetgrid(): oc["rotations"]["targetgrid"] = tgrid r = eko.runner.Runner(tc, oc) o = r.get_output() + # We are testing if (as expected) the runner ignores inputgrid and targetgrid. + actual_grid = oc["rotations"]["xgrid"] check_shapes( - o, eko.interpolation.XGrid(tgrid), eko.interpolation.XGrid(igrid), tc, oc + o, + eko.interpolation.XGrid(actual_grid), + eko.interpolation.XGrid(actual_grid), + tc, + oc, ) # check actual value np.testing.assert_allclose(o.rotations.targetgrid.raw, tgrid) @@ -95,8 +101,8 @@ def test_rotate_pids(): o = r.get_output() check_shapes(o, o.xgrid, o.xgrid, tc, oc) # check actual values - assert (o.rotations.targetpids == [0] * 14).all() - assert (o.rotations.inputpids == [0] * 14).all() + assert (o.rotations.targetpids == oc["rotations"]["targetpids"]).all() + assert (o.rotations.inputpids == oc["rotations"]["inputpids"]).all() def check_shapes(o, txs, ixs, theory_card, operators_card): @@ -104,10 +110,17 @@ def check_shapes(o, txs, ixs, theory_card, operators_card): ipids = len(o.rotations.inputpids) op_shape = (tpids, len(txs), ipids, len(ixs)) + op_targetgrid = operators_card["rotations"]["targetgrid"] + op_inputgrid = operators_card["rotations"]["inputgrid"] # check output = input np.testing.assert_allclose(o.xgrid.raw, operators_card["rotations"]["xgrid"]) - np.testing.assert_allclose(o.rotations.targetgrid.raw, txs.raw) - np.testing.assert_allclose(o.rotations.inputgrid.raw, ixs.raw) + np.testing.assert_allclose( + o.rotations.targetgrid.raw, + op_targetgrid if op_targetgrid is not None else txs.raw, + ) + np.testing.assert_allclose( + o.rotations.inputgrid.raw, op_inputgrid if op_inputgrid is not None else ixs.raw + ) for k in ["interpolation_polynomial_degree", "interpolation_is_log"]: assert getattr(o.configs, k) == operators_card["configs"][k] np.testing.assert_allclose(o.Q02, theory_card["Q0"] ** 2)