hackingmaterials / matminer

Data mining for materials science
https://hackingmaterials.github.io/matminer/
Other
466 stars 191 forks source link

Fixing matminer's multiprocessing problem #902

Open ardunn opened 1 year ago

ardunn commented 1 year ago

Matminer's multiprocessing problem comes from featurizing a few expensive entries in large iterables of entries (generally structures). When a multiprocessing job hangs for a long time, it is usually because the memory needed for some low number of chunks winds up getting thrashed around or stagnating, resulting in the final result never being able to compute.

Proposed solution: replace multiprocessing with Dask bag

Assumptions:

General overview:

  1. In featurize_many, create a Dask.bag.Bag from chunks (AKA partitions in dask) of the dataframe input samples. Alternatively could be done with a delayed call.
  2. Compute the bag lazily
  3. Reconvert the bag back into dataframe (should be done automatically via generator in featurize_many)

By default, dask uses multiprocessing as the scheduler if no distributed client is defined. So to actually take advantage of this, you need to define a LocalClient or distributed client with a different scheduler. Then you can compute according to whatever is available (including constraints on memory)

I don't think the memory-locking problem from multiprocessing will happen if parallelization is done this way, but we can't be sure until we try it. If it still does happen, it might be worth looking into. At very least, using dask will allow you to use multiple machines to compute features

ardunn commented 1 year ago

@ml-evs @computron @hrushikesh-s