Skip to content

Commit

Permalink
General improvemts
Browse files Browse the repository at this point in the history
- All files are pyflakes and black clean.
- Improved logging for models.kernelridge, features.gaussian and
  features.coulombmatrix.
  • Loading branch information
muammar committed Jan 18, 2020
1 parent 823f188 commit 96453bc
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
3 changes: 1 addition & 2 deletions bin/ml4chem
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
import time
import click
import os
import sys
Expand Down Expand Up @@ -39,7 +38,7 @@ def main(**args):
elif args["plot"].lower() in dim_visualization:
method = args["plot"]
backend = args["backend"]
plt = plot_atomic_features(_file, method=method, backend=backend)
plot_atomic_features(_file, method=method, backend=backend)


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions ml4chem/data/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from ase import Atom, Atoms
from ase.calculators.calculator import Calculator
from ase.io import Trajectory, write
from ase.io import Trajectory


# to get the total energy
Expand Down Expand Up @@ -68,7 +68,7 @@ class SinglePointCalculator(Calculator):
"""A SinglePointCalculator class
This class creates a fake calculator that is used to populate
calc.results dictionaries in ASE objects.
calc.results dictionaries in ASE objects.
Parameters
----------
Expand Down Expand Up @@ -109,14 +109,14 @@ def get_forces(atoms):
Returns
-------
forces
The atomic force of the molecule.
The atomic force of the molecule.
"""
return atoms.calc.results["forces"]


def ani_to_ase(hdf5file, data_keys, trajfile=None):
"""ANI to ASE
Parameters
----------
hdf5file : hdf5, list
Expand Down
8 changes: 1 addition & 7 deletions ml4chem/features/coulombmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import os
import time
import torch
import pandas as pd
from collections import OrderedDict
from dscribe.descriptors import CoulombMatrix as CoulombMatrixDscribe
Expand Down Expand Up @@ -210,15 +209,10 @@ def calculate(self, images=None, purpose="training", data=None, svm=False):
stacked_features += intermediate
del intermediate

scheduler_time = time.time() - initial_time
# scheduler_time = time.time() - initial_time

# dask.distributed.wait(stacked_features)

h, m, s = convert_elapsed_time(scheduler_time)
logger.info(
"... finished in {} hours {} minutes {:.2f}" " seconds.".format(h, m, s)
)

logger.info("")

if self.preprocessor is not None:
Expand Down
7 changes: 5 additions & 2 deletions ml4chem/features/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ def calculate(self, images=None, purpose="training", data=None, svm=False):

self.print_fingerprint_params(self.GP)

symbol = data.unique_element_symbols[purpose][0]
sample = np.zeros(len(self.GP[symbol]))

self.dimension = len(sample)

preprocessor = Preprocessing(self.preprocessor, purpose=purpose)
preprocessor.set(purpose=purpose)

Expand Down Expand Up @@ -322,8 +327,6 @@ def calculate(self, images=None, purpose="training", data=None, svm=False):
# To take advantage of dask_ml we need to convert our numpy array
# into a dask array.
logger.info("Converting features to dask array...")
symbol = data.unique_element_symbols[purpose][0]
sample = np.zeros(len(self.GP[symbol]))
stacked_features = [
da.from_delayed(lazy, dtype=float, shape=sample.shape)
for lazy in stacked_features
Expand Down
9 changes: 4 additions & 5 deletions ml4chem/models/autoencoders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dask
import datetime
import inspect
import logging
import time
import torch
Expand Down Expand Up @@ -1214,7 +1213,7 @@ class Annealer(object):
"""Annealing class
Based on on https://arxiv.org/abs/1903.10145.
Parameters
----------
warm_up : int, optional
Expand All @@ -1236,12 +1235,12 @@ def __init__(self, warm_up=50, step=50, n_cycles=5):

def update(self, epoch):
"""Update annealing value
Parameters
----------
epoch : int
Epoch on the training process.
Epoch on the training process.
Returns
-------
annealing
Expand Down
11 changes: 10 additions & 1 deletion ml4chem/models/kernelridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ def get_kernel_matrix(self, feature_space, reference_features, purpose):
kernel_matrix = []

for c, chunk in enumerate(chunks):
print("Chunk", c)
chunk_initial_time = time.time()
logger.info(" Computing kernel functions for chunk {}...".format(c))
intermediates = []

if isinstance(chunk, dict) is False:
chunk = OrderedDict(chunk)

Expand Down Expand Up @@ -323,6 +325,13 @@ def get_kernel_matrix(self, feature_space, reference_features, purpose):
intermediates.append(kernel)
kernel_matrix += dask.compute(intermediates, scheduler=self.scheduler)[0]
del intermediates

chunk_final_time = time.time() - chunk_initial_time
h, m, s = convert_elapsed_time(chunk_final_time)
logger.info(
" ...finished in {} hours {} minutes {:.2f} "
"seconds.".format(h, m, s)
)
# dask.distributed.wait(kernel_matrix)

del reference_features
Expand Down
2 changes: 0 additions & 2 deletions ml4chem/models/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ def VAELoss(

loss = []

dim = 1

if annealing is None:
annealing = 1.0

Expand Down
2 changes: 1 addition & 1 deletion ml4chem/models/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from collections import OrderedDict
from ml4chem.metrics import compute_rmse
from ml4chem.utils import convert_elapsed_time, dynamic_import, get_chunks, lod_to_list
from ml4chem.utils import dynamic_import, get_chunks, lod_to_list
from ml4chem.optim.handler import get_optimizer, get_lr_scheduler

# Setting precision and starting logger object
Expand Down

0 comments on commit 96453bc

Please sign in to comment.