-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
87 additions
and
19 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[build-system] | ||
requires = ["setuptools", "numpy==1.26.4", "matplotlib"] | ||
requires = ["setuptools", "numpy<2.1.0", "matplotlib"] | ||
|
||
build-backend = "setuptools.build_meta:__legacy__" |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
numpy==1.26.4 | ||
numpy<2.1.0 | ||
matplotlib | ||
setuptools |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
"""Created on Jun 12 13:48:59 2024""" | ||
|
||
from multiprocessing import Pool | ||
from typing import Callable, Dict, List | ||
|
||
import numpy as np | ||
|
||
|
||
class MultiProcessor: | ||
"""Generalized multiprocessing functionality for processing dictionary inputs.""" | ||
|
||
def __init__(self, func: Callable, args: Dict[str, List], n_processors: int = 3): | ||
""" | ||
Initialize the `MultiProcessor` class. | ||
Parameters | ||
---------- | ||
func: Callable | ||
Function to be processed. The function should take arguments corresponding to the keys in the dictionary. | ||
args: Dict[str, List] | ||
A dictionary where keys are argument names, and values are lists of values for those arguments. | ||
n_processors: int, optional | ||
The number of processors to use for multiprocessing. Default is 3. | ||
""" | ||
if n_processors < 1: | ||
raise ValueError("`n_processors` must be at least 1.") | ||
|
||
self.func = func | ||
self.args = args | ||
self.n_proc = n_processors | ||
|
||
lengths = [len(v) for v in args.values()] | ||
if len(set(lengths)) != 1: | ||
raise ValueError("All argument lists must have the same length.") | ||
|
||
self.arg_tuples = list(zip(*self.args.values())) | ||
|
||
def run(self) -> np.ndarray: | ||
"""Run the multiprocessing task.""" | ||
with Pool(self.n_proc) as pool: | ||
try: | ||
results = pool.starmap(self.func, self.arg_tuples) | ||
except Exception as e: | ||
raise RuntimeError(f"Error occurred during parallel execution: {e}") | ||
|
||
return np.array(results) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Created on Nov 02 21:24:07 2024""" | ||
|
||
__version__ = "0.0.9a0" | ||
__name__ = 'mpyez' | ||
__version__ = "0.1.0" | ||
__author__ = "Syed Ali Mohsin Bukhari" | ||
__email__ = "[email protected]" | ||
__license__ = "MIT" | ||
|