Skip to content

Commit

Permalink
Add kwargs passthrough to Parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyue Ping Ong committed Jul 26, 2023
1 parent ebf7f3c commit 4524140
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions matcalc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,26 @@ def calc(self, structure: Structure) -> dict:
Returns: {"prop name": value}
"""

def calc_many(self, structures: Sequence[Structure], n_jobs: None | int = None) -> Generator[dict, None, None]:
def calc_many(
self, structures: Sequence[Structure], n_jobs: None | int = None, **kwargs
) -> Generator[dict, None, None]:
"""
Performs calc on many structures. The return type is a generator given that the calc method can potentially be
reasonably expensive. It is trivial to convert the generator to a list/tuple.
Args:
structures: List or generator of Structures.
n_jobs: Number of processes to use for multiprocessing.Pool. Defaults to None, i.e., all CPUs.
n_jobs: The maximum number of concurrently running jobs, such as the number of Python worker processes when
backend=”multiprocessing” or the size of the thread-pool when backend=”threading”. If -1 all CPUs are
used. If 1 is given, no parallel computing code is used at all, and the behavior amounts to a simple
python for loop. This mode is not compatible with timeout. For n_jobs below -1, (n_cpus + 1 + n_jobs)
are used. Thus for n_jobs = -2, all CPUs but one are used. None is a marker for `unset` that will be
interpreted as n_jobs=1 unless the call is performed under a parallel_config() context manager that
sets another value for n_jobs.
**kwargs: Passthrough to joblib.Parallel.
Returns:
Generator of dicts.
"""
parallel = Parallel(n_jobs=n_jobs, return_as="generator")
parallel = Parallel(n_jobs=n_jobs, return_as="generator", **kwargs)
return parallel(delayed(self.calc)(s) for s in structures)

0 comments on commit 4524140

Please sign in to comment.