From fbbd4ef559d254eb658b8f57dc6b01f77a6c2fa3 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Fri, 8 Apr 2022 12:17:45 +0200 Subject: [PATCH 1/3] fix info file --- validphys2/src/validphys/lhio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validphys2/src/validphys/lhio.py b/validphys2/src/validphys/lhio.py index ebe2f3d671..6aaf2a0bf0 100644 --- a/validphys2/src/validphys/lhio.py +++ b/validphys2/src/validphys/lhio.py @@ -310,8 +310,8 @@ def hessian_from_lincomb(pdf, V, set_name=None, folder = None, extra_fields=None out.write(f"SetDesc: \"Hessian {pdf}_hessian\"\n") elif l.find("NumMembers:") >= 0: out.write(f"NumMembers: {neig+1}\n") - elif l.find("error_type: replicas") >= 0: - out.write("error_type: symmhessian\n") + elif l.find("ErrorType: replicas") >= 0: + out.write("ErrorType: symmhessian\n") else: out.write(l) if extra_fields is not None: From 7546d063813c2ff7cc3948c1d0a91b7538dcdef7 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Fri, 8 Apr 2022 12:57:23 +0200 Subject: [PATCH 2/3] add test for mc2hessian --- .../src/validphys/tests/test_mc2hessian.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 validphys2/src/validphys/tests/test_mc2hessian.py diff --git a/validphys2/src/validphys/tests/test_mc2hessian.py b/validphys2/src/validphys/tests/test_mc2hessian.py new file mode 100644 index 0000000000..749e568f25 --- /dev/null +++ b/validphys2/src/validphys/tests/test_mc2hessian.py @@ -0,0 +1,41 @@ +""" + Test for the mc2hessian module +""" +from validphys.api import API + +NEIG = 5 + + +def test_mc2hessian(data_config, tmp, monkeypatch): + """Tests that the generated hessian PDF is indeed marked as such + and that the metadata is not obviously broken + """ + config = dict(data_config) + pdf_hessian_name = f"{config['pdf']}_hessian_{NEIG}" + + config["Neig"] = NEIG + config["output_path"] = tmp + API.mc2hessian(**config) + + # Save a reference to the original pdf + orig_pdf = API.pdf(pdf=config["pdf"]) + + # Now try to read the PDF we just wrote + monkeypatch.setenv("LHAPDF_DATA_PATH", tmp.as_posix()) + pdf = API.pdf(pdf=pdf_hessian_name) + + # Check the correct changed metadata + assert pdf.error_type == "symmhessian" + assert len(pdf) == NEIG + 1 + + # Now check that all info is the same as the original + # except for ErrorType that _must_ be different + skip_this = ["SetDesc", "NumMembers"] + for key, item in orig_pdf.info.items(): + if key in skip_this: + continue + new_item = pdf.info[key] + if key == "ErrorType": + assert item != new_item + else: + assert item == new_item From 1eaff2b4428531aa74af1462f7ae9e9e598f3923 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Fri, 8 Apr 2022 14:04:23 +0200 Subject: [PATCH 3/3] change lhapdf data dir --- .../src/validphys/tests/test_mc2hessian.py | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/validphys2/src/validphys/tests/test_mc2hessian.py b/validphys2/src/validphys/tests/test_mc2hessian.py index 749e568f25..51b1e4ec2c 100644 --- a/validphys2/src/validphys/tests/test_mc2hessian.py +++ b/validphys2/src/validphys/tests/test_mc2hessian.py @@ -1,12 +1,25 @@ """ Test for the mc2hessian module """ +import contextlib +import lhapdf from validphys.api import API NEIG = 5 -def test_mc2hessian(data_config, tmp, monkeypatch): +@contextlib.contextmanager +def temp_lhapdf_path(folder): + """Modify the data path for LHAPDF sets""" + oldpaths = lhapdf.paths() + lhapdf.setPaths([str(folder)]) + try: + yield + finally: + lhapdf.setPaths(oldpaths) + + +def test_mc2hessian(data_config, tmp): """Tests that the generated hessian PDF is indeed marked as such and that the metadata is not obviously broken """ @@ -18,24 +31,24 @@ def test_mc2hessian(data_config, tmp, monkeypatch): API.mc2hessian(**config) # Save a reference to the original pdf - orig_pdf = API.pdf(pdf=config["pdf"]) - - # Now try to read the PDF we just wrote - monkeypatch.setenv("LHAPDF_DATA_PATH", tmp.as_posix()) - pdf = API.pdf(pdf=pdf_hessian_name) - - # Check the correct changed metadata - assert pdf.error_type == "symmhessian" - assert len(pdf) == NEIG + 1 - - # Now check that all info is the same as the original - # except for ErrorType that _must_ be different - skip_this = ["SetDesc", "NumMembers"] - for key, item in orig_pdf.info.items(): - if key in skip_this: - continue - new_item = pdf.info[key] - if key == "ErrorType": - assert item != new_item - else: - assert item == new_item + orig_pdf_info = API.pdf(pdf=config["pdf"]).info + + # Now try to read the PDF we just wrote to some non_std location + with temp_lhapdf_path(tmp.as_posix()): + pdf = API.pdf(pdf=pdf_hessian_name) + + # Check the correct changed metadata + assert pdf.error_type == "symmhessian" + assert len(pdf) == NEIG + 1 + + # Now check that all info is the same as the original + # except for ErrorType that _must_ be different + skip_this = ["SetDesc", "NumMembers"] + for key, item in orig_pdf_info.items(): + if key in skip_this: + continue + new_item = pdf.info[key] + if key == "ErrorType": + assert item != new_item + else: + assert item == new_item