Skip to content

Commit 8c2fd41

Browse files
authored
Merge pull request #20 from ChEB-AI/fix/inference-dependencies
move networkx call to read_data / reformatting with ruff
2 parents 21e4378 + cd2655d commit 8c2fd41

22 files changed

Lines changed: 147 additions & 64 deletions

.github/workflows/black.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Set up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.10' # or any version your project uses
16+
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install black==25.1.0 ruff==0.12.2
21+
22+
- name: Run Black
23+
run: black --check .
24+
25+
- name: Run Ruff (no formatting)
26+
run: ruff check . --no-fix

.pre-commit-config.yaml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
repos:
2-
#- repo: https://github.com/PyCQA/isort
3-
# rev: "5.12.0"
4-
# hooks:
5-
# - id: isort
62
- repo: https://github.com/psf/black
7-
rev: "22.10.0"
3+
rev: "25.1.0"
84
hooks:
9-
- id: black
5+
- id: black
6+
- id: black-jupyter # for formatting jupyter-notebook
7+
8+
- repo: https://github.com/pycqa/isort
9+
rev: 5.13.2
10+
hooks:
11+
- id: isort
12+
name: isort (python)
13+
args: ["--profile=black"]
14+
15+
- repo: https://github.com/asottile/seed-isort-config
16+
rev: v2.2.0
17+
hooks:
18+
- id: seed-isort-config
19+
20+
- repo: https://github.com/pre-commit/pre-commit-hooks
21+
rev: v4.6.0
22+
hooks:
23+
- id: check-yaml
24+
- id: end-of-file-fixer
25+
- id: trailing-whitespace
26+
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.12.2
29+
hooks:
30+
- id: ruff
31+
args: [--fix]

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Graph-based models for molecular property prediction and ontology classification
77

88
## Installation
99

10-
To install this repository, download it and run
10+
To install this repository, download it and run
1111

1212
```bash
1313
pip install .
@@ -30,7 +30,7 @@ Replace:
3030
- `${TORCH}` with a PyTorch version (e.g., `2.6.0`; for later versions, check first if they are compatible with torch_scatter and torch_geometric)
3131
- `${CUDA}` with e.g. `cpu`, `cu118`, or `cu121` depending on your system and CUDA version
3232

33-
If you already have `torch` installed, make sure that `torch_scatter` and `torch_geometric` are compatible with your
33+
If you already have `torch` installed, make sure that `torch_scatter` and `torch_geometric` are compatible with your
3434
PyTorch version and are installed with the same CUDA version.
3535

3636
For a full list of currently available PyTorch versions and CUDA compatibility, please refer to libraries' official documentation:
@@ -68,11 +68,10 @@ my_projects/
6868
### Ontology Prediction
6969

7070

71-
This example command trains a Residual Gated Graph Convolutional Network on the ChEBI50 dataset (see [wiki](https://github.com/ChEB-AI/python-chebai/wiki/Data-Management)).
72-
The dataset has a customizable list of properties for atoms, bonds and molecules that are added to the graph.
71+
This example command trains a Residual Gated Graph Convolutional Network on the ChEBI50 dataset (see [wiki](https://github.com/ChEB-AI/python-chebai/wiki/Data-Management)).
72+
The dataset has a customizable list of properties for atoms, bonds and molecules that are added to the graph.
7373
The list can be found in the `configs/data/chebi50_graph_properties.yml` file.
7474

7575
```bash
7676
python -m chebai fit --trainer=configs/training/default_trainer.yml --trainer.logger=configs/training/csv_logger.yml --model=../python-chebai-graph/configs/model/gnn_res_gated.yml --model.train_metrics=configs/metrics/micro-macro-f1.yml --model.test_metrics=configs/metrics/micro-macro-f1.yml --model.val_metrics=configs/metrics/micro-macro-f1.yml --data=../python-chebai-graph/configs/data/chebi50_graph_properties.yml --data.init_args.batch_size=128 --trainer.accumulate_grad_batches=4 --data.init_args.num_workers=10 --model.pass_loss_kwargs=false --data.init_args.chebi_version=241 --trainer.min_epochs=200 --trainer.max_epochs=200 --model.criterion=configs/loss/bce.yml
7777
```
78-

chebai_graph/models/gin_net.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import typing
2+
3+
import torch
4+
import torch.nn.functional as F
5+
import torch_geometric
16
from torch_scatter import scatter_add
27

38
from chebai_graph.models.graph import GraphBaseNet
4-
import torch_geometric
5-
import torch.nn.functional as F
6-
import torch
7-
import typing
89

910

1011
class AggregateMLP(torch.nn.Module):
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
1-
from chebai_graph.preprocessing.properties import *
1+
from chebai_graph.preprocessing.properties import (
2+
AtomAromaticity,
3+
AtomCharge,
4+
AtomChirality,
5+
AtomHybridization,
6+
AtomNumHs,
7+
AtomProperty,
8+
AtomType,
9+
BondAromaticity,
10+
BondInRing,
11+
BondProperty,
12+
BondType,
13+
MolecularProperty,
14+
MoleculeNumRings,
15+
MoleculeProperty,
16+
NumAtomBonds,
17+
RDKit2DNormalized,
18+
)
19+
20+
__all__ = [
21+
"AtomAromaticity",
22+
"AtomCharge",
23+
"AtomChirality",
24+
"AtomHybridization",
25+
"AtomNumHs",
26+
"AtomProperty",
27+
"AtomType",
28+
"BondAromaticity",
29+
"BondInRing",
30+
"BondProperty",
31+
"BondType",
32+
"MolecularProperty",
33+
"MoleculeNumRings",
34+
"MoleculeProperty",
35+
"NumAtomBonds",
36+
"RDKit2DNormalized",
37+
]

chebai_graph/preprocessing/collate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from typing import Dict
22

33
import torch
4+
from chebai.preprocessing.collate import RaggedCollator
45
from torch_geometric.data import Data as GeomData
56
from torch_geometric.data.collate import collate as graph_collate
6-
from chebai_graph.preprocessing.structures import XYGraphData
77

8-
from chebai.preprocessing.collate import RaggedCollator
8+
from chebai_graph.preprocessing.structures import XYGraphData
99

1010

1111
class GraphCollator(RaggedCollator):

chebai_graph/preprocessing/datasets/chebi.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ def _setup_properties(self):
9696
features = [row["features"] for row in raw_data]
9797

9898
# use vectorized version of encode function, apply only if value is present
99-
enc_if_not_none = lambda encode, value: (
100-
[encode(atom_v) for atom_v in value]
101-
if value is not None and len(value) > 0
102-
else None
103-
)
99+
def enc_if_not_none(encode, value):
100+
return (
101+
[encode(v) for v in value]
102+
if value is not None and len(value) > 0
103+
else None
104+
)
104105

105106
for property in self.properties:
106107
if not os.path.isfile(self.get_property_path(property)):
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from chebai_graph.preprocessing.datasets.chebi import GraphPropertiesMixIn
21
from chebai.preprocessing.datasets.pubchem import PubchemChem
32

3+
from chebai_graph.preprocessing.datasets.chebi import GraphPropertiesMixIn
4+
45

56
class PubChemGraphProperties(GraphPropertiesMixIn, PubchemChem):
67
pass

chebai_graph/preprocessing/properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from descriptastorus.descriptors import rdNormalizedDescriptors
77

88
from chebai_graph.preprocessing.property_encoder import (
9-
PropertyEncoder,
10-
IndexEncoder,
11-
OneHotEncoder,
129
AsIsEncoder,
1310
BoolEncoder,
11+
IndexEncoder,
12+
OneHotEncoder,
13+
PropertyEncoder,
1414
)
1515

1616

0 commit comments

Comments
 (0)