Skip to content

Commit

Permalink
Merge pull request #606 from DeepRank/fix_inspect_function_trainer_gc…
Browse files Browse the repository at this point in the history
…roci2

fix: OSError when retrieving source code for lambda functions
  • Loading branch information
gcroci2 authored Jun 6, 2024
2 parents e422fb3 + 3183e41 commit 655f301
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
7 changes: 6 additions & 1 deletion deeprank2/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from time import time
from typing import Any

import dill
import h5py
import numpy as np
import torch
Expand Down Expand Up @@ -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) # noqa: S301
str_expr = inspect.getsource(deserialized_func)
match = re.search(r"[\"|\']transform[\"|\']:.*(lambda.*).*,.*[\"|\']standardize[\"|\'].*", str_expr).group(1)
key["transform"] = match

Expand Down
8 changes: 4 additions & 4 deletions deeprank2/utils/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"scipy",
"h5py",
"sklearn",
"scipy.signal",
"scipy.interpolate",
"torch",
"torch.utils",
"torch.utils.data",
Expand Down
2 changes: 1 addition & 1 deletion env/deeprank2-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion env/deeprank2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ 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
addopts = "-ra"

[tool.ruff]
line-length = 159

Expand Down

0 comments on commit 655f301

Please sign in to comment.