-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from SEDenmarkLab/dev-lena-benchmarks
Additional benchmarks for SI
- Loading branch information
Showing
4 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# This script is to show the process of timing measurement | ||
import molli as ml | ||
import timeit | ||
|
||
N = 3 | ||
|
||
# ml.aux.assert_molli_version_min("1.0.0b2") | ||
|
||
_clib = ml.ConformerLibrary("bpa_test.clib") | ||
|
||
with _clib.reading(): | ||
ensembles = {k: v for k, v in _clib.items()} | ||
|
||
|
||
def _dir_col(path, overwrite=False): | ||
return ml.storage.Collection( | ||
path, | ||
backend=ml.storage.DirCollectionBackend, | ||
value_decoder=lambda x: ml.ConformerEnsemble.loads_mol2(x.decode()), | ||
value_encoder=lambda x: ml.ConformerEnsemble.dumps_mol2(x).encode(), | ||
ext=".mol2", | ||
readonly=False, | ||
overwrite=overwrite, | ||
) | ||
|
||
|
||
def _zip_col(path, overwrite=False): | ||
return ml.storage.Collection( | ||
path, | ||
backend=ml.storage.ZipCollectionBackend, | ||
value_decoder=lambda x: ml.ConformerEnsemble.loads_mol2(x.decode()), | ||
value_encoder=lambda x: ml.ConformerEnsemble.dumps_mol2(x).encode(), | ||
ext=".mol2", | ||
readonly=False, | ||
overwrite=overwrite, | ||
) | ||
|
||
|
||
def _tar_col(path, overwrite=False): | ||
return ml.storage.Collection( | ||
path, | ||
backend=ml.storage.TarCollectionBackend, | ||
value_decoder=lambda x: ml.ConformerEnsemble.loads_mol2(x.decode()), | ||
value_encoder=lambda x: ml.ConformerEnsemble.dumps_mol2(x).encode(), | ||
ext=".mol2", | ||
readonly=False, | ||
overwrite=overwrite, | ||
) | ||
|
||
|
||
def _ukv_col(path, overwrite=False): | ||
return ml.ConformerLibrary( | ||
path, | ||
readonly=False, | ||
overwrite=overwrite, | ||
) | ||
|
||
|
||
# Note: bpa_test_deflate5.zip is not here as you cannot write into the compressed format | ||
for prep, path in ( | ||
(_ukv_col, "bpa_test.clib"), | ||
(_tar_col, "bpa_test.tar"), | ||
(_zip_col, "bpa_test.zip"), | ||
# (_dir_col, "bpa_test"), | ||
): | ||
clib_write_times = timeit.Timer( | ||
stmt="""with library.writing():\n for k, v in ensembles.items(): library[k]=v""", | ||
setup="""library = prep(path, overwrite=True)""", | ||
globals=globals(), | ||
).repeat(5, number=1) | ||
|
||
print("Writing times", path, min(clib_write_times), clib_write_times, flush=True) | ||
|
||
# Note: bpa_test_deflate5.zip is written from the compressed "bpa_test" directory created after the first one | ||
for prep, path in ( | ||
(_ukv_col, "bpa_test.clib"), | ||
(_tar_col, "bpa_test.tar"), | ||
(_zip_col, "bpa_test.zip"), | ||
# (_zip_col, "bpa_test_deflate5.zip"), | ||
# (_dir_col, "bpa_test"), | ||
): | ||
clib_read_times = timeit.Timer( | ||
stmt="""with library.reading():\n for k, v in library.items(): pass""", | ||
setup="""library = prep(path, overwrite=False)""", | ||
globals=globals(), | ||
).repeat(5, number=1) | ||
|
||
print("Read times", path, min(clib_read_times), clib_read_times, flush=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import molli as ml | ||
import timeit | ||
import h5py | ||
import numpy as np | ||
|
||
_clib = ml.ConformerLibrary("bpa_test.clib") | ||
|
||
with _clib.reading(): | ||
ensembles = {k: v for k, v in _clib.items()} | ||
|
||
path = "bpa_test.hdf5" | ||
|
||
|
||
def write_hdf5(): | ||
with h5py.File(path, "w") as f: | ||
for entry_key, ensemble in ensembles.items(): | ||
group = f.create_group(entry_key) | ||
group.create_dataset( | ||
name="coords", | ||
data=ensemble.coords, | ||
dtype="float32", | ||
) | ||
|
||
group.create_dataset( | ||
name="atomic_charges", data=ensemble.atomic_charges, dtype="float32" | ||
) | ||
group.create_dataset(name="weights", data=ensemble.weights, dtype="float32") | ||
group.create_dataset( | ||
name="atoms", | ||
data=[int(a.element) for a in ensemble.atoms], | ||
dtype="int16", | ||
) | ||
atom_idxs = {a: i for i, a in enumerate(ensemble.atoms)} | ||
group.create_dataset( | ||
name="bonds", | ||
data=[ | ||
[atom_idxs[bond.a1], atom_idxs[bond.a2], int(bond.btype)] | ||
for bond in ensemble.bonds | ||
], | ||
dtype="int16", | ||
) | ||
|
||
|
||
def read_hdf5(): | ||
with h5py.File(path, "r") as f: | ||
for entry_key in f.keys(): | ||
group = f[entry_key] | ||
ens = ml.ConformerEnsemble( | ||
[int(i) for i in group["atoms"][:]], | ||
n_conformers=group["coords"].shape[0], | ||
name=entry_key, | ||
coords=group["coords"][:], | ||
weights=group["weights"][:], | ||
atomic_charges=group["atomic_charges"][:], | ||
) | ||
for a1, a2, bt in group["bonds"][:]: | ||
ens.connect(int(a1), int(a2), btype=ml.BondType(bt)) | ||
|
||
|
||
# Measure writing speed | ||
write_times = timeit.repeat(write_hdf5, repeat=5, number=1) | ||
print(f"Writing time: min {min(write_times):.6f} seconds of {write_times}") | ||
|
||
# Measure reading speed | ||
read_times = timeit.repeat(read_hdf5, repeat=5, number=1) | ||
print(f"Reading time: min {min(read_times):.6f} seconds of {read_times}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters