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: KeyError: 'asscalar' #363

Closed
beniroquai opened this issue Nov 10, 2022 · 15 comments · Fixed by #365
Closed

Import Error: KeyError: 'asscalar' #363

beniroquai opened this issue Nov 10, 2022 · 15 comments · Fixed by #365
Assignees
Labels
bug Something isn't working

Comments

@beniroquai
Copy link

Hey, first of all, great project! I'm really looking forward to work with this software! However, I'm running into some problems when installing and starting Scico. I'm running it on a Macbook M1, where I installed jax/jaxlib using this command:

conda install -c conda-forge jaxlib
conda install -c conda-forge jax

I had to make sure that scico leaves this installation untouched - I guess it tries installing its pip equivalent? Didn't work out nicely..

After trying to import the scico package I get this error:

Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:01:00) 
[Clang 13.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import jax
>>> impor scico
  File "<stdin>", line 1
    impor scico
          ^
SyntaxError: invalid syntax
>>> import scico
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bene/Dropbox/Dokumente/Promotion/PYTHON/scico/scico/__init__.py", line 24, in <module>
    from . import numpy
  File "/Users/bene/Dropbox/Dokumente/Promotion/PYTHON/scico/scico/numpy/__init__.py", line 43, in <module>
    _wrappers.wrap_recursively(vars(), mathematical_functions, _wrappers.map_func_over_blocks)
  File "/Users/bene/Dropbox/Dokumente/Promotion/PYTHON/scico/scico/numpy/_wrappers.py", line 57, in wrap_recursively
    target_dict[name] = wrap(target_dict[name])
KeyError: 'asscalar'

I get this in the latest pipy and github version. I haven't looked too deep into the sources to understand therror- but is it known already?
Thanks! Help very much appreciated!

@bwohlberg
Copy link
Collaborator

Thanks for the bug report. This is not a known issue. Is this using the latest scico release from pypi, or the development version from github? What are the version numbers of jaxlib and jax that you have installed?

@beniroquai
Copy link
Author

Thanks for fast response!
I installed latest github and pipy version. The error appears with scico-0.0.4.dev0+cf5ad2f(latest github).

jax.__version__ '0.3.24'
jaxlib.__version__ '0.3.24'

@bwohlberg
Copy link
Collaborator

Thanks. Those are very recent versions of jaxlib/jax that are not yet included in the supported range specified in the scico requirements.txt file, but they are passing all tests in CI running under Linux. Perhaps this is an OSX specific issue. We'll have to investigate further.

@beniroquai
Copy link
Author

I'm observing the same issue when downgrading to jax=0.3.0.

@bwohlberg bwohlberg added the bug Something isn't working label Nov 10, 2022
@bwohlberg
Copy link
Collaborator

I'm unable to replicate the problem under OSX. Could you please run the following and let me know the output?

import jax.numpy as jnp
print(jnp.asscalar)
print(jnp.__dict__['asscalar'])

@beniroquai
Copy link
Author

Thanks @bwohlberg for helping out. I get the following error:

>>> import jax.numpy as jnp
>>> print(jnp.asscalar)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'jax.numpy' has no attribute 'asscalar'
>>> print(jnp.__dict__['asscalar'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'asscalar'

This indeed is weird. I'll quickly try that on colab, but this should be fine I gues..

@bwohlberg
Copy link
Collaborator

On further investigation, I see that numpy.asscalar is deprecated, and while asscalar is still present in jax.numpy, the docs indicate that calling it will raise a NotImplementedError. What is really strange, though, is that it's present in our installation of jax 0.3.24, and not in yours.

It would be useful to confirm that asscalar is the only problematic function in jax.numpy. Could you please comment out the asscalar entry on line 209 of your copy of scico/numpy/_wrapped_function_lists.py to see if that resolves your input problems?

@bwohlberg bwohlberg self-assigned this Nov 11, 2022
@beniroquai
Copy link
Author

Hey @bwohlberg, with outcomment this line, the problem disappears.

As for the notes, I installed jax using this command on a MacBook m1:

conda install -c conda-forge jaxlib
conda install -c conda-forge jax

After that I'm trying to run this notebook: https://scico.readthedocs.io/en/latest/examples/deconv_microscopy_tv_admm.html

which gave me an error with a missing six package, that I had to (re)install (?).

Later I'm running into a connection timeout error, but this is hopefully due to my non stable internet connection right now. I'll try it once I'm back home again.
Btw. the notebook does not run on google colab right now. It throws the following error:

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting git+https://github.com/lanl/scico
  Cloning https://github.com/lanl/scico to /tmp/pip-req-build-sxfyw5bu
  Running command git clone -q https://github.com/lanl/scico /tmp/pip-req-build-sxfyw5bu
  Running command git submodule update --init --recursive -q
  From https://github.com/lanl/scico-data
   * branch            c3b7db1f69967833d178e029713d5200f9fc6304 -> FETCH_HEAD
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: jax<=0.3.23,>=0.3.0 in /usr/local/lib/python3.7/dist-packages (from scico==0.0.4.dev0+cf5ad2f) (0.3.23)
Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.7/dist-packages (from scico==0.0.4.dev0+cf5ad2f) (1.7.3)
Requirement already satisfied: jaxlib<=0.3.22,>=0.3.0 in /usr/local/lib/python3.7/dist-packages (from scico==0.0.4.dev0+cf5ad2f) (0.3.22+cuda11.cudnn805)
Collecting flax>=0.4.0
  Downloading flax-0.6.1-py3-none-any.whl (185 kB)
     |████████████████████████████████| 185 kB 3.4 MB/s 
Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from scico==0.0.4.dev0+cf5ad2f) (3.2.2)
Collecting pyabel>=0.8.5
  Downloading PyAbel-0.8.5.tar.gz (147 kB)
     |████████████████████████████████| 147 kB 45.0 MB/s 
Requirement already satisfied: tifffile in /usr/local/lib/python3.7/dist-packages (from scico==0.0.4.dev0+cf5ad2f) (2021.11.2)
Collecting bm3d>=3.0.9
  Downloading bm3d-3.0.9-py3-none-any.whl (8.4 MB)
     |████████████████████████████████| 8.4 MB 58.7 MB/s 
Collecting imageio>=2.17
  Downloading imageio-2.22.4-py3-none-any.whl (3.4 MB)
     |████████████████████████████████| 3.4 MB 43.6 MB/s 
Requirement already satisfied: numpy>=1.20.0 in /usr/local/lib/python3.7/dist-packages (from scico==0.0.4.dev0+cf5ad2f) (1.21.6)
Collecting svmbir>=0.3.0
  Downloading svmbir-0.3.0.tar.gz (65 kB)
     |████████████████████████████████| 65 kB 4.3 MB/s 
  Installing build dependencies ... error
WARNING: Discarding https://files.pythonhosted.org/packages/0c/16/909f298bd2ab94ff8d60522107f8c5d2ae77a5870932d6d2d131c3ae31a1/svmbir-0.3.0.tar.gz#sha256=840bbd99de28483e4d7b3642b6fc5552fd0e3954a6db5288b82840a75105d8ce (from https://pypi.org/simple/svmbir/). Command errored out with exit status 1: /usr/bin/python3 /tmp/pip-standalone-pip-pbtta9bj/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-psqxo_y8/overlay --no-warn-script-location -v --no-binary :none: --only-binary :none: -i https://pypi.org/simple --extra-index-url https://us-python.pkg.dev/colab-wheels/public/simple/ -- setuptools wheel 'numpy==1.22.*' Cython Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement svmbir>=0.3.0 (from scico) (from versions: 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5, 0.2.6, 0.2.7, 0.2.8, 0.2.9, 0.2.10, 0.3.0)
ERROR: No matching distribution found for svmbir>=0.3.0
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-1-4c8b686bae40>](https://localhost:8080/#) in <module>
      6 get_ipython().system('pip install git+https://github.com/lanl/scico')
      7 
----> 8 import scico.numpy as snp
      9 from scico import functional, linop, loss, plot, util
     10 from scico.examples import downsample_volume, epfl_deconv_data, tile_volume_slices

ModuleNotFoundError: No module named 'scico'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

I don't think this is a related issue, is it?

@bwohlberg
Copy link
Collaborator

Thanks for reporting the notebook problem on Colab. I have opened #364 as a note that this should be resolved. Note that the launch binder alternative does still seem to be working correctly. I'll create a PR to address the asscalar issue that's the primary subject of this issue.

@beniroquai
Copy link
Author

Ok. Seems to be working on my machine. But I must admit, I'm not yet familiar with the way arm64 and x86_64 packages are to be installed on this new machine. Most likely the error is due to some conflicts with these versions. Thanks for helping!

@bwohlberg
Copy link
Collaborator

Agreed, it's probably some difference between the arm64 and x86_64 packages. We'll close this issue when #365 is merged. Please don't hesitate to open another issue if you experience further problems.

bwohlberg added a commit that referenced this issue Nov 14, 2022
* Remove deprecated asscalar (see #363)

* Handle names not in target_dict

* Bump jaxlib/jax versions

* Resolve mypy errors and warnings

* Attempt to debug test failures

* Clean up

* Address test warnings
@lamyc
Copy link

lamyc commented Dec 17, 2022

Hello @bwohlberg, I encounter the same KeyError: 'asscalar' mentioned by @beniroquai

package_info:

python=3.10
scico=0.03
jax=0.3.17
jaxlib=0.3.15
numpy=1.23.5

All installed via pip, following Installation guide.
However, the issue goes away when I downgrade the numpy version to 1.22.3
So perhaps a solution is to change the requirement.txt to limit the version of numpy installed?

p.s.
this is my first time writing a issue, so please forgive my poor deliverance.

@bwohlberg
Copy link
Collaborator

Thanks for reporting this issue. Could you please try installing the current development version from github and let us know if the problem persists? We have made some changes to resolve this issue, but the updated version has not yet been released.

@lamyc
Copy link

lamyc commented Dec 18, 2022

I installed scico-0.0.4.dev0+d05ff9c (latest github). I tested it with both numpy-1.21.5 and numpy-1.23.5, which the latter would casue KeyError: 'asscalar' for the previous version scico-0.0.3. The problem no longer exists.

@bwohlberg
Copy link
Collaborator

Great, thank you for confirming that it's resolved by the unreleased changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants