From bafcbde81cb3c7df4cb4215f1110dbcc50c346d6 Mon Sep 17 00:00:00 2001 From: siranipour Date: Tue, 21 Apr 2020 11:15:31 +0100 Subject: [PATCH 1/3] Changing loc behaviour in pandas --- validphys2/src/validphys/eff_exponents.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validphys2/src/validphys/eff_exponents.py b/validphys2/src/validphys/eff_exponents.py index 37ed5afed2..2092170952 100644 --- a/validphys2/src/validphys/eff_exponents.py +++ b/validphys2/src/validphys/eff_exponents.py @@ -425,8 +425,8 @@ def next_effective_exponents_yaml(fit: FitSpec, effective_exponents_table): runcard_flavours = basis.to_known_elements( [ref_fl['fl'] for ref_fl in previous_exponents]).tolist() for fl in flavours: - alphas = df_effexps.loc[(f'${fl}$', r'$\alpha$'), ['next Min', 'next Max']].values - betas = df_effexps.loc[(f'${fl}$', r'$\beta$'), ['next Min', 'next Max']].values + alphas = df_effexps.loc[(f'${fl}$', r'$\alpha$')].filter(like="next").values + betas = df_effexps.loc[(f'${fl}$', r'$\beta$')].filter(like="next").values previous_exponents[runcard_flavours.index(fl)]['smallx'] = [fmt(alpha) for alpha in alphas] previous_exponents[runcard_flavours.index(fl)]['largex'] = [fmt(beta) for beta in betas] #iterate t0 From 4ec0f34d0d5892adb9f293ee2d1510f2ff981008 Mon Sep 17 00:00:00 2001 From: wilsonm Date: Tue, 21 Apr 2020 12:19:59 +0100 Subject: [PATCH 2/3] update next eff exps yaml to use the next effective exponents table - avoid pandas gymnastics --- validphys2/src/validphys/eff_exponents.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/validphys2/src/validphys/eff_exponents.py b/validphys2/src/validphys/eff_exponents.py index 2092170952..7587045978 100644 --- a/validphys2/src/validphys/eff_exponents.py +++ b/validphys2/src/validphys/eff_exponents.py @@ -397,7 +397,9 @@ def effective_exponents_table_internal( 'effective_exponents_table_internal', ('fitpdfandbasis',)) fmt = lambda a: float(significant_digits(a, 4)) -def next_effective_exponents_yaml(fit: FitSpec, effective_exponents_table): +next_fit_eff_exps_table = collect("next_effective_exponents_table", ("fitpdfandbasis",)) + +def next_effective_exponents_yaml(fit: FitSpec, next_fit_eff_exps_table): """-Returns a table in yaml format called NextEffExps.yaml -Prints the yaml table in the report using `effective_exponents_table` this provider outputs the yaml runcard to run @@ -412,8 +414,8 @@ def next_effective_exponents_yaml(fit: FitSpec, effective_exponents_table): """ - df_effexps = effective_exponents_table[0] - #Reading from the filter + df_effexps = next_fit_eff_exps_table[0] + # Use round trip loader rather than safe_load in fit.as_input() with open(fit.path/'filter.yml', 'r') as f: filtermap = yaml.load(f, yaml.RoundTripLoader) previous_exponents = filtermap['fitting']['basis'] @@ -425,8 +427,8 @@ def next_effective_exponents_yaml(fit: FitSpec, effective_exponents_table): runcard_flavours = basis.to_known_elements( [ref_fl['fl'] for ref_fl in previous_exponents]).tolist() for fl in flavours: - alphas = df_effexps.loc[(f'${fl}$', r'$\alpha$')].filter(like="next").values - betas = df_effexps.loc[(f'${fl}$', r'$\beta$')].filter(like="next").values + alphas = df_effexps.loc[(f'${fl}$', r'$\alpha$')].values + betas = df_effexps.loc[(f'${fl}$', r'$\beta$')].values previous_exponents[runcard_flavours.index(fl)]['smallx'] = [fmt(alpha) for alpha in alphas] previous_exponents[runcard_flavours.index(fl)]['largex'] = [fmt(beta) for beta in betas] #iterate t0 From dd52f780785adb89cbbf46734d01d6951073fa68 Mon Sep 17 00:00:00 2001 From: siranipour Date: Wed, 29 Apr 2020 11:34:19 +0100 Subject: [PATCH 3/3] Adding a test to ensure the correct ite2 runcard is generated --- .../src/validphys/tests/test_effexponents.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 validphys2/src/validphys/tests/test_effexponents.py diff --git a/validphys2/src/validphys/tests/test_effexponents.py b/validphys2/src/validphys/tests/test_effexponents.py new file mode 100644 index 0000000000..4703a2aa91 --- /dev/null +++ b/validphys2/src/validphys/tests/test_effexponents.py @@ -0,0 +1,20 @@ +import pytest + +from validphys.api import API +from validphys.loader import FallbackLoader as Loader + +from reportengine.compat import yaml + + +def test_next_runcard(): + l = Loader() + ite1_fit = l.check_fit("191015-mw-001") + # The runcard of a 2nd iteration fit I ran manually + ite2_runcard = l.check_fit("191015-mw-001_ite2_for_testing").as_input() + ite2_runcard.pop("pdf") # Removing the PDF key, it's an artefact of as_input + + predicted_ite2_runcard = yaml.safe_load( + API.next_effective_exponents_yaml(fit="191015-mw-001") + ) + # Check that the actual ite2 runcard matches what vp thinks it should be + assert predicted_ite2_runcard == ite2_runcard