From 3347eb84d2693e526f61631d8c66621f94cbc6f7 Mon Sep 17 00:00:00 2001 From: gcroci2 Date: Thu, 30 May 2024 14:20:48 +0200 Subject: [PATCH 1/5] use dill to fix inspect transform functions --- deeprank2/trainer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deeprank2/trainer.py b/deeprank2/trainer.py index e133dbca..9c0667ca 100644 --- a/deeprank2/trainer.py +++ b/deeprank2/trainer.py @@ -6,6 +6,7 @@ from time import time from typing import Any +import dill import h5py import numpy as np import torch @@ -946,7 +947,11 @@ def _save_model(self) -> dict[str, Any]: for key in features_transform_to_save.values(): if key["transform"] is None: continue - str_expr = inspect.getsource(key["transform"]) + # Serialize the function + serialized_func = dill.dumps(key["transform"]) + # Deserialize the function + deserialized_func = dill.loads(serialized_func) + str_expr = inspect.getsource(deserialized_func) match = re.search(r"[\"|\']transform[\"|\']:.*(lambda.*).*,.*[\"|\']standardize[\"|\'].*", str_expr).group(1) key["transform"] = match From 69776c5032f6a9a098d85b908cd6bc098387423c Mon Sep 17 00:00:00 2001 From: gcroci2 Date: Thu, 30 May 2024 15:03:42 +0200 Subject: [PATCH 2/5] upgrade scipy --- deeprank2/utils/grid.py | 8 ++++---- docs/conf.py | 2 +- env/deeprank2-docker.yml | 2 +- env/deeprank2.yml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/deeprank2/utils/grid.py b/deeprank2/utils/grid.py index 70e7bda6..a31bef0f 100644 --- a/deeprank2/utils/grid.py +++ b/deeprank2/utils/grid.py @@ -7,7 +7,7 @@ import h5py import numpy as np from numpy.typing import NDArray -from scipy.signal import bspline +from scipy.interpolate import BSpline from deeprank2.domain import gridstorage @@ -190,9 +190,9 @@ def _get_mapped_feature_bsp_line( fx, fy, fz = position bsp_data = ( - bspline((self.xgrid - fx) / self._settings.resolutions[0], order) - * bspline((self.ygrid - fy) / self._settings.resolutions[1], order) - * bspline((self.zgrid - fz) / self._settings.resolutions[2], order) + BSpline((self.xgrid - fx) / self._settings.resolutions[0], order) + * BSpline((self.ygrid - fy) / self._settings.resolutions[1], order) + * BSpline((self.zgrid - fz) / self._settings.resolutions[2], order) ) return value * bsp_data diff --git a/docs/conf.py b/docs/conf.py index 5ed177fa..368af535 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ "scipy", "h5py", "sklearn", - "scipy.signal", + "scipy.interpolate", "torch", "torch.utils", "torch.utils.data", diff --git a/env/deeprank2-docker.yml b/env/deeprank2-docker.yml index 440daf9c..3b49f806 100644 --- a/env/deeprank2-docker.yml +++ b/env/deeprank2-docker.yml @@ -25,7 +25,7 @@ dependencies: - pytorch-spline-conv>=1.2.2 - tables>=3.8.0 - numpy>=1.21.5 - - scipy>=1.11.2 + - scipy>=1.13.1 - h5py>=3.6.0 - networkx>=2.6.3 - matplotlib>=3.5.1 diff --git a/env/deeprank2.yml b/env/deeprank2.yml index 6127fcb6..e73ab82d 100644 --- a/env/deeprank2.yml +++ b/env/deeprank2.yml @@ -25,7 +25,7 @@ dependencies: - pytorch-spline-conv>=1.2.2 - tables>=3.8.0 - numpy>=1.21.5 - - scipy>=1.11.2 + - scipy>=1.13.1 - h5py>=3.6.0 - networkx>=2.6.3 - matplotlib>=3.5.1 From a3ff8e29b2e87f7818463d848442ebcd1d859a03 Mon Sep 17 00:00:00 2001 From: gcroci2 Date: Thu, 30 May 2024 15:08:58 +0200 Subject: [PATCH 3/5] ignore ruff error --- deeprank2/trainer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeprank2/trainer.py b/deeprank2/trainer.py index 9c0667ca..ab54a436 100644 --- a/deeprank2/trainer.py +++ b/deeprank2/trainer.py @@ -950,7 +950,7 @@ def _save_model(self) -> dict[str, Any]: # Serialize the function serialized_func = dill.dumps(key["transform"]) # Deserialize the function - deserialized_func = dill.loads(serialized_func) + deserialized_func = dill.loads(serialized_func) # noqa: S301 str_expr = inspect.getsource(deserialized_func) match = re.search(r"[\"|\']transform[\"|\']:.*(lambda.*).*,.*[\"|\']standardize[\"|\'].*", str_expr).group(1) key["transform"] = match From 08867009575c4ff8426f01b0b5d5a17e6739461d Mon Sep 17 00:00:00 2001 From: Giulia Crocioni <55382553+gcroci2@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:32:12 +0200 Subject: [PATCH 4/5] add handy init options to pytest --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 5ecc23d9..48cd127b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,11 @@ exclude = ["tests", "tests*", "*tests.*", "*tests"] [tool.setuptools.package-data] "*" = ["*.xlsx", "*.param", "*.top", "*residue-classes"] +[tool.pytest.ini_options] +# pytest options: -ra: show summary info for all test outcomes +# -n auto: run tests in parallel +addopts = "-ra -n auto" + [tool.ruff] line-length = 159 From 3183e417754620d472c359cc26261f45948b8db5 Mon Sep 17 00:00:00 2001 From: gcroci2 Date: Mon, 3 Jun 2024 15:08:50 +0200 Subject: [PATCH 5/5] remove pytest running in parallel --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 48cd127b..df16c396 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,8 +67,7 @@ exclude = ["tests", "tests*", "*tests.*", "*tests"] [tool.pytest.ini_options] # pytest options: -ra: show summary info for all test outcomes -# -n auto: run tests in parallel -addopts = "-ra -n auto" +addopts = "-ra" [tool.ruff] line-length = 159