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

QWidget: Must construct a QApplication before a QWidget #601

Closed
parviz-gh opened this issue Mar 2, 2024 · 23 comments
Closed

QWidget: Must construct a QApplication before a QWidget #601

parviz-gh opened this issue Mar 2, 2024 · 23 comments

Comments

@parviz-gh
Copy link

Describe the issue:

hello , I have tried to compare results from different versions of Kilosort . The problem is when I run Phy on KS4 results, I get this error
" IndexError: index 232 is out of bounds for axis 0 with size 232
QWidget: Must construct a QApplication before a QWidget .
while it doesnt give the error when I run the Phy on same data for KS2 and KS2.5 results .

@jacobpennington
Copy link
Collaborator

Hello,

Are you able to post the full trace-back for the error you got? Also, did you run Kilosort4 through the GUI or with a script/notebook?

@ckwalters
Copy link

ckwalters commented Mar 3, 2024

I'm getting the same error, full traceback:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\CKW\anaconda3\Scripts\phy.exe\__main__.py", line 7, in <module>
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1053, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 754, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phy\apps\__init__.py", line 244, in template_extract_waveforms
    model = load_model(params_path)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 1433, in load_model
    return TemplateModel(**get_template_params(params_path))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 339, in __init__
    self._load_data()
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 419, in _load_data
    self.sparse_clusters = self.cluster_waveforms()
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 1323, in cluster_waveforms
    data[clust, :, :] = self.sparse_templates.data[val[0], :, :]
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\numpy\core\memmap.py", line 334, in __getitem__
    res = super().__getitem__(index)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: index 250 is out of bounds for axis 0 with size 250
09:30:37.015 [E] __init__:62          An error has occurred (IndexError): index 250 is out of bounds for axis 0 with size 250
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\CKW\anaconda3\Scripts\phy.exe\__main__.py", line 7, in <module>
    sys.exit(phycli())
             ^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1053, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\core.py", line 754, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phy\apps\__init__.py", line 159, in cli_template_gui
    template_gui(params_path, **kwargs)
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phy\apps\template\gui.py", line 209, in template_gui
    model = load_model(params_path)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 1433, in load_model
    return TemplateModel(**get_template_params(params_path))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 339, in __init__
    self._load_data()
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 419, in _load_data
    self.sparse_clusters = self.cluster_waveforms()
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\phylib\io\model.py", line 1323, in cluster_waveforms
    data[clust, :, :] = self.sparse_templates.data[val[0], :, :]
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "C:\Users\CKW\anaconda3\Lib\site-packages\numpy\core\memmap.py", line 334, in __getitem__
    res = super().__getitem__(index)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: index 250 is out of bounds for axis 0 with size 250
QWidget: Must construct a QApplication before a QWidget

@allllex3202
Copy link

Hi Kilosort experts,

We got the similar error recently.
We're trying to using Kilosort 4 with Plexon's 24 linear channel data, were able to import, run the sorting processing, and make some plots using of your tutorials codes by modifying some parameters. However some attempts of the parameters would cause this type of error, which resulted in fail in launching the phy gui. [e.g. settings['nearest_templates'] = 10, or settings['nearest_chans'] = 1, or settings['cluster_pcs'] = 10 and so on.

The specific errors varies according to the input parameter, but always point to the same code line (IndexError), below is an example.


17:52:59.582 [E] init:62 An error has occurred (IndexError): index 14 is out of bounds for axis 0 with size 14
Traceback (most recent call last):
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\Scripts\phy.exe_main
.py", line 7, in
sys.exit(phycli())
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1157, in call
return self.main(*args, **kwargs)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 783, in invoke
return _callback(*args, **kwargs)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\click\decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\phy\apps_init
.py", line 159, in cli_template_gui
template_gui(params_path, **kwargs)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\phy\apps\template\gui.py", line 209, in template_gui
model = load_model(params_path)
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 1433, in load_model
return TemplateModel(**get_template_params(params_path))
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 339, in init
self._load_data()
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 419, in _load_data
self.sparse_clusters = self.cluster_waveforms()
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 1323, in cluster_waveforms
data[clust, :, :] = self.sparse_templates.data[val[0], :, :]
File "C:\Users\xx..xx\anaconda3\envs\kilosort\lib\site-packages\numpy\core\memmap.py", line 334, in getitem
res = super().getitem(index)
IndexError: index 14 is out of bounds for axis 0 with size 14

QWidget: Must construct a QApplication before a QWidget


Since we currently don't have a good sense of the working mechanism about these parameters, we'd very much appreciated if you can suggest some initial parameters for the 24 channels data processing, which seems to be critical for the sorting quality.

Many thanks!

@zm711
Copy link

zm711 commented Mar 4, 2024

@jacobpennington,

These look like Phy errors. The install instructions on your readme are now out of date for the current state of Phy. Phy now recommends to install from source rather than with a pip install.

@jacobpennington
Copy link
Collaborator

Hello,

I still haven't been able to reproduce this myself, but based on the traceback I think it's related to one of two things:

  1. a recent change in how variables were saved for phy
  2. differences in the Phy version being used.

For 1), please try pulling the latest copy of the repo and see if that fixes the issue, that change has been reverted. Or, if you don't want to wait for the sorting to run again, you can rename spike_templates.npy in the KS4 results folder to spike_detection_templates.npy (or something else, it won't be used by Phy), then make a copy of spike_clusters.npy and rename it to spike_templates.npy.

For 2), please follow the install instructions at https://github.com/cortex-lab/phy for installing Phy. I will update our readme to avoid confusion about that.

Please let me know if any of you continue to have issues after trying that.

@ckwalters
Copy link

@zm711 I had followed your instructions for phy install from source using .yml and an older version of python and got the same issue with only ks4, not ks2.5.

@zm711
Copy link

zm711 commented Mar 4, 2024

Jacob,
One last annoying point for Phy is that their readme instructions are missing a couple packages for the conda install and I have a PR open to fix their requirements.txt but Cyrille is a little busy now for upkeep. So if people come to Kilosort for help with Phy stuff the best recommendation is to install with the environment.yaml in the repo, but edit such that python < 3.12. I know it's an annoying workaround, but since I'm helping out with the issue tracker these qt widget issues come up a lot and they can usually be solved.

Thanks @ckwalters!
That's actually good to know. I wanted to make sure this was a ks4 issue and not a phy issue. So this puts the issue back on the KS side.

@jacobpennington
Copy link
Collaborator

From feedback in #604 it looks like the most recent changes to the code have fixed this issue, so if any of you haven't tried pulling the new version yet that would be my suggestion. Thanks for catching this!

@Alchemist-Y
Copy link

Alchemist-Y commented Mar 5, 2024

From feedback in #604 it looks like the most recent changes to the code have fixed this issue, so if any of you haven't tried pulling the new version yet that would be my suggestion. Thanks for catching this!

Jacob,
I tried your new version 1 hour ago, but the same bug still exists. Here is my full traceback.

12:27:55.580 [E] init:62 An error has occurred (IndexError): index 395 is out of bounds for axis 0 with size 394
Traceback (most recent call last):
File "C:\Users\alche\anaconda3\envs\kilosort\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\alche\anaconda3\envs\kilosort\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\alche\anaconda3\envs\kilosort\Scripts\phy.exe_main
.py", line 7, in
sys.exit(phycli())
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1157, in call
return self.main(*args, **kwargs)
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\click\core.py", line 783, in invoke
return _callback(*args, **kwargs)
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\click\decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\phy\apps_init
.py", line 159, in cli_template_gui
template_gui(params_path, **kwargs)
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\phy\apps\template\gui.py", line 209, in template_gui
model = load_model(params_path)
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 1433, in load_model
return TemplateModel(**get_template_params(params_path))
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 339, in init
self._load_data()
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 419, in _load_data
self.sparse_clusters = self.cluster_waveforms()
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\phylib\io\model.py", line 1323, in cluster_waveforms
data[clust, :, :] = self.sparse_templates.data[val[0], :, :]
File "C:\Users\alche\anaconda3\envs\kilosort\lib\site-packages\numpy\core\memmap.py", line 334, in getitem
res = super().getitem(index)
IndexError: index 395 is out of bounds for axis 0 with size 394

QWidget: Must construct a QApplication before a QWidget

Tnanks for catching this!

@ckwalters
Copy link

@jacobpennington Hi Jacob! Both of your fixes (duplicating the .npy file and re-installing kilosort) worked for me to allow me to open results in phy, but as of this morning 3/5 the setup.py file in the current repo is not working for me. I ended up using the setup.py file from the old repo which worked fine.

@jacobpennington
Copy link
Collaborator

@ckwalters What issue are you having with the setup file?

@jacobpennington
Copy link
Collaborator

@AlchemsitY Just double checking, did you reinstall from source after pulling the new version, or install in editable mode?

@ckwalters
Copy link

ckwalters commented Mar 5, 2024

@ckwalters What issue are you having with the setup file?

It was a setuptools_scm problem:

 × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [42 lines of output]
      WARNING setuptools_scm.pyproject_reading toml section missing 'pyproject.toml does
 not contain a tool.setuptools_scm section'
      Traceback (most recent call last):
        File "C:\Users\CKW\anaconda3\envs\kilosort\Lib\site-packages\pip\_vendor\pyproje
ct_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\CKW\anaconda3\envs\kilosort\Lib\site-packages\pip\_vendor\pyproje
ct_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\CKW\anaconda3\envs\kilosort\Lib\site-packages\pip\_vendor\pyproje
ct_hooks\_in_process\_in_process.py", line 149, in prepare_metadata_for_build_wheel     
          return hook(metadata_directory, config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\build_meta.py", line 366, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 40, in <module>
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\_distutils\core.py", line 147, in setup
          _setup_distribution = dist = klass(attrs)
                                       ^^^^^^^^^^^^
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\dist.py", line 303, in __init__
          _Distribution.__init__(self, dist_attrs)
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\_distutils\dist.py", line 283, in __init__
          self.finalize_options()
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\dist.py", line 654, in finalize_options
          ep(self)
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\overlay\Lib\site-pa
ckages\setuptools\dist.py", line 674, in _finalize_setup_keywords
          ep.load()(self, ep.name, value)
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\normal\Lib\site-pac
kages\setuptools_scm\_integration\setuptools.py", line 101, in version_keyword
          _assign_version(dist, config)
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\normal\Lib\site-packages\setuptools_scm\_
integration\setuptools.py", line 56, in _assign_version
          _version_missing(config)
        File "C:\Users\CKW\AppData\Local\Temp\pip-build-env-181s35hz\normal\Lib\site-packages\setuptools_scm\_
get_version_impl.py", line 112, in _version_missing
          raise LookupError(
      LookupError: setuptools-scm was unable to detect version for C:\Users\CKW\Kilosort\Kilosort4_20240305.  

      Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources
 (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and 
will not work.

      For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+htt
ps://github.com/user/proj.git#egg=proj
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

@Alchemist-Y
Copy link

@AlchemsitY Just double checking, did you reinstall from source after pulling the new version, or install in editable mode?

I excitedly found the version updated and tried the new one. Now I have established the solo environment for Phy, but new error is reported as the Traceback shows.Thanks for catching this.

Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "C:\Users\alche\anaconda3\envs\phy2\Scripts\phy.exe_main
.py", line 4, in
File "C:\Users\alche\anaconda3\envs\phy2\Lib\site-packages\phy_init
.py", line 21, in
from .utils.config import load_master_config
File "C:\Users\alche\anaconda3\envs\phy2\Lib\site-packages\phy\utils_init_.py", line 8, in
from .plugin import IPlugin, attach_plugins
File "C:\Users\alche\anaconda3\envs\phy2\Lib\site-packages\phy\utils\plugin.py", line 14, in
import imp
ModuleNotFoundError: No module named 'imp'

@zm711
Copy link

zm711 commented Mar 6, 2024

@AlchemsitY,

I have a PR open to fix this. But Phy can not be used with python 3.12 because of the removal of imp for importlib. So you need the env to be <3.12. This error is due to this.

@jacobpennington
Copy link
Collaborator

@ckwalters Which command are you using to install? I can only reproduce that error using python setup.py, which is deprecated.

@ckwalters
Copy link

ckwalters commented Mar 6, 2024

@jacobpennington I was using the instructions as written in the ks4 documentation,
python -m pip install .
But I'm seeing now there's a different suggested pip command in the readme

@jacobpennington
Copy link
Collaborator

@carsen-stringer Any ideas on the setup.py issue?

@Alchemist-Y
Copy link

@AlchemsitY,

I have a PR open to fix this. But Phy can not be used with python 3.12 because of the removal of imp for importlib. So you need the env to be <3.12. This error is due to this.

hi, zm711. Thanks for catching this. May I ask where is your PR about this error? I'd like to hava a try. Thanks a lot!

@zm711
Copy link

zm711 commented Mar 8, 2024

@AlchemsitY here

@Alchemist-Y
Copy link

@AlchemsitY here

Thanks a lot!

@carsen-stringer
Copy link
Member

The setuptools error can happen I believe if the repo folder is not actually a git clone, but a zipped git folder or a copied folder without a .git folder. What might be easier to recommend for non-developers is this command to install the git version (the user does need to have git installed): pip install git+https://github.com/mouseland/kilosort.git

@jacobpennington
Copy link
Collaborator

The original issue appears to be resolved. If you continue to have trouble with installation, please let us know in a new issue.

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

7 participants