Unverified Commit af50a84f authored by Gao, Xiang's avatar Gao, Xiang Committed by GitHub
Browse files

Document cache_aev (#84)

parent 83248cf1
...@@ -21,3 +21,4 @@ benchmark_xyz ...@@ -21,3 +21,4 @@ benchmark_xyz
/*.ipt /*.ipt
/*.params /*.params
/*.dat /*.dat
/tmp
\ No newline at end of file
...@@ -31,9 +31,9 @@ steps: ...@@ -31,9 +31,9 @@ steps:
- python examples/training-benchmark.py ./dataset/ani_gdb_s01.h5 # run twice to test if checkpoint is working - python examples/training-benchmark.py ./dataset/ani_gdb_s01.h5 # run twice to test if checkpoint is working
- python examples/energy_force.py - python examples/energy_force.py
- python examples/neurochem-test.py ./dataset/ani_gdb_s01.h5 - python examples/neurochem-test.py ./dataset/ani_gdb_s01.h5
- python examples/inference-benchmark.py examples/xyz_files/CH4-5.xyz - python examples/inference-benchmark.py --tqdm examples/xyz_files/CH4-5.xyz
- python -m torchani.neurochem.trainer tests/test_data/inputtrain.ipt dataset/ani_gdb_s01.h5 dataset/ani_gdb_s01.h5 - python -m torchani.neurochem.trainer --tqdm tests/test_data/inputtrain.ipt dataset/ani_gdb_s01.h5 dataset/ani_gdb_s01.h5
- python -m torchani.data.cache-aev tmp dataset/ani_gdb_s01.h5 256 - python -m torchani.data.cache_aev tmp dataset/ani_gdb_s01.h5 256
Docs: Docs:
image: '${{BuildTorchANI}}' image: '${{BuildTorchANI}}'
......
...@@ -17,6 +17,7 @@ Datasets ...@@ -17,6 +17,7 @@ Datasets
.. automodule:: torchani.data .. automodule:: torchani.data
.. autoclass:: torchani.data.BatchedANIDataset .. autoclass:: torchani.data.BatchedANIDataset
.. automodule:: torchani.data.cache_aev
Utilities Utilities
......
...@@ -3,6 +3,7 @@ import torchani ...@@ -3,6 +3,7 @@ import torchani
import torch import torch
import os import os
import timeit import timeit
import tqdm
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
...@@ -14,6 +15,8 @@ parser.add_argument('filename', ...@@ -14,6 +15,8 @@ parser.add_argument('filename',
parser.add_argument('-d', '--device', parser.add_argument('-d', '--device',
help='Device of modules and tensors', help='Device of modules and tensors',
default=('cuda' if torch.cuda.is_available() else 'cpu')) default=('cuda' if torch.cuda.is_available() else 'cpu'))
parser.add_argument('--tqdm', dest='tqdm', action='store_true',
help='Whether to use tqdm to display progress')
parser = parser.parse_args() parser = parser.parse_args()
# set up benchmark # set up benchmark
...@@ -88,6 +91,8 @@ print() ...@@ -88,6 +91,8 @@ print()
# test single mode # test single mode
print('[Single mode]') print('[Single mode]')
start = timeit.default_timer() start = timeit.default_timer()
if parser.tqdm:
xyz = tqdm.tqdm(xyz)
for species, coordinates in xyz: for species, coordinates in xyz:
species = species.unsqueeze(0) species = species.unsqueeze(0)
coordinates = torch.tensor(coordinates.unsqueeze(0), requires_grad=True) coordinates = torch.tensor(coordinates.unsqueeze(0), requires_grad=True)
......
...@@ -132,11 +132,7 @@ class BatchedANIDataset(Dataset): ...@@ -132,11 +132,7 @@ class BatchedANIDataset(Dataset):
shuffle=True, properties=['energies'], transform=(), shuffle=True, properties=['energies'], transform=(),
dtype=torch.get_default_dtype(), device=torch.device('cpu')): dtype=torch.get_default_dtype(), device=torch.device('cpu')):
super(BatchedANIDataset, self).__init__() super(BatchedANIDataset, self).__init__()
self.path = path
self.batch_size = batch_size
self.shuffle = shuffle
self.properties = properties self.properties = properties
self.dtype = dtype
self.device = device self.device = device
# get name of files storing data # get name of files storing data
......
# -*- coding: utf-8 -*-
"""AEVs for a dataset can be precomputed by invoking
``python -m torchani.data.cache_aev``, this would dump the dataset and
computed aevs. Use the ``-h`` option for help.
"""
import os import os
import torch import torch
from .. import aev, neurochem from .. import aev, neurochem
...@@ -18,6 +24,12 @@ if __name__ == '__main__': ...@@ -18,6 +24,12 @@ if __name__ == '__main__':
parser.add_argument('--constfile', parser.add_argument('--constfile',
help='Path of the constant file `.params`', help='Path of the constant file `.params`',
default=builtin.const_file) default=builtin.const_file)
parser.add_argument('--properties', nargs='+',
help='Output properties to load.`',
default=['energies'])
parser.add_argument('--dtype',
help='Data type',
default=str(torch.get_default_dtype()).split('.')[1])
default_device = 'cuda' if torch.cuda.is_available() else 'cpu' default_device = 'cuda' if torch.cuda.is_available() else 'cpu'
parser.add_argument('-d', '--device', help='Device for training', parser.add_argument('-d', '--device', help='Device for training',
default=default_device) default=default_device)
...@@ -36,13 +48,19 @@ if __name__ == '__main__': ...@@ -36,13 +48,19 @@ if __name__ == '__main__':
aev_computer = aev.AEVComputer(**consts).to(device) aev_computer = aev.AEVComputer(**consts).to(device)
dataset = BatchedANIDataset(parser.dataset, consts.species_to_tensor, dataset = BatchedANIDataset(parser.dataset, consts.species_to_tensor,
parser.batchsize, shuffle=parser.shuffle, parser.batchsize, shuffle=parser.shuffle,
properties=[], device=device) properties=parser.properties, device=device,
dtype=getattr(torch, parser.dtype))
# dump out the dataset
filename = os.path.join(parser.output, 'dataset')
with open(filename, 'wb') as f:
pickle.dump(dataset, f)
if parser.tqdm: if parser.tqdm:
import tqdm import tqdm
indices = tqdm.trange(len(dataset)) indices = tqdm.trange(len(dataset))
else: else:
indices = range(len(dataset)) indices = range(len(dataset))
for i in indices: for i in indices:
input_, _ = dataset[i] input_, _ = dataset[i]
aevs = [aev_computer(j) for j in input_] aevs = [aev_computer(j) for j in input_]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment