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

Py310 #242

Merged
merged 13 commits into from
May 27, 2024
1 change: 1 addition & 0 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
max-parallel: 3
matrix:
python-version:
- 3.10
- 3.8
- 3.7
os:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
defaults:
run:
shell: bash -l {0} # for conda command
env:
GIT_CLONE_PROTECTION_ACTIVE: false
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
Expand Down Expand Up @@ -48,7 +50,7 @@ jobs:
- name: Check mypy
run: |
conda activate gt4sd
python -m mypy src/gt4sd
python -m mypy src/gt4sd --show-traceback
- name: Run pytests
run: |
conda activate gt4sd
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Almost all pretrained models are also available via `gradio`-powered [web apps](

Currently `gt4sd` relies on:

- python>=3.7,<3.9
- pip>=19.1,<20.3
- python>=3.7,<=3.10
- pip==24.0

We are actively working on relaxing these, so stay tuned or help us with this by [contributing](./CONTRIBUTING.md) to the project.

Expand Down
5 changes: 3 additions & 2 deletions conda_cpu_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ channels:
- https://conda.anaconda.org/pyg
- https://conda.anaconda.org/conda-forge
dependencies:
- python>=3.7,<3.9
- pip>=19.1,<20.3
- setuptools==69.5.1
- python>=3.7,<3.11
- pip=24.0
- pytorch>=1.0,<=1.12.1
- cpuonly
- pytorch-scatter<=2.0.9=*cu102*
Expand Down
5 changes: 3 additions & 2 deletions conda_cpu_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ channels:
- https://conda.anaconda.org/pyg
- https://conda.anaconda.org/conda-forge
dependencies:
- python>=3.7,<3.9
- pip>=19.1,<20.3
- setuptools==69.5.1
- python>=3.7,<3.11
- pip=24.0
- pytorch>=1.0,<=1.12.1
- cpuonly
- pytorch-scatter<=2.0.9
Expand Down
5 changes: 3 additions & 2 deletions conda_gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ channels:
- https://conda.anaconda.org/pyg
- https://conda.anaconda.org/conda-forge
dependencies:
- python>=3.7,<3.9
- pip>=19.1,<20.3
- setuptools==69.5.1
- python>=3.7,<3.11
- pip=24.0
- pytorch>=1.0,<=1.12.1=*cu*
- pytorch-scatter<=2.0.9=*cu102*
- torchvision<=0.13.1=*cu*
Expand Down
8 changes: 4 additions & 4 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ flask==1.1.2
flask_login==0.5.0
# isort==5.7.0
licenseheaders==0.8.8
mypy==0.950
myst-parser==0.13.3
pytest==6.1.1
mypy>=1.0.0
myst-parser==1.0.0
pytest==6.2.5
pytest-cov==2.10.1
sphinx==3.4.3
sphinx>=5
sphinx-autodoc-typehints==1.11.1
jinja2<3.1.0
sphinx_rtd_theme==0.5.1
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pypi requirements
setuptools==69.5.1
accelerate>=0.12,<0.20.0
datasets>=1.11.0
diffusers<=0.6.0
Expand All @@ -11,12 +12,13 @@ gt4sd-molformer>=0.1.1
gt4sd-trainer-hf-pl>=0.0.2
keras>=2.3.1,<2.11.0
keybert>=0.7.0
markdown-it-py<3.0.0,>=2.2.0
markdown-it-py
minio==7.0.1
modlamp>=4.0.0
molgx>=0.22.0a1
nglview>=3.0.3
numpy>=1.16.5,<1.24.0
pandas<=2.0.3
protobuf<3.20
pyarrow>=8.0.0
pydantic>=1.7.3,<2.0.0
Expand All @@ -25,12 +27,13 @@ PyTDC==0.3.7
pytorch_lightning<=1.7.7
pyyaml>=5.4.1
rdkit>=2022.3.5
rdkit-stubs>=0.7
regex>=2.5.91
reinvent-chemistry==0.0.38
sacremoses>=0.0.41
scikit-learn>=1.0.0,<1.3.0
scikit-optimize>=0.8.1
scipy>=1.0.0
scipy>=1.0.0,<=1.11.0
sentencepiece>=0.1.95
sentence_transformers>1.0,<=2.2.2
sympy>=1.10.1
Expand Down
8 changes: 7 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,20 @@ ignore = E203, E501, W503
[mypy]
check_untyped_defs = True
plugins = pydantic.mypy
exclude = ^src/gt4sd/frameworks/gflownet/envs

[mypy-gt4sd.frameworks.gflownet.envs.*]
follow_imports = skip

[mypy-pytest.*]
ignore_missing_imports = True

[mypy-rdkit.*]
ignore_missing_imports = True

[mypy-rdkit-stubs.*]
ignore_errors = True

[mypy-setuptools.*]
ignore_missing_imports = True

Expand Down Expand Up @@ -141,7 +148,6 @@ ignore_missing_imports = True
[mypy-transformers.*]
ignore_missing_imports = True

# to avoid mypy from crashing (https://github.com/python/mypy/issues/11045)
[mypy-transformers.trainer]
check_untyped_defs = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def validate_output(self, sequences: List[Any]) -> Tuple[List[Any], List[int]]:
if isinstance(self.tokenizer.text_tokenizer, PolymerGraphTokenizer):
# Copolymer models require specific validation
return validate_molecules(
pattern_list=list(zip(*sequences))[0],
pattern_list=list(zip(*sequences))[0], # type: ignore
input_type=MoleculeFormat.copolymer,
)

Expand Down Expand Up @@ -1086,9 +1086,11 @@ def filter_substructures(
f"{keep} is not a valid SMILES/SELFIES. Instead substructure filtering "
f"based on sequence alone can be done and is set to: {self.text_filtering}"
)
if keep not in self.substructures_to_keep and not Chem.MolFromSmiles(
if keep not in self.substructures_to_keep and not Chem.MolFromSmiles( # type: ignore
self.target
).HasSubstructMatch(subs_mol):
).HasSubstructMatch(
subs_mol
):
logger.info(
f"{keep} could not be identified in SMILES/SELFIES on text level AND no "
"substructure match occurred, hence it will be ignored"
Expand Down Expand Up @@ -1120,7 +1122,7 @@ def filter_substructures(
sane = False
break
else:
if not mol.HasSubstructMatch(subs_mol):
if not mol.HasSubstructMatch(subs_mol): # type: ignore
# Desired substructure not found
sane = False
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ def filter_stubbed(
Tuple of tuples of length 2 with filtered, generated molecule and its properties.
"""

seed = Chem.MolFromSmiles(target)
seed = Chem.MolFromSmiles(target) # type: ignore

seed_atoms = len(list(seed.GetAtoms()))
seed_bonds = seed.GetNumBonds()
seed_atoms = len(list(seed.GetAtoms())) # type: ignore
seed_bonds = seed.GetNumBonds() # type: ignore

smis: List[str] = []
props: List[str] = []
for smi, prop in property_sequences:
if smi == "":
continue
try:
mol = Chem.MolFromSmiles(smi)
num_atoms = len(list(mol.GetAtoms()))
num_bonds = mol.GetNumBonds()
mol = Chem.MolFromSmiles(smi) # type: ignore
num_atoms = len(list(mol.GetAtoms())) # type: ignore
num_bonds = mol.GetNumBonds() # type: ignore

if num_atoms > (threshold * seed_atoms) and num_bonds > (
threshold * seed_bonds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(
targets: Dict[str, float],
property_predictors: Dict[str, PropertyPredictor],
representations: RepresentationsDict,
representation_order: List[str] = None,
representation_order: Optional[List[str]] = None,
scalers: Optional[Dict[str, Scaler]] = None,
weights: Optional[Dict[str, float]] = None,
custom_score_function: Optional[
Expand Down
20 changes: 12 additions & 8 deletions src/gt4sd/algorithms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from __future__ import annotations

import collections
from collections.abc import Hashable
import logging
import os
import shutil
Expand Down Expand Up @@ -233,7 +233,7 @@ def sample(self, number_of_items: int = 100) -> Iterator[S]:
try:
valid_item = self.configuration.validate_item(item)
# check if sample is hashable
if not isinstance(item, collections.Hashable):
if not isinstance(item, Hashable):
yield valid_item
item_set.add(str(index))
else:
Expand Down Expand Up @@ -623,9 +623,11 @@ def save_version_from_training_pipeline_arguments(
target_version,
)
filepaths_mapping = {
filename: source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
filename: (
source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
)
for filename, source_filepath in filepaths_mapping.items()
}
logger.info(f"Saving artifacts into {target_path}...")
Expand Down Expand Up @@ -713,9 +715,11 @@ def upload_version_from_training_pipeline_arguments(

# mapping between filenames and paths for a version.
filepaths_mapping = {
filename: source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
filename: (
source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
)
for filename, source_filepath in filepaths_mapping.items()
}

Expand Down
4 changes: 2 additions & 2 deletions src/gt4sd/algorithms/generation/diffusion/geodiff/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def visualize_2d_input(self, data: Data) -> None:
molSize = (450, 300)
drawer = MD2.MolDraw2DSVG(molSize[0], molSize[1])
drawer.DrawMolecule(mc)
drawer.FinishDrawing()
svg = drawer.GetDrawingText()
drawer.FinishDrawing() # type: ignore
svg = drawer.GetDrawingText() # type: ignore
display(SVG(svg.replace("svg:", "")))

def visualize_3d(self, mols_gen: List[Chem.Mol]) -> None:
Expand Down
10 changes: 5 additions & 5 deletions src/gt4sd/algorithms/generation/diffusion/geodiff/model/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
from typing import Any, Tuple, Union
from typing import Any, Tuple, Union, Optional

import torch
from diffusers.configuration_utils import ConfigMixin
Expand Down Expand Up @@ -127,13 +127,13 @@ def _forward(
bond_index: torch.Tensor,
bond_type: torch.Tensor,
batch: torch.Tensor,
edge_index: torch.Tensor = None,
edge_type: torch.Tensor = None,
edge_length: int = None,
edge_index: Optional[torch.Tensor] = None,
edge_type: Optional[torch.Tensor] = None,
edge_length: Optional[int] = None,
return_edges: bool = False,
extend_order: bool = True,
extend_radius: bool = True,
is_sidechain: bool = None,
is_sidechain: Optional[bool] = None,
) -> Tuple[Any, ...]:
"""Forward pass for edges features.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def set_seed(seed: int = 42) -> None:
"""
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available:
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed) # type:ignore


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def set_seed(seed: int = 42) -> None:
"""
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available:
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed) # type:ignore


Expand Down
2 changes: 1 addition & 1 deletion src/gt4sd/domains/materials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def validate_smiles(
for index, molecule in enumerate(molecules)
if molecule is not None and molecule != ""
]
return molecules, valid_ids
return molecules, valid_ids # type: ignore


def validate_selfies(
Expand Down
10 changes: 6 additions & 4 deletions src/gt4sd/frameworks/cgcnn/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import logging
import os
import random
from typing import Any, Callable, List, Tuple, Union
from typing import Any, Callable, List, Tuple, Union, Optional

import numpy as np
import torch
Expand All @@ -49,7 +49,7 @@ def get_train_val_test_loader(
dataset: torch.utils.data.Dataset,
collate_fn: Callable[[List[Any]], Any] = default_collate,
batch_size: int = 64,
train_ratio: float = None,
train_ratio: Optional[float] = None,
val_ratio: float = 0.1,
test_ratio: float = 0.1,
return_test: bool = False,
Expand Down Expand Up @@ -212,7 +212,9 @@ class GaussianDistance:
Unit: angstrom
"""

def __init__(self, dmin: float, dmax: float, step: float, var: float = None):
def __init__(
self, dmin: float, dmax: float, step: float, var: Optional[float] = None
):
"""
Args:
dmin: float
Expand Down Expand Up @@ -333,7 +335,7 @@ def __init__(
dmin: int = 0,
step: float = 0.2,
random_seed: int = 123,
atom_initialization: AtomCustomJSONInitializer = None,
atom_initialization: Optional[AtomCustomJSONInitializer] = None,
):
"""
Args:
Expand Down
Loading
Loading