Skip to content

Commit

Permalink
Added loading bars
Browse files Browse the repository at this point in the history
  • Loading branch information
SurgeArrester committed Feb 28, 2021
1 parent c31a007 commit 85bb9ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
29 changes: 21 additions & 8 deletions ElM2D/ElM2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import plotly.express as px
import plotly.io as pio

from tqdm import tqdm
from tqdm.contrib.concurrent import process_map

if __name__ == "__main__":
mapper = ElM2D()
Expand All @@ -69,7 +71,7 @@ def __init__(self, n_proc=None,

self.verbose = verbose

self.n_proc = cpu_count()
self.n_proc = cpu_count() - 1

self.formula_list = None # Input formulae
self.input_mat = None # Pettifor vector representation of formula
Expand Down Expand Up @@ -236,18 +238,29 @@ def _process_list(self, formula_list, n_proc):
self.input_mat[i] = ElMD(formula).vector_form

# Create input pairings
for i in range(len(formula_list) - 1):
sublist = []
for j in range(i + 1, len(formula_list)):
sublist.append((i, j))

pool_list.append(sublist)
if self.verbose:
print("Constructing joint compositional pairings")
for i in tqdm(range(len(formula_list) - 1)):
sublist = [(i, j) for j in range(i + 1, len(formula_list))]
pool_list.append(sublist)
else:
for i in range(len(formula_list) - 1):
sublist = [(i, j) for j in range(i + 1, len(formula_list))]
pool_list.append(sublist)

# Distribute amongst processes
if self.verbose: print("Creating Process Pool")
process_pool = Pool(n_proc)
scores = process_pool.map(self._pool_ElMD, pool_list)
if self.verbose:
print("Scattering scores and computing values")
scores = process_map(self._pool_ElMD, pool_list, chunksize=1)
else:
scores = process_pool.map(self._pool_ElMD, pool_list)

if self.verbose: print("Scores computed closing processes")
process_pool.close()

if self.verbose: print("Flattening sublists")
# Flattens list of lists to single list
distances = [dist for sublist in scores for dist in sublist]

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
setup(
name = 'ElM2D',
packages = ['ElM2D'],
version = '0.1.5',
version = '0.1.6',
license='GPL3',
description = 'A mapping class to embed large datasets of ionic compositions with respect to the ElMD metric.',
description = 'A high performance mapping class to embed large datasets of ionic compositions with respect to the ElMD metric.',
author = 'Cameron Hagreaves',
author_email = 'cameron.h@rgreaves.me.uk',
url = 'https://github.com/lrcfmd/ElM2D/',
download_url = 'https://github.com/lrcfmd/ElM2D/archive/0.1.5.tar.gz',
download_url = 'https://github.com/lrcfmd/ElM2D/archive/0.1.6.tar.gz',
keywords = ['ChemInformatics', 'Materials Science', 'Machine Learning', 'Materials Representation'],
install_requires=[
'cython',
'numba',
'numpy',
'pandas',
'tqdm',
'scipy',
'plotly',
'umap-learn'
Expand Down

0 comments on commit 85bb9ad

Please sign in to comment.