Skip to content

Commit

Permalink
Added github action on github master branch.
Browse files Browse the repository at this point in the history
Change tolerance in test
Change type hints to be compatible with python <3.9
  • Loading branch information
renzph committed Apr 1, 2024
2 parents bf69345 + b1a23ab commit 16b7596
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 8 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Tests (dev)

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
40 changes: 40 additions & 0 deletions .github/workflows/test_master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Tests (master)

on:
push:
branches: [ "master"]
pull_request:
branches: [ "master"]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Fréchet ChemNet Distance
![PyPI](https://img.shields.io/pypi/v/fcd)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fcd)
![Tests (master)](https://github.com/bioinf-jku/fcd/actions/workflows/test-package_master.yml/badge.svg?branch=dev)
![Tests (dev)](https://github.com/bioinf-jku/fcd/actions/workflows/test-package_dev.yml/badge.svg?branch=dev)
![PyPI - Downloads](https://img.shields.io/pypi/dm/fcd)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/bioinf-jku/fcd)
![GitHub release date](https://img.shields.io/github/release-date/bioinf-jku/fcd)
![GitHub](https://img.shields.io/github/license/bioinf-jku/fcd)


Code for the paper "Fréchet ChemNet Distance: A Metric for Generative Models for Molecules in Drug Discovery"
[JCIM](https://pubs.acs.org/doi/10.1021/acs.jcim.8b00234) /
Expand Down
4 changes: 2 additions & 2 deletions fcd/fcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_predictions(
smiles_list: List[str],
batch_size: int = 128,
n_jobs: int = 1,
device: str | None = None,
device: Optional[str] = None,
) -> np.ndarray:
"""Calculate Chemnet activations
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_predictions(
return np.row_stack(chemnet_activations)


def get_fcd(smiles1: List[str], smiles2: List[str], model: nn.Module | None = None, device=None) -> float:
def get_fcd(smiles1: List[str], smiles2: List[str], model: Optional[nn.Module] = None, device=None) -> float:
"""Calculate FCD between two sets of Smiles
Args:
Expand Down
4 changes: 2 additions & 2 deletions fcd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import warnings
from contextlib import contextmanager
from multiprocessing import Pool
from typing import List
from typing import List, Optional

import numpy as np
import torch
Expand Down Expand Up @@ -43,7 +43,7 @@ def tokenize(smiles: str) -> List[str]:
return tok_smile


def get_one_hot(smiles: str, pad_len: int | None = None) -> np.ndarray:
def get_one_hot(smiles: str, pad_len: Optional[int] = None) -> np.ndarray:
"""Generate one-hot representation of a Smiles string.
Args:
Expand Down
8 changes: 4 additions & 4 deletions test/test_fcd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
import numpy as np
import pytest
from pytest import approx

from fcd import get_fcd
from fcd.utils import get_one_hot, SmilesDataset
from pytest import approx
from fcd.utils import SmilesDataset, get_one_hot


class TestFCD:
Expand All @@ -12,7 +12,7 @@ def test_random_smiles_cpu(self):
smiles_list2 = ["ISi#()", "Si#()+", "#()+-", "()+-1"]
target = 8.8086
fcd = get_fcd(smiles_list1, smiles_list2, device="cpu")
assert fcd == approx(target, abs=1e-3)
assert fcd == approx(target, abs=1e-2)

def test_random_smiles_gpu(self):
# Skip test if CUDA is not available
Expand Down

0 comments on commit 16b7596

Please sign in to comment.