-
Notifications
You must be signed in to change notification settings - Fork 217
smart dependency manager #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dcolinmorgan
wants to merge
170
commits into
master
Choose a base branch
from
dev/dep_man
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
170 commits
Select commit
Hold shift + click to select a range
9208e27
naive first pass, not working
dcolinmorgan 1b1a727
working smart dep manager in feature_utils
dcolinmorgan eb4ac0c
working smart dep manager in feature_utils
dcolinmorgan ea08c7c
working smart dep manager in feature_utils
dcolinmorgan e0c7123
working smart dep manager in feature_utils
dcolinmorgan a41f762
lint
dcolinmorgan d54ee2e
umap smart dependecies
dcolinmorgan 01abf59
update umap&feature tests
dcolinmorgan 2e58fa5
update umap&feature tests
dcolinmorgan 2960bda
update umap&feature tests
dcolinmorgan e2fac00
feature_utils build import_min_exn using deps
dcolinmorgan 70d3e9b
feature_utils build import_min_exn using deps
dcolinmorgan 4d8c6c8
add return types
dcolinmorgan 3c2fdcf
add return types
dcolinmorgan f168a4f
working dgl, progress on embed
dcolinmorgan 5144e3c
smart packages load, subfunctions not yet
dcolinmorgan f7a8e01
working embed and library function import
dcolinmorgan 3e3d44c
working embed and library function import
dcolinmorgan e99cbe5
add functional import to feature/umap
dcolinmorgan c8523ba
review leo lint
dcolinmorgan c2b0397
loading just libraries
dcolinmorgan 813fde2
lint
dcolinmorgan caecfba
lint
dcolinmorgan 4af3fad
lint
dcolinmorgan 22e4d18
lint
dcolinmorgan 68537c6
lint
dcolinmorgan 886d51a
add tests
dcolinmorgan a4ca316
add tests
dcolinmorgan f6fb4b9
if library then subfunction import
dcolinmorgan ed0262b
if library then subfunction import
dcolinmorgan 0f9539d
naive first pass, not working
dcolinmorgan d34fef2
working smart dep manager in feature_utils
dcolinmorgan 65eca98
working smart dep manager in feature_utils
dcolinmorgan 629b648
working smart dep manager in feature_utils
dcolinmorgan ff7590b
working smart dep manager in feature_utils
dcolinmorgan 4d7b824
lint
dcolinmorgan fc89beb
umap smart dependecies
dcolinmorgan 6778a16
update umap&feature tests
dcolinmorgan df5fcae
update umap&feature tests
dcolinmorgan 8c48dcf
update umap&feature tests
dcolinmorgan c1df5ba
feature_utils build import_min_exn using deps
dcolinmorgan 0c86a7e
feature_utils build import_min_exn using deps
dcolinmorgan 86f51b3
add return types
dcolinmorgan 7230af2
add return types
dcolinmorgan 45415e8
working dgl, progress on embed
dcolinmorgan 9e28265
smart packages load, subfunctions not yet
dcolinmorgan 5e9956b
working embed and library function import
dcolinmorgan f595dc5
working embed and library function import
dcolinmorgan 5e25907
add functional import to feature/umap
dcolinmorgan f47b6d7
review leo lint
dcolinmorgan 511187f
loading just libraries
dcolinmorgan e7ba215
lint
dcolinmorgan d784537
lint
dcolinmorgan 8e6cd50
lint
dcolinmorgan fddde77
lint
dcolinmorgan 9aed732
lint
dcolinmorgan 2ee37fc
add tests
dcolinmorgan 0011a73
add tests
dcolinmorgan e08c16f
if library then subfunction import
dcolinmorgan e6f29dd
if library then subfunction import
dcolinmorgan 9f95b7e
Merge branch 'dev/dep_man' of https://github.com/graphistry/pygraphis…
dcolinmorgan 1304968
lint
dcolinmorgan 4dd7d0a
lint
dcolinmorgan a12898b
lint
dcolinmorgan a1db061
tqdm bugs ??
dcolinmorgan 9199db0
tqdm bugs ??
dcolinmorgan f3c12e9
tqdm bugs ??
dcolinmorgan 95be2db
tqdm bugs ??
dcolinmorgan 74092fc
tqdm bugs ??
dcolinmorgan 3210019
test_text_utils deps check
dcolinmorgan abb999e
test_text_utils deps check
dcolinmorgan 5192f79
typos
dcolinmorgan 0d165dd
ignore type
dcolinmorgan 032193a
lint
dcolinmorgan 75207ce
lint
dcolinmorgan 1f539f1
lint
dcolinmorgan 219555b
lint
dcolinmorgan 8b53e6d
lint
dcolinmorgan 3380fa5
lint
dcolinmorgan c12ed7e
push test logic
dcolinmorgan ecdd72b
push test logic
dcolinmorgan 181abfa
push test logic
dcolinmorgan 703e923
push test logic
dcolinmorgan 5d7f750
lint
dcolinmorgan 849baae
lint
dcolinmorgan 6935a91
lint
dcolinmorgan c1f94c2
lint
dcolinmorgan eeaef0b
dep_flag lint
dcolinmorgan 8d4c1df
assert logic
dcolinmorgan 37ea918
lint
dcolinmorgan 8e32e0c
lint
dcolinmorgan 1f5f243
lint
dcolinmorgan 20430e0
lint
dcolinmorgan a3bb113
remove conditional
dcolinmorgan 9528e4a
sklearn assert
dcolinmorgan d170ace
sklearn assert
dcolinmorgan 6a508c4
sklearn assert
dcolinmorgan f5812bd
sklearn assert
dcolinmorgan 976d1dd
cumml _v_ test
dcolinmorgan 2faf466
cumml _v_ test
dcolinmorgan 2c96419
lint
dcolinmorgan ab73859
lint
dcolinmorgan a379787
lint
dcolinmorgan 580ef32
lint
dcolinmorgan 2c35bb2
lint
dcolinmorgan 3d5aa45
lint
dcolinmorgan 260c3b7
remove two too precise tests
dcolinmorgan 23e4257
lint
dcolinmorgan c6417f9
lint
dcolinmorgan 457ef7a
lint
dcolinmorgan 69e59e7
add sklearn to core dep
dcolinmorgan 6977d67
add sklearn to core dep
dcolinmorgan bba6c00
add sklearn to core dep
dcolinmorgan 533a750
add sklearn+umap to core dep
dcolinmorgan 20b1f16
add sklearn+umap to core dep
dcolinmorgan dd23f25
add sklearn+umap to core dep
dcolinmorgan 3b59258
add scipy, dc to core dep
dcolinmorgan 5e63074
add scipy, dc to core dep
dcolinmorgan 6db86a3
revert to working
dcolinmorgan 42f6a75
Merge branch 'dev/dep_man' of https://github.com/graphistry/pygraphis…
dcolinmorgan aadc84b
clsoe
dcolinmorgan edbdf37
remove has_
dcolinmorgan 0ec47bb
np.all to allclose
dcolinmorgan 139f7f9
lint
dcolinmorgan 3223a27
revert allclose
dcolinmorgan c47df98
drop assert
dcolinmorgan 26cd5e9
drop assert
dcolinmorgan e47fa35
drop assert
dcolinmorgan d8f9e6d
lint
dcolinmorgan 1904df5
respond to most comments
dcolinmorgan a9d3d9e
respond to most comments
dcolinmorgan 0dd4ed6
respond to most comments
dcolinmorgan 6007eb7
respond to tqdm, <2 column comments
dcolinmorgan 6d0cb1c
respond to tqdm, <2 column comments
dcolinmorgan 86378eb
respond to tqdm, <2 column comments
dcolinmorgan 5b36dd0
respond to tqdm
dcolinmorgan 90ca97a
Merge branch 'master' into dev/dep_man
dcolinmorgan 08de406
tqdm set_descr error
dcolinmorgan b236337
tqdm set_descr error
dcolinmorgan 85e1e24
tqdm not trange has "set_description"
dcolinmorgan c86cb53
tqdm not trange has "set_description"
dcolinmorgan 5d5146f
tqdm not trange has "set_description"
dcolinmorgan 8640971
tqdm.tqdm
dcolinmorgan 58d9810
tqdm.tqdm
dcolinmorgan d02d480
fallback to lazy import
dcolinmorgan a39928c
fallback to lazy import
dcolinmorgan cedd9ad
half lazy import
dcolinmorgan dcfdd9c
smart import
dcolinmorgan cc8c4d2
smart import
dcolinmorgan 79045df
smart import
dcolinmorgan 21bf0c9
lint
dcolinmorgan 9801824
refactored 1 column exception workaround
dcolinmorgan 7b86a04
refactored 1 column exception workaround
dcolinmorgan 0eea678
Merge branch 'master' into dev/dep_man
dcolinmorgan 7441b29
no explicit lazy
dcolinmorgan 52abe0f
lint
dcolinmorgan f87139d
lint
dcolinmorgan 637a991
lint
dcolinmorgan 21d2748
lint
dcolinmorgan f0db78b
remove defunct lazies
dcolinmorgan 9189800
lint
dcolinmorgan 0de2ffa
lint
dcolinmorgan 071faf1
lint
dcolinmorgan 62c58bc
lint
dcolinmorgan ab49794
lint
dcolinmorgan 8cb2838
lint
dcolinmorgan bb8a258
lint sheesh
dcolinmorgan 0309329
test gpu-avail
dcolinmorgan f37ce87
lint
dcolinmorgan 83f8fc5
lint2
dcolinmorgan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,36 @@ | ||
| import importlib | ||
|
|
||
| class DepManager: | ||
| def __init__(self): | ||
| self.pkgs = {} | ||
|
|
||
| def __getattr__(self, pkg:str): | ||
| if '_' not in pkg: | ||
dcolinmorgan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self._add_deps(pkg) | ||
| try: | ||
| return True, "ok", self.pkgs[pkg], self.pkgs[pkg].__version__ | ||
| except KeyError: | ||
| return False, str(pkg) + " not installed", None, None | ||
| else: | ||
| module = '.'.join(pkg.split('_')[:-1]) | ||
dcolinmorgan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name = pkg.split('_')[-1] | ||
| self.import_from(module, name) | ||
| try: | ||
| return True, "ok", self.pkgs[name], self.pkgs[module].__version | ||
| except KeyError: | ||
| return False, str([module,name]) + " not installed", None, None | ||
|
|
||
| def _add_deps(self, pkg:str): | ||
| try: | ||
| pkg_val = importlib.import_module(pkg) | ||
| self.pkgs[pkg] = pkg_val | ||
| # setattr(self, pkg, pkg_val) | ||
| except: | ||
| setattr(self, pkg, None) | ||
dcolinmorgan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def import_from(self,pkg:str, name:str): | ||
| try: | ||
| module = __import__(pkg, fromlist=[name]) | ||
| self.pkgs[name] = module | ||
| except: | ||
| setattr(self, pkg, None) | ||
dcolinmorgan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
| ) | ||
|
|
||
| from .util import setup_logger | ||
|
|
||
| from .dep_manager import DepManager | ||
|
|
||
| if TYPE_CHECKING: | ||
| import scipy | ||
|
|
@@ -34,24 +34,24 @@ | |
| MIXIN_BASE = object | ||
|
|
||
|
|
||
| def lazy_dgl_import_has_dependency(): | ||
| try: | ||
| import warnings | ||
| warnings.filterwarnings('ignore') | ||
| import dgl # noqa: F811 | ||
| return True, 'ok', dgl | ||
| except ModuleNotFoundError as e: | ||
| return False, e, None | ||
| # def lazy_dgl_import_has_dependency(): | ||
| # try: | ||
| # import warnings | ||
| # warnings.filterwarnings('ignore') | ||
| # import dgl # noqa: F811 | ||
| # return True, 'ok', dgl | ||
| # except ModuleNotFoundError as e: | ||
| # return False, e, None | ||
|
|
||
|
|
||
| def lazy_torch_import_has_dependency(): | ||
| try: | ||
| import warnings | ||
| warnings.filterwarnings('ignore') | ||
| import torch # noqa: F811 | ||
| return True, 'ok', torch | ||
| except ModuleNotFoundError as e: | ||
| return False, e, None | ||
| # def lazy_torch_import_has_dependency(): | ||
| # try: | ||
| # import warnings | ||
| # warnings.filterwarnings('ignore') | ||
| # import torch # noqa: F811 | ||
| # return True, 'ok', torch | ||
| # except ModuleNotFoundError as e: | ||
| # return False, e, None | ||
|
|
||
|
|
||
| logger = setup_logger(name=__name__, verbose=config.VERBOSE) | ||
|
|
@@ -73,7 +73,7 @@ def convert_to_torch(X_enc: pd.DataFrame, y_enc: Optional[pd.DataFrame]): # typ | |
| :param y_enc: DataFrame Matrix of Values for Target | ||
| :return: Dictionary of torch encoded arrays | ||
| """ | ||
| _, _, torch = lazy_torch_import_has_dependency() # noqa: F811 | ||
| _, _, torch, _ = deps.torch # noqa: F811 | ||
|
|
||
| if not y_enc.empty: # type: ignore | ||
| data = { | ||
|
|
@@ -98,7 +98,7 @@ def get_available_devices(): | |
| device (torch.device): Main device (GPU 0 or CPU). | ||
| gpu_ids (list): List of IDs of all GPUs that are available. | ||
| """ | ||
| _, _, torch = lazy_torch_import_has_dependency() # noqa: F811 | ||
| _, _, torch, _ = deps.torch # noqa: F811 | ||
|
|
||
| gpu_ids = [] | ||
| if torch.cuda.is_available(): | ||
|
|
@@ -181,7 +181,9 @@ def pandas_to_dgl_graph( | |
| sp_mat: sparse scipy matrix | ||
| ordered_nodes_dict: dict ordered from most common src and dst nodes | ||
| """ | ||
| _, _, dgl = lazy_dgl_import_has_dependency() # noqa: F811 | ||
| deps = DepManager() | ||
|
||
| _, _, dgl, _ = deps.dgl # noqa: F811 | ||
|
|
||
| sp_mat, ordered_nodes_dict = pandas_to_sparse_adjacency(df, src, dst, weight_col) | ||
| g = dgl.from_scipy(sp_mat, device=device) # there are other ways too | ||
| logger.info(f"Graph Type: {type(g)}") | ||
|
|
@@ -196,7 +198,7 @@ def get_torch_train_test_mask(n: int, ratio: float = 0.8): | |
| :param ratio: mimics train/test split. `ratio` sets number of True vs False mask entries. | ||
| :return: train and test torch tensor masks | ||
| """ | ||
| _, _, torch = lazy_torch_import_has_dependency() # noqa: F811 | ||
| _, _, torch, _ = deps.torch # noqa: F811 | ||
|
|
||
| train_mask = torch.zeros(n, dtype=torch.bool).bernoulli(ratio) | ||
| test_mask = ~train_mask | ||
|
|
@@ -225,8 +227,8 @@ def dgl_lazy_init(self, train_split: float = 0.8, device: str = "cpu"): | |
| """ | ||
|
|
||
| if not self.dgl_initialized: | ||
| lazy_dgl_import_has_dependency() | ||
| lazy_torch_import_has_dependency() | ||
| deps.dgl | ||
| deps.torch | ||
| self.train_split = train_split | ||
| self.device = device | ||
| self._removed_edges_previously = False | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.