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

Import error npyx 4.0.6, python3.9 NameError: name 'KronDecomposed' is not defined` #398

Open
Antorithms opened this issue Sep 29, 2024 · 8 comments

Comments

@Antorithms
Copy link

Antorithms commented Sep 29, 2024

Dear Maxime,
Thanks for developing this nice package!
With npyx version 4.0.6 I get the error below after installing in a conda environment with python==3.9 and trying to import from npyx.spk_wvf import get_peak_chan. Can you reproduce the issue?
Thanks for your help.
Anto

In [2]: from npyx.spk_wvf import get_peak_chan
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 from npyx.spk_wvf import get_peak_chan

File -\lib\site-packages\npyx\__init__.py:7
      1 # -*- coding: utf-8 -*-
      3 from . import utils, inout, gl, spk_t, spk_wvf, corr, stats, plot,\
      4               behav, merger, circuitProphyler, feat, metrics,\
      5               info, model, h5, testing, ml, datasets
----> 7 from .c4 import dataset_init, misc
      9 try:
     10     import torch

File -\lib\site-packages\npyx\c4\__init__.py:5
      2 import torch
      4 from .acg_augmentations import *
----> 5 from .acg_vs_firing_rate import *
      6 from .dl_transforms import *
      7 from .dl_utils import *

File -\lib\site-packages\npyx\c4\acg_vs_firing_rate.py:24
     18 from .dataset_init import (
     19     extract_and_check,
     20     extract_and_merge_datasets,
     21     get_paths_from_dir,
     22 )
     23 from .monkey_dataset_init import MONKEY_CENTRAL_RANGE, get_lisberger_dataset
---> 24 from .predict_cell_types import get_n_cores, redirect_stdout_fd
     26 BIN_SIZE = 1
     27 WIN_SIZE = 200

File -\lib\site-packages\npyx\c4\predict_cell_types.py:42
     36 from .misc import require_advanced_deps
     37 from .plots_functions import (
     38     C4_COLORS,
     39     plot_features_1cell_vertical,
     40     plot_survival_confidence,
     41 )
---> 42 from .run_deep_classifier import (
     43     CustomDataset,
     44     encode_layer_info,
     45     ensemble_predict,
     46     load_ensemble,
     47     prepare_classification_dataset,
     48 )
     50 MODELS_URL_DICT = {
     51     "base": "https://figshare.com/ndownloader/files/42117042?private_link=2530fd0da03e18296d51",
     52     "mli_clustering": "https://figshare.com/ndownloader/files/42129447?private_link=d508ebc51d544ed8cd4c",
     53     "layer_information": "https://figshare.com/ndownloader/files/42853297?private_link=6531855c261b7bad032d",
     54     "layer_information_mli_clustering": "https://figshare.com/ndownloader/files/42853708?private_link=3a81e48aff77d844a402",
     55 }
     57 HESSIANS_URL_DICT = {
     58     "base": "https://figshare.com/ndownloader/files/42117033?private_link=2530fd0da03e18296d51",
     59     "mli_clustering": "https://figshare.com/ndownloader/files/42129435?private_link=d508ebc51d544ed8cd4c",
     60     "layer_information": "https://figshare.com/ndownloader/files/42853141?private_link=6531855c261b7bad032d",
     61     "layer_information_mli_clustering": "https://figshare.com/ndownloader/files/42853567?private_link=3a81e48aff77d844a402",
     62 }

File -\lib\site-packages\npyx\c4\run_deep_classifier.py:354
    348         new_probs = new_probs.numpy()
    350     return new_probs
    353 @require_advanced_deps("torch", "torchvision", "laplace")
--> 354 def get_kronecker_hessian_attributes(*kronecker_hessians: KronDecomposed):
    355     hessians = []
    356     for h in kronecker_hessians:

NameError: name 'KronDecomposed' is not defined
@m-beau
Copy link
Owner

m-beau commented Sep 29, 2024

Hi there!

It seems like you are trying to import a dependency that you shouldn't need when using the boilerplate version of npyx: would you mind uninstalling it fully and reinstalling it from pip with 'pip install npyx', and let me how that goes?

Hope you find it useful :)

@Antorithms
Copy link
Author

Tried again but the error persists.
Thanks for your help.
Anto

@m-beau
Copy link
Owner

m-beau commented Sep 30, 2024

All right - can you tell me what was your exact procedure to install npyx (did you use a fresh conda environment?), and also tell me what is the installed version (you can find this out by running 'pip list' and scrolling to npyx in your terminal)

@Antorithms
Copy link
Author

version is 4.0.6
After a few tests I think the issue might be causewd by other packages installing packages that are only there in a dev npyx version (?) and tricking npyx in believing that and trying to load functions that are not there, could that be the case?
Thanks,
Anto

@m-beau
Copy link
Owner

m-beau commented Nov 26, 2024

Hi Anto,

Did you manage to get npyx to work for you? Indeed, it seems like you were importing packages that you shouldn't be importing when using the basic version - I would recommend uninstalling npyx (pip uninstall npyx) and reinstalling it from pip.

@Antorithms
Copy link
Author

The thing is that in my case npyx needs to be part of a larger environment.
you can try to reproduce running this in a newly formed conda env
conda install -c conda-forge pip ffmpeg cupy cudatoolkit
pip install joblib jupyterlab ccf-streamlines npyx tdt cebra scipy numpy matplotlib nemos ffmpeg-python matplotlib-venn scikit-learn dlc2kinematics ipympl rastermap affinewarp moviepy

@m-beau
Copy link
Owner

m-beau commented Nov 28, 2024

Hmmm I cannot reproduce your error with the MWE that you provided.

It does sound like, because you have torch installed for cebra, that npyx believes that the 'developer' version is installed, but it should not pose any problem and I cannot reproduce your exact issue - this line should set KronDecomposed to None when laplace is not found:

try:
    from laplace import BaseLaplace, Laplace
    from laplace.utils import KronDecomposed
except ImportError:
    # Used for type hints, will be ignored if not installed
    BaseLaplace = Laplace = KronDecomposed = None

Can you confirm that this MWE does cause an error for you:

conda create -n test_env python==3.11
conda install -c conda-forge pip ffmpeg cupy cudatoolkit
pip install joblib jupyterlab ccf-streamlines npyx tdt cebra scipy numpy matplotlib nemos ffmpeg-python matplotlib-venn scikit-learn dlc2kinematics ipympl rastermap affinewarp moviepy
python

(now, in the python session)
from npyx.spk_wvf import get_peak_chan

@m-beau
Copy link
Owner

m-beau commented Dec 11, 2024

Hi Anto,

Any update?

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