Skip to content
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

smart dependency manager #511

Open
wants to merge 170 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
9208e27
naive first pass, not working
dcolinmorgan Oct 5, 2023
1b1a727
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
eb4ac0c
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
ea08c7c
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
e0c7123
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
a41f762
lint
dcolinmorgan Oct 10, 2023
d54ee2e
umap smart dependecies
dcolinmorgan Oct 11, 2023
01abf59
update umap&feature tests
dcolinmorgan Oct 12, 2023
2e58fa5
update umap&feature tests
dcolinmorgan Oct 12, 2023
2960bda
update umap&feature tests
dcolinmorgan Oct 12, 2023
e2fac00
feature_utils build import_min_exn using deps
dcolinmorgan Oct 12, 2023
70d3e9b
feature_utils build import_min_exn using deps
dcolinmorgan Oct 12, 2023
4d8c6c8
add return types
dcolinmorgan Oct 12, 2023
3c2fdcf
add return types
dcolinmorgan Oct 12, 2023
f168a4f
working dgl, progress on embed
dcolinmorgan Oct 13, 2023
5144e3c
smart packages load, subfunctions not yet
dcolinmorgan Oct 13, 2023
f7a8e01
working embed and library function import
dcolinmorgan Oct 13, 2023
3e3d44c
working embed and library function import
dcolinmorgan Oct 13, 2023
e99cbe5
add functional import to feature/umap
dcolinmorgan Oct 14, 2023
c8523ba
review leo lint
dcolinmorgan Oct 16, 2023
c2b0397
loading just libraries
dcolinmorgan Oct 19, 2023
813fde2
lint
dcolinmorgan Oct 19, 2023
caecfba
lint
dcolinmorgan Oct 19, 2023
4af3fad
lint
dcolinmorgan Oct 19, 2023
22e4d18
lint
dcolinmorgan Oct 19, 2023
68537c6
lint
dcolinmorgan Oct 19, 2023
886d51a
add tests
dcolinmorgan Oct 19, 2023
a4ca316
add tests
dcolinmorgan Oct 19, 2023
f6fb4b9
if library then subfunction import
dcolinmorgan Oct 23, 2023
ed0262b
if library then subfunction import
dcolinmorgan Oct 23, 2023
0f9539d
naive first pass, not working
dcolinmorgan Oct 5, 2023
d34fef2
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
65eca98
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
629b648
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
ff7590b
working smart dep manager in feature_utils
dcolinmorgan Oct 10, 2023
4d7b824
lint
dcolinmorgan Oct 10, 2023
fc89beb
umap smart dependecies
dcolinmorgan Oct 11, 2023
6778a16
update umap&feature tests
dcolinmorgan Oct 12, 2023
df5fcae
update umap&feature tests
dcolinmorgan Oct 12, 2023
8c48dcf
update umap&feature tests
dcolinmorgan Oct 12, 2023
c1df5ba
feature_utils build import_min_exn using deps
dcolinmorgan Oct 12, 2023
0c86a7e
feature_utils build import_min_exn using deps
dcolinmorgan Oct 12, 2023
86f51b3
add return types
dcolinmorgan Oct 12, 2023
7230af2
add return types
dcolinmorgan Oct 12, 2023
45415e8
working dgl, progress on embed
dcolinmorgan Oct 13, 2023
9e28265
smart packages load, subfunctions not yet
dcolinmorgan Oct 13, 2023
5e9956b
working embed and library function import
dcolinmorgan Oct 13, 2023
f595dc5
working embed and library function import
dcolinmorgan Oct 13, 2023
5e25907
add functional import to feature/umap
dcolinmorgan Oct 14, 2023
f47b6d7
review leo lint
dcolinmorgan Oct 16, 2023
511187f
loading just libraries
dcolinmorgan Oct 19, 2023
e7ba215
lint
dcolinmorgan Oct 19, 2023
d784537
lint
dcolinmorgan Oct 19, 2023
8e6cd50
lint
dcolinmorgan Oct 19, 2023
fddde77
lint
dcolinmorgan Oct 19, 2023
9aed732
lint
dcolinmorgan Oct 19, 2023
2ee37fc
add tests
dcolinmorgan Oct 19, 2023
0011a73
add tests
dcolinmorgan Oct 19, 2023
e08c16f
if library then subfunction import
dcolinmorgan Oct 23, 2023
e6f29dd
if library then subfunction import
dcolinmorgan Oct 23, 2023
9f95b7e
Merge branch 'dev/dep_man' of https://github.com/graphistry/pygraphis…
dcolinmorgan Nov 23, 2023
1304968
lint
dcolinmorgan Nov 23, 2023
4dd7d0a
lint
dcolinmorgan Nov 23, 2023
a12898b
lint
dcolinmorgan Nov 23, 2023
a1db061
tqdm bugs ??
dcolinmorgan Nov 23, 2023
9199db0
tqdm bugs ??
dcolinmorgan Nov 24, 2023
f3c12e9
tqdm bugs ??
dcolinmorgan Nov 24, 2023
95be2db
tqdm bugs ??
dcolinmorgan Nov 24, 2023
74092fc
tqdm bugs ??
dcolinmorgan Nov 24, 2023
3210019
test_text_utils deps check
dcolinmorgan Nov 24, 2023
abb999e
test_text_utils deps check
dcolinmorgan Nov 24, 2023
5192f79
typos
dcolinmorgan Nov 24, 2023
0d165dd
ignore type
dcolinmorgan Nov 24, 2023
032193a
lint
dcolinmorgan Nov 24, 2023
75207ce
lint
dcolinmorgan Nov 24, 2023
1f539f1
lint
dcolinmorgan Nov 24, 2023
219555b
lint
dcolinmorgan Nov 24, 2023
8b53e6d
lint
dcolinmorgan Nov 24, 2023
3380fa5
lint
dcolinmorgan Nov 24, 2023
c12ed7e
push test logic
dcolinmorgan Nov 24, 2023
ecdd72b
push test logic
dcolinmorgan Nov 24, 2023
181abfa
push test logic
dcolinmorgan Nov 24, 2023
703e923
push test logic
dcolinmorgan Nov 24, 2023
5d7f750
lint
dcolinmorgan Nov 24, 2023
849baae
lint
dcolinmorgan Nov 24, 2023
6935a91
lint
dcolinmorgan Nov 24, 2023
c1f94c2
lint
dcolinmorgan Nov 24, 2023
eeaef0b
dep_flag lint
dcolinmorgan Nov 24, 2023
8d4c1df
assert logic
dcolinmorgan Nov 24, 2023
37ea918
lint
dcolinmorgan Nov 27, 2023
8e32e0c
lint
dcolinmorgan Nov 27, 2023
1f5f243
lint
dcolinmorgan Nov 27, 2023
20430e0
lint
dcolinmorgan Nov 27, 2023
a3bb113
remove conditional
dcolinmorgan Nov 27, 2023
9528e4a
sklearn assert
dcolinmorgan Nov 27, 2023
d170ace
sklearn assert
dcolinmorgan Nov 27, 2023
6a508c4
sklearn assert
dcolinmorgan Nov 27, 2023
f5812bd
sklearn assert
dcolinmorgan Nov 27, 2023
976d1dd
cumml _v_ test
dcolinmorgan Nov 27, 2023
2faf466
cumml _v_ test
dcolinmorgan Nov 27, 2023
2c96419
lint
dcolinmorgan Nov 27, 2023
ab73859
lint
dcolinmorgan Nov 27, 2023
a379787
lint
dcolinmorgan Nov 27, 2023
580ef32
lint
dcolinmorgan Nov 27, 2023
2c35bb2
lint
dcolinmorgan Nov 27, 2023
3d5aa45
lint
dcolinmorgan Nov 27, 2023
260c3b7
remove two too precise tests
dcolinmorgan Nov 27, 2023
23e4257
lint
dcolinmorgan Nov 27, 2023
c6417f9
lint
dcolinmorgan Nov 27, 2023
457ef7a
lint
dcolinmorgan Nov 27, 2023
69e59e7
add sklearn to core dep
dcolinmorgan Nov 27, 2023
6977d67
add sklearn to core dep
dcolinmorgan Nov 27, 2023
bba6c00
add sklearn to core dep
dcolinmorgan Nov 27, 2023
533a750
add sklearn+umap to core dep
dcolinmorgan Nov 27, 2023
20b1f16
add sklearn+umap to core dep
dcolinmorgan Nov 27, 2023
dd23f25
add sklearn+umap to core dep
dcolinmorgan Nov 27, 2023
3b59258
add scipy, dc to core dep
dcolinmorgan Nov 27, 2023
5e63074
add scipy, dc to core dep
dcolinmorgan Nov 27, 2023
6db86a3
revert to working
dcolinmorgan Nov 27, 2023
42f6a75
Merge branch 'dev/dep_man' of https://github.com/graphistry/pygraphis…
dcolinmorgan Nov 27, 2023
aadc84b
clsoe
dcolinmorgan Nov 27, 2023
edbdf37
remove has_
dcolinmorgan Nov 27, 2023
0ec47bb
np.all to allclose
dcolinmorgan Nov 27, 2023
139f7f9
lint
dcolinmorgan Nov 27, 2023
3223a27
revert allclose
dcolinmorgan Nov 27, 2023
c47df98
drop assert
dcolinmorgan Nov 27, 2023
26cd5e9
drop assert
dcolinmorgan Nov 27, 2023
e47fa35
drop assert
dcolinmorgan Nov 27, 2023
d8f9e6d
lint
dcolinmorgan Nov 27, 2023
1904df5
respond to most comments
dcolinmorgan Dec 4, 2023
a9d3d9e
respond to most comments
dcolinmorgan Dec 4, 2023
0dd4ed6
respond to most comments
dcolinmorgan Dec 4, 2023
6007eb7
respond to tqdm, <2 column comments
dcolinmorgan Dec 5, 2023
6d0cb1c
respond to tqdm, <2 column comments
dcolinmorgan Dec 5, 2023
86378eb
respond to tqdm, <2 column comments
dcolinmorgan Dec 5, 2023
5b36dd0
respond to tqdm
dcolinmorgan Dec 5, 2023
90ca97a
Merge branch 'master' into dev/dep_man
dcolinmorgan Dec 5, 2023
08de406
tqdm set_descr error
dcolinmorgan Dec 5, 2023
b236337
tqdm set_descr error
dcolinmorgan Dec 5, 2023
85e1e24
tqdm not trange has "set_description"
dcolinmorgan Dec 5, 2023
c86cb53
tqdm not trange has "set_description"
dcolinmorgan Dec 5, 2023
5d5146f
tqdm not trange has "set_description"
dcolinmorgan Dec 5, 2023
8640971
tqdm.tqdm
dcolinmorgan Dec 5, 2023
58d9810
tqdm.tqdm
dcolinmorgan Dec 5, 2023
d02d480
fallback to lazy import
dcolinmorgan Dec 5, 2023
a39928c
fallback to lazy import
dcolinmorgan Dec 5, 2023
cedd9ad
half lazy import
dcolinmorgan Dec 5, 2023
dcfdd9c
smart import
dcolinmorgan Dec 5, 2023
cc8c4d2
smart import
dcolinmorgan Dec 5, 2023
79045df
smart import
dcolinmorgan Dec 5, 2023
21bf0c9
lint
dcolinmorgan Dec 5, 2023
9801824
refactored 1 column exception workaround
dcolinmorgan Dec 5, 2023
7b86a04
refactored 1 column exception workaround
dcolinmorgan Dec 5, 2023
0eea678
Merge branch 'master' into dev/dep_man
dcolinmorgan May 23, 2024
7441b29
no explicit lazy
dcolinmorgan May 23, 2024
52abe0f
lint
dcolinmorgan May 23, 2024
f87139d
lint
dcolinmorgan May 23, 2024
637a991
lint
dcolinmorgan May 23, 2024
21d2748
lint
dcolinmorgan May 23, 2024
f0db78b
remove defunct lazies
dcolinmorgan May 23, 2024
9189800
lint
dcolinmorgan May 23, 2024
0de2ffa
lint
dcolinmorgan May 23, 2024
071faf1
lint
dcolinmorgan May 23, 2024
62c58bc
lint
dcolinmorgan May 23, 2024
ab49794
lint
dcolinmorgan May 23, 2024
8cb2838
lint
dcolinmorgan May 23, 2024
bb8a258
lint sheesh
dcolinmorgan May 23, 2024
0309329
test gpu-avail
dcolinmorgan May 24, 2024
f37ce87
lint
dcolinmorgan May 27, 2024
83f8fc5
lint2
dcolinmorgan May 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions graphistry/dep_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import importlib

DEPS = ['cu_cat']

class DepManager:
def __init__(self):
self.pkgs = {}
self.deps()

def __getattr__(self, pkg):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add return types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added pkg:str here to return type; i dont think this is related to the pytest type check errors below and in #489.

but i also dont know why this arrow_uploader error is coming up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any idea about this type check error, seemingly involving arrow_uploader? another PR pings this same error, not sure what to make of it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed in main

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

def _add_deps(self, pkg:str):
if pkg not in self.pkgs.keys():
try:
pkg_val = importlib.import_module(pkg)
self.pkgs[pkg] = pkg_val
setattr(self, pkg, pkg_val)
except:
setattr(self, pkg, None)

def deps(self):
[self._add_deps(dep) for dep in DEPS]
70 changes: 24 additions & 46 deletions graphistry/feature_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .PlotterBase import WeakValueDictionary, Plottable
from .util import setup_logger, check_set_memoize
from .ai_utils import infer_graph, infer_self_graph
from .dep_manager import DepManager

# add this inside classes and have a method that can set log level
logger = setup_logger(name=__name__, verbose=config.VERBOSE)
Expand Down Expand Up @@ -69,33 +70,11 @@


#@check_set_memoize
def lazy_import_has_dependancy_text():
import warnings
warnings.filterwarnings("ignore")
try:
from sentence_transformers import SentenceTransformer
return True, 'ok', SentenceTransformer
except ModuleNotFoundError as e:
return False, e, None

def lazy_import_has_min_dependancy():
import warnings
warnings.filterwarnings("ignore")
try:
import scipy.sparse # noqa
from scipy import __version__ as scipy_version
from dirty_cat import __version__ as dirty_cat_version
from sklearn import __version__ as sklearn_version
logger.debug(f"SCIPY VERSION: {scipy_version}")
logger.debug(f"Dirty CAT VERSION: {dirty_cat_version}")
logger.debug(f"sklearn VERSION: {sklearn_version}")
return True, 'ok'
except ModuleNotFoundError as e:
return False, e

deps = DepManager()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


def assert_imported_text():
has_dependancy_text_, import_text_exn, _ = lazy_import_has_dependancy_text()
has_dependancy_text_, import_text_exn, _, _ = deps.sentence_transformers

if not has_dependancy_text_:
logger.error( # noqa
"AI Package sentence_transformers not found,"
Expand All @@ -105,7 +84,14 @@ def assert_imported_text():


def assert_imported():
has_min_dependancy_, import_min_exn = lazy_import_has_min_dependancy()
has_min_dependancy_,import_min_exn,_,scipy_version = deps.scipy
has_min_dependancy_,import_min_exn,_,dirty_cat_version = deps.dirty_cat
has_min_dependancy_,import_min_exn,_,sklearn_version = deps.sklearn
if None not in [scipy_version, dirty_cat_version, sklearn_version]:
logger.debug(f"SCIPY VERSION: {scipy_version}")
logger.debug(f"Dirty CAT VERSION: {dirty_cat_version}")
logger.debug(f"sklearn VERSION: {sklearn_version}")

if not has_min_dependancy_:
logger.error( # noqa
"AI Packages not found, trying running" # noqa
Expand Down Expand Up @@ -149,10 +135,10 @@ def resolve_feature_engine(
return feature_engine # type: ignore

if feature_engine == "auto":
has_dependancy_text_, _, _ = lazy_import_has_dependancy_text()
has_dependancy_text_, _, _, _ = deps.sentence_transformers
if has_dependancy_text_:
return "torch"
has_min_dependancy_, _ = lazy_import_has_min_dependancy()
has_min_dependancy_, _, _, _ = deps.dirty_cat
if has_min_dependancy_:
return "dirty_cat"
return "pandas"
Expand All @@ -169,7 +155,7 @@ def resolve_feature_engine(

def resolve_y(df: Optional[pd.DataFrame], y: YSymbolic) -> pd.DataFrame:

if isinstance(y, pd.DataFrame) or 'cudf' in str(getmodule(y)):
if isinstance(y, pd.DataFrame) or 'cudf.core.dataframe' in str(getmodule(y)):
return y # type: ignore

if df is None:
Expand All @@ -190,7 +176,7 @@ def resolve_y(df: Optional[pd.DataFrame], y: YSymbolic) -> pd.DataFrame:

def resolve_X(df: Optional[pd.DataFrame], X: XSymbolic) -> pd.DataFrame:

if isinstance(X, pd.DataFrame) or 'cudf' in str(getmodule(X)):
if isinstance(X, pd.DataFrame) or 'cudf.core.dataframe' in str(getmodule(X)):
return X # type: ignore

if df is None:
Expand Down Expand Up @@ -292,14 +278,7 @@ def remove_internal_namespace_if_present(df: pd.DataFrame):
config.IMPLICIT_NODE_ID,
"index", # in umap, we add as reindex
]

if (len(df.columns) <= 2):
df = df.rename(columns={c: c + '_1' for c in df.columns if c in reserved_namespace})
# if (isinstance(df.columns.to_list()[0],int)):
# int_namespace = pd.to_numeric(df.columns, errors = 'ignore').dropna().to_list() # type: ignore
# df = df.rename(columns={c: str(c) + '_1' for c in df.columns if c in int_namespace})
else:
df = df.drop(columns=reserved_namespace, errors="ignore") # type: ignore
df = df.drop(columns=reserved_namespace, errors="ignore") # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like the code ^^ is to work around some error case, so why the change?

return df


Expand Down Expand Up @@ -703,7 +682,7 @@ def encode_textual(
max_df: float = 0.2,
min_df: int = 3,
) -> Tuple[pd.DataFrame, List, Any]:
_, _, SentenceTransformer = lazy_import_has_dependancy_text()
_, _, SentenceTransformer, _ = deps.sentence_transformers

t = time()
text_cols = get_textual_columns(
Expand Down Expand Up @@ -1096,7 +1075,7 @@ def process_nodes_dataframes(
text_cols: List[str] = []
text_model: Any = None
text_enc = pd.DataFrame([])
has_deps_text, import_text_exn, _ = lazy_import_has_dependancy_text()
has_deps_text, import_text_exn, _, _ = deps.sentence_transformers
if has_deps_text and (feature_engine in ["torch", "auto"]):
text_enc, text_cols, text_model = encode_textual(
df,
Expand Down Expand Up @@ -1317,7 +1296,7 @@ def process_edge_dataframes(

:return: Encoded data matrix and target (if not None), the data encoders, and the label encoder.
"""
lazy_import_has_min_dependancy()
deps.scipy
from sklearn.preprocessing import (
MultiLabelBinarizer,
)
Expand Down Expand Up @@ -1467,7 +1446,7 @@ def transform_text(
text_cols: Union[List, str],
) -> pd.DataFrame:
from sklearn.pipeline import Pipeline
_, _, SentenceTransformer = lazy_import_has_dependancy_text()
_, _, SentenceTransformer, _ = deps.sentence_transformer()

logger.debug("Transforming text using:")
if isinstance(text_model, Pipeline):
Expand Down Expand Up @@ -2005,8 +1984,7 @@ def _featurize_nodes(
logger.info("--- [[ RE-USING NODE FEATURIZATION ]]")
fresh_res = copy.copy(res)
for attr in ["_node_features", "_node_target", "_node_encoder"]:
if hasattr(old_res, attr):
setattr(fresh_res, attr, getattr(old_res, attr))
setattr(fresh_res, attr, getattr(old_res, attr))

return fresh_res

Expand Down Expand Up @@ -2210,9 +2188,9 @@ def transform(self, df: pd.DataFrame,
"""

# This is temporary until cucat release
if 'cudf' in str(getmodule(df)):
if 'cudf.core.dataframe' in str(getmodule(df)):
df = df.to_pandas() # type: ignore
if (y is not None) and ('cudf' in str(getmodule(y))):
if (y is not None) and ('cudf.core.dataframe' in str(getmodule(y))):
y = y.to_pandas() # type: ignore

if kind == "nodes":
Expand Down
Loading