Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OSError when retrieving source code for lambda functions #606

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading