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

Question regarding the main GRAPE module import #32

Open
RemyLau opened this issue Mar 12, 2023 · 1 comment
Open

Question regarding the main GRAPE module import #32

RemyLau opened this issue Mar 12, 2023 · 1 comment

Comments

@RemyLau
Copy link

RemyLau commented Mar 12, 2023

Hi! One minor question/suggestion: I'm wondering if it would be a better idea not to load all modules as is done right now. For example, when I want to load from the local module utils.py, it fails because utils was taken by ensmallen. One way I've tried to work around this is to pop the automatically loaded ensmallen utils module by sys.modules.pop['utils'].

grape/grape/__init__.py

Lines 13 to 30 in 788e195

def import_all(module_locals):
"""Execute dynamic loading of submodules."""
import ensmallen as _ensmallen
import embiggen as _embiggen
import sys as _sys
import pkgutil as _pkgutil
for _module in (_ensmallen, _embiggen):
for _loader, _module_name, _is_pkg in _pkgutil.iter_modules(_module.__path__):
if not _is_pkg:
continue
if _module_name.startswith(("_", "~")):
continue
_loaded_module = _loader.find_module(
_module_name
).load_module(_module_name)
_sys.modules[f'grape.{_module_name}'] = _loaded_module
module_locals[_module_name] = _loaded_module

Would it be better to simply do the following instead of importing everything?

import embiggen
import ensmallen

__all__ = ["embiggne", "ensmallen"]  # or add whatever top level modules that make sense
RemyLau added a commit to krishnanlab/obnb that referenced this issue Mar 12, 2023
* import relevant grape submodules instead of directly importing grape

AnacletoLAB/grape#32

* create align_to_ids method for BaseFeature object

* make sure the embeddings ids are aligned with that of the input graph
@LucaCappelletti94
Copy link
Member

Hi @RemyLau! I am thinking about some alternative ways to bypass this issue. The complex import procedure was designed to resolve directly the sub-packages, without having to add the middle call, which I found tedious. Which feature would you like to import from utils? We'll find a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants