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

Version 0.1.0 #21

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5d2d2e3
Improved forward pass efficiency and general enhancements
muammar Apr 12, 2020
69fb154
Fixed prediction for new format.
muammar Apr 13, 2020
d21cf8d
Improvements to Gaussian class and new model for retention times.
muammar Apr 29, 2020
58b14a1
G2 symmetry function are vectorized.
muammar Jul 29, 2020
cdd971f
Merge branch 'master' into 0.1.0
muammar Aug 12, 2020
8e3dc78
calculate_G3 is now "vectorized" to help compute forces.
muammar Aug 12, 2020
ae532cb
Gaussian class now can set requires_grad to True for training forces.
muammar Aug 13, 2020
5f913f2
More changes to activate force training.
muammar Aug 14, 2020
136cc5f
AtomicMSELoss is now a class with a __call__ method.
muammar Aug 21, 2020
fa5e842
MinMaxScaler pure pytorch implementation and respective changes.
muammar Sep 17, 2020
f3e66da
Checkpoint.
muammar Sep 30, 2020
156251c
Merge branch 'master' into 0.1.0
muammar Oct 11, 2020
5c63474
Merge branch 'master' into 0.1.0
muammar Jan 19, 2021
dbdf626
fix try/except and black cleaned up.
muammar Jan 19, 2021
e849bf8
Fix Gaussian features.
muammar Jan 19, 2021
8635bc6
Commit fixes training, and general improvement.
May 15, 2021
e47ccb5
Updated parity() function in visualization
muammar Sep 1, 2021
5411556
Update visualization.py
muammar Sep 2, 2021
c2b43a3
Remove unused imports.
muammar Sep 2, 2021
adfdf16
Code is able to run in single core.
muammar Feb 26, 2022
3c98466
Pyflakes cleaning.
muammar Feb 26, 2022
dc658ca
Fixed feature computation on single core.
muammar Apr 9, 2022
c199cee
Blacked and some minimal improvements.
muammar May 20, 2023
bed710f
Updated environment.
muammar Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improved forward pass efficiency and general enhancements
These changes improve efficiency and represent a step forward for GPU
training as well as the addition of force training.

- Updated reference to cite ML4Chem.
- Bumped version.
- Dscribe module is optional and not required.
- `backends.operations` renamed to `backends.oper`.  
- `atomistic.models.base`: added new `feature_preparation` function that
  prepares data in a way that vectorization is favored.
- `models.merger` the merger class now uses `torch.nn.ModuleList`
  instead of a plain list.
- `atomistic.models.neuralnetwork`:
    * `forward` is more efficient.
    * All data is scattered once to avoid problems with Dask messing up
      some tensors.
    * More steps forward to force training.
- `data.handler`:
    - New `get_largest_number_atoms` function for new vectorized forward
      improvements and avoid breaking compatibility.
    - New `target_keys` attribute that can be used to set any name for
      targets.
  • Loading branch information
muammar committed Apr 12, 2020
commit 5d2d2e3d42eb18129d2d73a07fb53dbce7f8c584
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ very nice.
If you find this software useful, please use this bibtex to cite it:

```
@article{El_Khatib2020,
author = "Muammar El Khatib and Wibe de Jong",
title = "{ML4Chem: A Machine Learning Package for Chemistry and Materials Science}",
year = "2020",
month = "3",
url = "https://chemrxiv.org/articles/ML4Chem_A_Machine_Learning_Package_for_Chemistry_and_Materials_Science/11952516",
doi = "10.26434/chemrxiv.11952516.v1"
@article{Elkhatib2020ml4chem,
title={ML4Chem: A Machine Learning Package for Chemistry and Materials Science},
author={Muammar El Khatib and Wibe A de Jong},
year={2020},
eprint={2003.13388},
archivePrefix={arXiv},
primaryClass={physics.chem-ph}
}
```

Expand Down
1 change: 1 addition & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dependencies:
- sphinxcontrib-bibtex
- sphinxcontrib-inlinesyntaxhighlight
- m2r
- pip_install: True
2 changes: 1 addition & 1 deletion ml4chem/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.9"
__version__ = "0.1.0-dev"
11 changes: 9 additions & 2 deletions ml4chem/atomistic/features/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from ml4chem.atomistic.features.autoencoders import LatentFeatures
from ml4chem.atomistic.features.cartesian import Cartesian
from ml4chem.atomistic.features.coulombmatrix import CoulombMatrix
from ml4chem.atomistic.features.gaussian import Gaussian

__all__ = ["LatentFeatures", "Cartesian", "CoulombMatrix", "Gaussian"]

__all__ = ["LatentFeatures", "Cartesian", "Gaussian"]

try:
from ml4chem.atomistic.features.coulombmatrix import CoulombMatrix

__all__.append("CoulombMatrix")
except ModuleNotFoundError:
pass
64 changes: 64 additions & 0 deletions ml4chem/atomistic/models/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import types
import torch
from ml4chem.atomistic import Potentials
from abc import ABC, abstractmethod
from collections import OrderedDict


class DeepLearningModel(ABC):
Expand Down Expand Up @@ -56,3 +59,64 @@ def checkpoint_save(self, epoch, model, label=None, checkpoint=None, path=""):
Potentials.save(model=model, label=label, path=path)
elif epoch % checkpoint == 0:
Potentials.save(model=model, label=label, path=path)

def feature_preparation(self, features, data):
"""Feature preparation

This function takes features and rearrange the data to operate with a
DeepLearning class.

Parameters
----------

"""
purpose = "training"
data.get_largest_number_atoms(purpose)

rearrengements = []
conditions = []
if isinstance(features, (list, types.GeneratorType)):
for chunk in features:
chunk = OrderedDict(chunk)
rearrange = {
symbol: [] for symbol in data.unique_element_symbols[purpose]
}

for _, values in chunk.items():
image = {}
for symbol, features_ in values:
if symbol not in image.keys():
image[symbol] = []
image[symbol].append(features_)

for symbol in data.unique_element_symbols[purpose]:
tensors = image.get(symbol)

if tensors == None:
tensors = [torch.zeros(self.input_dimension)]

tensors = torch.stack(tensors)

tensor_size = tensors.size()[0]
if tensor_size < data.largest_number_atoms[symbol]:

diff = data.largest_number_atoms[symbol] - tensor_size
expand = torch.zeros(diff, self.input_dimension)
tensors = torch.cat([tensors, expand])

rearrange[symbol].append(tensors)

rearrange = {
symbol: torch.stack(tensors)
for symbol, tensors in rearrange.items()
}

condition = {}

for symbol, tensors in rearrange.items():
condition[symbol] = (tensors.sum(dim=2) != 0).float()

rearrengements.append(rearrange)
conditions.append(condition)

return rearrengements, conditions
2 changes: 1 addition & 1 deletion ml4chem/atomistic/models/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def AtomicMSELoss(outputs, targets, atoms_per_image, uncertainty=None):
outputs : tensor
Outputs of the model.
targets : tensor
Expected value of outputs.
Dictionary of tensors.
atoms_per_image : tensor
A tensor with the number of atoms per image.
uncertainty : tensor, optional
Expand Down
2 changes: 1 addition & 1 deletion ml4chem/atomistic/models/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def name(cls):

def __init__(self, models):
super(ModelMerger, self).__init__()
self.models = models
self.models = torch.nn.ModuleList(models)

def forward(self, X, models):
"""Forward propagation
Expand Down
Loading