Skip to content

Commit

Permalink
Add modules.py
Browse files Browse the repository at this point in the history
Additional:
    1. PointNetLit is renamed to PointLit to avoid confusion that it can
      be used only with PointNet.
    2. Necessary changes in unit tests and docs due to 1.
  • Loading branch information
adosar committed Jul 3, 2024
1 parent 24891da commit f5dfacc
Show file tree
Hide file tree
Showing 38 changed files with 610 additions and 519 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pylint
pip install .
- name: Run pylint
run: pylint src/aidsorb/
5 changes: 5 additions & 0 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install .
- name: Run unit tests
run: python -m unittest
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center">
<img alt="Logo" src="https://raw.githubusercontent.com/adosar/trial/master/docs/source/images/aidsorb_logo_light.svg"/>
<img alt="AIdsorb logo" src="https://raw.githubusercontent.com/adosar/aidsorb/master/docs/source/images/aidsorb_logo_light.svg" width=50%/>
</h1>

<h4 align="center">
Expand All @@ -13,17 +13,13 @@

**AIdsorb** is a Python package for **deep learning on molecular point clouds**.

**AIdsorb** aims to provide a **fast, easy-to-use and reproduce** interface for:
This package aims to provide a **fast, easy-to-use and reproduce** interface for:

- 📥 **Creating molecular point clouds**

- 🤖 **Training DL algorithms on molecular point clouds**


<p align="center">
<img alt="Point cloud" src="https://raw.githubusercontent.com/adosar/aidsorb/master/docs/source/images/pcd.gif" width="25%"/>
</p>

## ⚙️ Installation
> [!IMPORTANT]
> It is strongly recommended to **perform the installation inside a virtual environment**.
Expand All @@ -44,6 +40,11 @@ Here is a summary of what you can do from the command line:
aidsorb visualize path/to/structure
```

<p align="center">
<img alt="Point cloud" src="https://raw.githubusercontent.com/adosar/aidsorb/master/docs/source/images/pcd.gif" width="25%"/>
</p>


2. Create and prepare point clouds:
```bash
aidsorb create path/to/inp path/to/out # Create point clouds
Expand Down
6 changes: 3 additions & 3 deletions docs/source/_autosummary/aidsorb.data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
============

.. automodule:: aidsorb.data
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/_autosummary/aidsorb.datamodules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
===================

.. automodule:: aidsorb.datamodules
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/_autosummary/aidsorb.litmodels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
=================

.. automodule:: aidsorb.litmodels
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/_autosummary/aidsorb.models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
==============

.. automodule:: aidsorb.models
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/_autosummary/aidsorb.modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
aidsorb.modules
===============

.. automodule:: aidsorb.modules
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/_autosummary/aidsorb.transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
==================

.. automodule:: aidsorb.transforms
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/_autosummary/aidsorb.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
=============

.. automodule:: aidsorb.utils
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/_autosummary/aidsorb.visualize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
=================

.. automodule:: aidsorb.visualize
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/_templates/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{{ underline }}

.. automodule:: {{ fullname }}
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
24 changes: 11 additions & 13 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@
:octicon:`book` API Documentation
=================================

..
.. automodule:: aidsorb
:members:
:undoc-members:
:show-inheritance:

..
.. rubric:: Submodules

..
.. autosummary::
:nosignatures:
:template: module.rst
:toctree: _autosummary
:nosignatures:
:template: module.rst
:toctree: _autosummary

aidsorb.utils
aidsorb.visualize
aidsorb.data
aidsorb.datamodules
aidsorb.transforms
aidsorb.models
aidsorb.litmodels
aidsorb.utils
aidsorb.visualize
aidsorb.data
aidsorb.datamodules
aidsorb.transforms
aidsorb.modules
aidsorb.models
aidsorb.litmodels
Binary file modified docs/source/auto_examples/auto_examples_jupyter.zip
Binary file not shown.
Binary file modified docs/source/auto_examples/auto_examples_python.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/source/auto_examples/resume.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"After training a model, you might want to test its performance, make\npredictions or do whatever you want with it, such as continue training.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>This example assummes:\n * [PyTorch Lightning checkpoints](https://lightning.ai/docs/pytorch/stable/common/checkpointing_basic.html#lightningmodule-from-checkpoint)\n are enabled during training.\n * Training was performed with AIdsorb :doc:`../cli` or `AIdsorb +\n PyTorch Lightning <aidsorb_with_pytorch_and_lightning>`.</p></div>\n\n"
"After training a model, you might want to test its performance, make\npredictions or do whatever you want with it.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>This example assummes:\n * [PyTorch Lightning checkpoints](https://lightning.ai/docs/pytorch/stable/common/checkpointing_basic.html#lightningmodule-from-checkpoint)\n are enabled during training.\n * Training was performed with AIdsorb :doc:`../cli` or `AIdsorb +\n PyTorch Lightning <aidsorb_with_pytorch_and_lightning>`.</p></div>\n\n"
]
},
{
Expand All @@ -22,7 +22,7 @@
},
"outputs": [],
"source": [
"import yaml\nimport torch\nimport lightning as L\nfrom lightning.pytorch.cli import LightningCLI, LightningArgumentParser\nfrom aidsorb.datamodules import PCDDataModule\nfrom aidsorb.litmodels import PointNetLit\nfrom aidsorb.visualize import draw_pcd"
"import yaml\nimport torch\nimport lightning as L\nfrom lightning.pytorch.cli import LightningCLI, LightningArgumentParser\nfrom aidsorb.datamodules import PCDDataModule\nfrom aidsorb.litmodels import PointLit\nfrom aidsorb.visualize import draw_pcd"
]
},
{
Expand All @@ -40,7 +40,7 @@
},
"outputs": [],
"source": [
"def load_from_config(filename):\n r\"\"\"\n Load configuration, trainer, model and datamodule from a ``.yaml`` file.\n\n .. note::\n You are responsible for restoring the model's state (the weights of the model).\n\n Parameters\n ----------\n filename: str\n Absolute or relative path to the ``.yaml`` configuration file.\n \"\"\"\n with open(filename, 'r') as f:\n config_dict = yaml.safe_load(f)\n\n config_dict['trainer']['logger'] = False\n del config_dict['seed_everything'], config_dict['ckpt_path']\n\n parser = LightningArgumentParser()\n parser.add_class_arguments(PointNetLit, 'model', fail_untyped=False)\n parser.add_class_arguments(PCDDataModule, 'data', fail_untyped=False)\n parser.add_class_arguments(L.Trainer, 'trainer', fail_untyped=False)\n config = parser.parse_object(config_dict)\n objects = parser.instantiate_classes(config)\n\n return config, objects.trainer, objects.model, objects.data"
"def load_from_config(filename):\n r\"\"\"\n Load configuration, trainer, model and datamodule from a ``.yaml`` file.\n\n .. note::\n You are responsible for restoring the model's state (the weights of the model).\n\n Parameters\n ----------\n filename: str\n Absolute or relative path to the ``.yaml`` configuration file.\n \"\"\"\n with open(filename, 'r') as f:\n config_dict = yaml.safe_load(f)\n\n config_dict['trainer']['logger'] = False\n del config_dict['seed_everything'], config_dict['ckpt_path']\n\n parser = LightningArgumentParser()\n parser.add_class_arguments(PointLit, 'model', fail_untyped=False)\n parser.add_class_arguments(PCDDataModule, 'data', fail_untyped=False)\n parser.add_class_arguments(L.Trainer, 'trainer', fail_untyped=False)\n\n config = parser.parse_object(config_dict)\n objects = parser.instantiate_classes(config)\n\n return config, objects.trainer, objects.model, objects.data"
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions docs/source/auto_examples/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# %%
# After training a model, you might want to test its performance, make
# predictions or do whatever you want with it, such as continue training.
# predictions or do whatever you want with it.
#
# .. note::
# This example assummes:
Expand All @@ -20,7 +20,7 @@
import lightning as L
from lightning.pytorch.cli import LightningCLI, LightningArgumentParser
from aidsorb.datamodules import PCDDataModule
from aidsorb.litmodels import PointNetLit
from aidsorb.litmodels import PointLit
from aidsorb.visualize import draw_pcd

# %%
Expand Down Expand Up @@ -53,9 +53,10 @@ def load_from_config(filename):
del config_dict['seed_everything'], config_dict['ckpt_path']

parser = LightningArgumentParser()
parser.add_class_arguments(PointNetLit, 'model', fail_untyped=False)
parser.add_class_arguments(PointLit, 'model', fail_untyped=False)
parser.add_class_arguments(PCDDataModule, 'data', fail_untyped=False)
parser.add_class_arguments(L.Trainer, 'trainer', fail_untyped=False)

config = parser.parse_object(config_dict)
objects = parser.instantiate_classes(config)

Expand Down
27 changes: 14 additions & 13 deletions docs/source/auto_examples/resume.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Coming back after model training
.. GENERATED FROM PYTHON SOURCE LINES 7-17
After training a model, you might want to test its performance, make
predictions or do whatever you want with it, such as continue training.
predictions or do whatever you want with it.

.. note::
This example assummes:
Expand All @@ -44,7 +44,7 @@ predictions or do whatever you want with it, such as continue training.
import lightning as L
from lightning.pytorch.cli import LightningCLI, LightningArgumentParser
from aidsorb.datamodules import PCDDataModule
from aidsorb.litmodels import PointNetLit
from aidsorb.litmodels import PointLit
from aidsorb.visualize import draw_pcd
Expand All @@ -60,7 +60,7 @@ with the same settings as in the ``.yaml`` configuration file. For more
information 👉 `here
<https://github.com/Lightning-AI/pytorch-lightning/discussions/10363#discussioncomment-2326235>`_.

.. GENERATED FROM PYTHON SOURCE LINES 36-64
.. GENERATED FROM PYTHON SOURCE LINES 36-65
.. code-block:: Python
Expand All @@ -84,29 +84,30 @@ information 👉 `here
del config_dict['seed_everything'], config_dict['ckpt_path']
parser = LightningArgumentParser()
parser.add_class_arguments(PointNetLit, 'model', fail_untyped=False)
parser.add_class_arguments(PointLit, 'model', fail_untyped=False)
parser.add_class_arguments(PCDDataModule, 'data', fail_untyped=False)
parser.add_class_arguments(L.Trainer, 'trainer', fail_untyped=False)
config = parser.parse_object(config_dict)
objects = parser.instantiate_classes(config)
return config, objects.trainer, objects.model, objects.data
.. GENERATED FROM PYTHON SOURCE LINES 65-68
.. GENERATED FROM PYTHON SOURCE LINES 66-69
.. code-block:: Python
config, trainer, litmodel, dm = load_from_config('path/to/logs/config.yaml')
.. GENERATED FROM PYTHON SOURCE LINES 71-73
.. GENERATED FROM PYTHON SOURCE LINES 72-74
Restoring model's state
-----------------------

.. GENERATED FROM PYTHON SOURCE LINES 73-77
.. GENERATED FROM PYTHON SOURCE LINES 74-78
.. code-block:: Python
Expand All @@ -115,7 +116,7 @@ Restoring model's state
model_weights = {k: v for k, v in ckpt['state_dict'].items() if k.startswith('model.')}
.. GENERATED FROM PYTHON SOURCE LINES 78-84
.. GENERATED FROM PYTHON SOURCE LINES 79-85
.. code-block:: Python
Expand All @@ -126,7 +127,7 @@ Restoring model's state
litmodel(x);
.. GENERATED FROM PYTHON SOURCE LINES 85-89
.. GENERATED FROM PYTHON SOURCE LINES 86-90
.. code-block:: Python
Expand All @@ -135,7 +136,7 @@ Restoring model's state
litmodel.load_state_dict(model_weights)
.. GENERATED FROM PYTHON SOURCE LINES 90-96
.. GENERATED FROM PYTHON SOURCE LINES 91-97
.. code-block:: Python
Expand All @@ -146,12 +147,12 @@ Restoring model's state
.. GENERATED FROM PYTHON SOURCE LINES 97-99
.. GENERATED FROM PYTHON SOURCE LINES 98-100
Measure performance and make predictions
----------------------------------------

.. GENERATED FROM PYTHON SOURCE LINES 99-103
.. GENERATED FROM PYTHON SOURCE LINES 100-104
.. code-block:: Python
Expand All @@ -160,7 +161,7 @@ Measure performance and make predictions
trainer.test(litmodel, dm)
.. GENERATED FROM PYTHON SOURCE LINES 104-110
.. GENERATED FROM PYTHON SOURCE LINES 105-111
.. code-block:: Python
Expand Down
Binary file modified docs/source/auto_examples/resume_codeobj.pickle
Binary file not shown.
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
'examples_dirs': 'examples', # path to your example scripts
'gallery_dirs': 'auto_examples', # path to where to save gallery generated output
'ignore_pattern': r'{/.*\.xyz, /.*\.cif}',
'image_scrapers': (plotly_sg_scraper,),
}

intersphinx_mapping = {
Expand Down
1 change: 1 addition & 0 deletions docs/source/download/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
seed_everything: 1 # Workers are seeded as well.

# Here you setup the Trainer.
# https://lightning.ai/docs/pytorch/stable/common/trainer.html#trainer-class-api
trainer:
max_epochs: 2
accelerator: 'gpu'
Expand Down
Loading

0 comments on commit f5dfacc

Please sign in to comment.