Skip to content

Commit

Permalink
TESTS: configure codecov, add tests for directory initialization and …
Browse files Browse the repository at this point in the history
…probability calculations (#2)
  • Loading branch information
anmorgunov authored Oct 24, 2023
1 parent 96cf348 commit 20af783
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 46 deletions.
10 changes: 10 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[run]
source =
ChemSpaceAL/InitializeWorkspace.py

omit =
ChemSpaceAL/Model.py
ChemSpaceAL/Dataset.py
ChemSpaceAL/Docking.py
ChemSpaceAL/Generation.py
ChemSpaceAL/Training.py
30 changes: 12 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,31 @@ name: Python application test with pytest

on:
push:
branches: [ main ]
branches: [ main, sandbox ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install pandas numpy torch rdkit
pip install pytest pytest-cov
- name: Install package
run: |
python setup.py install
- name: Run pytest
run: |
pytest --cov tests/
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Run tests and collect coverage
run: pytest --cov=ChemSpaceAL
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4-beta
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

3 changes: 0 additions & 3 deletions ChemSpaceAL/ALConstruction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pandas as pd
import numpy as np
import pickle
import plotly.graph_objects as go

from ChemSpaceAL.Configuration import Config
from typing import Union, Dict, List, Callable, Optional, cast
Expand Down Expand Up @@ -67,7 +66,6 @@ def _preprocess_scores_linearly(
normalized = {k: v / total for k, v in negated.items()}
return normalized


def _preprocess_scores_softmax(
scores: Dict[int, Number],
do_negation: bool = False,
Expand All @@ -90,7 +88,6 @@ def _preprocess_scores_softmax(
softmax = {k: v / total for k, v in exponentiate.items()}
return softmax


def balance_cluster_to_n(
cluster_to_n: Dict[int, int], cluster_to_len: Dict[int, int]
) -> Dict[int, int]:
Expand Down
4 changes: 2 additions & 2 deletions ChemSpaceAL/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
numpy==1.24.3
pandas==1.5.3
prolif==2.0.1
scikit_learn==1.3.2
PyYAML
rdkit==2023.3.1
scikit_learn==1.3.2
torch
tqdm==4.64.1
wandb==0.15.4
wandb==0.15.4
Empty file added ChemSpaceAL/tests/__init__.py
Empty file.
75 changes: 75 additions & 0 deletions ChemSpaceAL/tests/test_al_construction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from ..ALConstruction import _preprocess_scores_linearly, _preprocess_scores_softmax
import pytest


@pytest.mark.parametrize(
"scores, do_negation, expected",
[
(
{1: 2, 2: 2, 3: 2},
False,
{1: 1 / 3, 2: 1 / 3, 3: 1 / 3},
),
(
{1: 1, 2: 0, 3: 0},
False,
{1: 1, 2: 0, 3: 0},
),
({}, False, {}),
(
{1: 0, 2: -2, 3: -2},
True,
{1: 0, 2: 0.5, 3: 0.5},
),
],
)
def test_preprocess_scores_linearly(scores, do_negation, expected):
result = _preprocess_scores_linearly(scores, do_negation)
for k, v in expected.items():
assert result[k] == pytest.approx(v)


@pytest.mark.parametrize(
"scores, do_negation, divide, divide_factor, expected",
[
(
{1: 2, 2: 2, 3: 2},
False,
False,
None,
{1: 1 / 3, 2: 1 / 3, 3: 1 / 3},
),
(
{1: 1, 2: 0, 3: 0},
False,
False,
None,
{1: 0.5761168847658291, 2: 0.21194155761708544, 3: 0.21194155761708544},
),
(
{1: 1, 2: 0, 3: 0},
False,
True,
0.5,
{1: 0.7869860421615985, 2: 0.10650697891920075, 3: 0.10650697891920075},
),
(
{1: -1, 2: -1, 3: 0},
True,
True,
0.5,
{1: 0.4683105308334812, 2: 0.4683105308334812, 3: 0.06337893833303762},
),
],
)
def test_preprocess_scores_softmax(
scores, do_negation, divide, divide_factor, expected
):
result = _preprocess_scores_softmax(scores, do_negation, divide, divide_factor)
for k, v in expected.items():
assert result[k] == pytest.approx(v)


def test_preprocess_scores_softmax_exception():
with pytest.raises(AssertionError):
_preprocess_scores_softmax({1: 2, 2: 3, 3: 4}, False, True, None)
26 changes: 26 additions & 0 deletions ChemSpaceAL/tests/test_initialize_workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import tempfile
from unittest.mock import patch
from .. import InitializeWorkspace as iw


def test_create_default_folders():
# Using a temporary directory for testing
with tempfile.TemporaryDirectory() as tempdir:
iw.create_folders(base_path=tempdir)

# Check if the main folders are created
assert os.path.exists(os.path.join(tempdir, "1_Pretraining"))
assert os.path.exists(os.path.join(tempdir, "2_Generation"))

# Check if subfolders are created
assert os.path.exists(os.path.join(tempdir, "1_Pretraining", "datasets"))
# ... (add more assertions for other subfolders)
assert isinstance(iw.FOLDER_STRUCTURE, dict)


@patch("builtins.input", return_value="Y")
def test_create_folders_without_base_path(mock_input):
with tempfile.TemporaryDirectory() as tempdir:
os.chdir(tempdir) # Change working directory
iw.create_folders()
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# ChemSpaceAL
ChemSpaceAL: An Efficient Active Learning Methodology Applied to Protein- Specific Molecular Generation
=======================================

## An Efficient Active Learning Methodology Applied to Protein- Specific Molecular Generation

<p align="center">
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![codecov](https://codecov.io/gh/batistagroup/ChemSpaceAL/graph/badge.svg?token=ROJSISYJWC)](https://codecov.io/gh/batistagroup/ChemSpaceAL)

![A description of the active learning methodology](media/toc_figure.jpg)
27 changes: 27 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
coverage:
precision: 2
round: down
range: "0...90"

status:
project: yes
patch: yes
changes: no

comment:
layout: "header, diff, components"

component_management:
default_rules:
statuses:
- type: patch
target: auto
individual_components:
- component_id: module_iw
name: InitializeWorkspace
paths:
- "ChemSpaceAL/InitializeWorkspace.py"
- component_id: module_al_construct
name: AL Training Set Construction
paths:
- "ChemSpaceAL/ALConstruction.py"
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
install_requires=required,
# install_requires=required,
# install_requires=[
# # "pytest"
# ]
python_requires=">=3.10",
)
16 changes: 0 additions & 16 deletions tests/test_config.py

This file was deleted.

0 comments on commit 20af783

Please sign in to comment.