Skip to content

Commit

Permalink
merge with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gcroci2 committed Jul 11, 2024
2 parents bb84d62 + 6206f15 commit 486ab48
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 84 deletions.
15 changes: 14 additions & 1 deletion .github/actions/install-python-and-package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ runs:
activate-environment: deeprank2
environment-file: env/deeprank2.yml
use-mamba: true
if: ${{ inputs.pkg-installation-type != 'frozen' }}

- name: Setup miniconda with frozen dependencies
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniforge-variant: Mambaforge
channels: conda-forge
python-version: ${{ inputs.python-version }}
activate-environment: deeprank2
environment-file: env/deeprank2_frozen.yml
use-mamba: true
if: ${{ inputs.pkg-installation-type == 'frozen' }}

- run: |
conda --version
Expand All @@ -53,7 +66,7 @@ runs:
- name: Install the GitHub repository version of the package
shell: bash -l {0}
if: ${{ inputs.pkg-installation-type == 'repository' }}
if: ${{ inputs.pkg-installation-type == 'repository' || inputs.pkg-installation-type == 'frozen' }}
run: |
conda activate deeprank2
pip install .'[${{ inputs.extras-require }}]'
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/build-repo-frozen-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: build (repository package) using the frozen environment

on:
push:
paths-ignore:
# specific folder locations
- ".vscode/**"
- "docs/**"
# filetypes
- "**.md"
- "**.rst"
- "**.ipynb"
- "**.cff"
- "**.png"
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
# specific folder locations
- ".vscode/**"
- "docs/**"
# filetypes
- "**.md"
- "**.rst"
- "**.ipynb"
- "**.cff"
- "**.png"

jobs:
build:
if: github.event.pull_request.draft == false
name: Build for (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10"] # ["3.10", "3.11"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/install-python-and-package
with:
python-version: ${{ matrix.python-version }}
extras-require: test, publishing
pkg-installation-type: "frozen"

- name: Run unit tests
run: pytest -v

- name: Verify that we can build the package
run: python3 -m build
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ conda activate deeprank2
pip install deeprank2
```

We also provide a frozen environment YML file located at `env/deeprank2_frozen.yml` with all dependencies set to fixed versions. The `env/deeprank2_frozen.yml` file provides a frozen environment with all dependencies set to fixed versions. This ensures reproducibility of experiments and results by preventing changes in package versions that could occur due to updates or modifications in the default `env/deeprank2.yml`. Use this frozen environment file for a stable and consistent setup, particularly if you encounter issues with the default environment file.

#### Manual installation (customizable)

If you want to use the GPUs, choose a specific python version (note that at the moment we support python 3.10 only), are a MacOS user, or if the YML installation was not successful, you can install the package manually. We advise to do this inside a [conda virtual environment](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html).
Expand Down
5 changes: 1 addition & 4 deletions deeprank2/tools/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ def add_target( # noqa: C901
1ATN_xxx-3 0
1ATN_xxx-4 0
"""
target_dict = {}

labels = np.loadtxt(target_list, delimiter=sep, usecols=[0], dtype=str)
values = np.loadtxt(target_list, delimiter=sep, usecols=[1])
for label, value in zip(labels, values, strict=True):
target_dict[label] = value
target_dict = dict(zip(labels, values, strict=False))

if os.path.isdir(graph_path):
graphs = glob.glob(f"{graph_path}/*.hdf5")
Expand Down
27 changes: 9 additions & 18 deletions deeprank2/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ def _precluster(self, dataset: GraphDataset) -> None:
f5.close()

def _put_model_to_device(self, dataset: GraphDataset | GridDataset) -> None:
"""
Puts the model on the available device.
"""Puts the model on the available device.
Args:
dataset (:class:`GraphDataset` | :class:`GridDataset`): GraphDataset object.
Expand Down Expand Up @@ -407,8 +406,7 @@ def configure_optimizers(
lr: float = 0.001,
weight_decay: float = 1e-05,
) -> None:
"""
Configure optimizer and its main parameters.
"""Configure optimizer and its main parameters.
Args:
optimizer (:class:`torch.optim`, optional): PyTorch optimizer object. If none, defaults to :class:`torch.optim.Adam`.
Expand Down Expand Up @@ -437,8 +435,7 @@ def set_lossfunction( # noqa: C901
lossfunction: nn.modules.loss._Loss | None = None,
override_invalid: bool = False,
) -> None:
"""
Set the loss function.
"""Set the loss function.
Args:
lossfunction (optional): Make sure to use a loss function that is appropriate for
Expand Down Expand Up @@ -526,8 +523,7 @@ def train( # noqa: PLR0915, C901
best_model: bool = True,
filename: str | None = "model.pth.tar",
) -> None:
"""
Performs the training of the model.
"""Performs the training of the model.
Args:
nepoch (int, optional): Maximum number of epochs to run.
Expand Down Expand Up @@ -687,8 +683,7 @@ def train( # noqa: PLR0915, C901
self.model.load_state_dict(self.model_load_state_dict)

def _epoch(self, epoch_number: int, pass_name: str) -> float | None:
"""
Runs a single epoch.
"""Runs a single epoch.
Args:
epoch_number (int): the current epoch number
Expand Down Expand Up @@ -753,8 +748,7 @@ def _eval(
epoch_number: int,
pass_name: str,
) -> float | None:
"""
Evaluates the model.
"""Evaluates the model.
Args:
loader (Dataloader): Data to evaluate on.
Expand Down Expand Up @@ -820,8 +814,7 @@ def _eval(

@staticmethod
def _log_epoch_data(stage: str, loss: float, time: float) -> None:
"""
Prints the data of each epoch.
"""Prints the data of each epoch.
Args:
stage (str): Train or valid.
Expand Down Expand Up @@ -865,8 +858,7 @@ def test(
batch_size: int = 32,
num_workers: int = 0,
) -> None:
"""
Performs the testing of the model.
"""Performs the testing of the model.
Args:
batch_size (int, optional): Sets the size of the batch.
Expand Down Expand Up @@ -937,8 +929,7 @@ def _load_params(self) -> None:
self.ngpu = state["ngpu"]

def _save_model(self) -> dict[str, Any]:
"""
Saves the model to a file.
"""Saves the model to a file.
Args:
filename (str, optional): Name of the file. Defaults to None.
Expand Down
8 changes: 1 addition & 7 deletions deeprank2/utils/parsing/residue.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def __init__(
absent_atom_names: list[str],
):
self.class_name = class_name

self.amino_acid_names = amino_acid_names

self.present_atom_names = present_atom_names
self.absent_atom_names = absent_atom_names

Expand All @@ -26,11 +24,7 @@ def matches(self, amino_acid_name: str, atom_names: list[str]) -> bool:
return False

# check the atom names that should be present
if not all(atom_name in atom_names for atom_name in self.present_atom_names):
return False

# all checks passed
return True
return all(atom_name in atom_names for atom_name in self.present_atom_names)


class ResidueClassParser: # noqa: D101
Expand Down
2 changes: 2 additions & 0 deletions docs/source/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ conda activate deeprank2
pip install deeprank2
```

We also provide a frozen environment YML file located at `env/deeprank2_frozen.yml` with all dependencies set to fixed versions. The `env/deeprank2_frozen.yml` file provides a frozen environment with all dependencies set to fixed versions. This ensures reproducibility of experiments and results by preventing changes in package versions that could occur due to updates or modifications in the default `env/deeprank2.yml`. Use this frozen environment file for a stable and consistent setup, particularly if you encounter issues with the default environment file.

## Manual installation (customizable)

(manual-installation)=
Expand Down
10 changes: 6 additions & 4 deletions env/deeprank2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ channels:
- conda-forge
- sbl
dependencies:
- sbl::libcifpp>=5.1.0
- sbl::dssp>=4.2.2.1
- msms>=2.6.1
- python=3.10
- pip>=23.3
- sbl::libcifpp=5.1.0
- sbl::dssp=4.2.2.1
- msms=2.6.1
- pytorch=2.1.1
- torchvision>=0.16.1
- torchaudio>=2.1.1
- cpuonly>=2.0
- pyg>=2.4.0
- pyg=2.4.0
- pytorch-scatter>=2.1.2
- pytorch-sparse>=0.6.18
- pytorch-cluster>=1.6.3
Expand Down
Loading

0 comments on commit 486ab48

Please sign in to comment.