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

Add support for Python 3.9 and 3.10 #117

Closed
nathanielvirgo opened this issue Feb 15, 2022 · 6 comments · Fixed by #120
Closed

Add support for Python 3.9 and 3.10 #117

nathanielvirgo opened this issue Feb 15, 2022 · 6 comments · Fixed by #120
Labels
enhancement New feature or request

Comments

@nathanielvirgo
Copy link

I don't know if this is a bug or a problem with my installation, but if I try to run a file containing only the line

from pgmax.fg import graph

I get the error

% /opt/local/bin/python3 /Users/nathaniel/Dropbox/Code/PGMax/test01.py
Traceback (most recent call last):
  File "/Users/nathaniel/Dropbox/Code/PGMax/test01.py", line 1, in <module>
    from pgmax.fg import graph
  File "/Users/nathaniel/Library/Python/3.9/lib/python/site-packages/pgmax/fg/graph.py", line 11, in <module>
    import pgmax.bp.infer as infer
  File "/Users/nathaniel/Library/Python/3.9/lib/python/site-packages/pgmax/bp/infer.py", line 6, in <module>
    import pgmax.bp.bp_utils as bp_utils
  File "/Users/nathaniel/Library/Python/3.9/lib/python/site-packages/pgmax/bp/bp_utils.py", line 11, in <module>
    @jax.partial(jax.jit, static_argnames="max_segment_length")
AttributeError: module 'jax' has no attribute 'partial'

This is with Python3.9 installed using Macports on MacOS 10.15.7. PGMax, jax and other prerequisities were installed with pip-3.9 install --user PGMax. I'm happy to give any other information about my installation if you can tell me how to obtain it.

@nathanielvirgo
Copy link
Author

nathanielvirgo commented Feb 15, 2022

I notice that the jax changelog for Sept 23 2021 says

jax.partial, and jax.lax.partial were accidental exports that have now been removed. Use functools.partial from the Python standard library instead.

So I would guess this is a bug

@StannisZhou
Copy link
Contributor

This has been addressed in #83 The current code uses correct functools.partial. See

@functools.partial(jax.jit, static_argnames="max_segment_length")

I believe if you do pip install --upgrade pgmax the issue would be resolved.

@nathanielvirgo
Copy link
Author

That's weird, I'm still getting the error. Here's the output from the upgrade command in case it helps.

% pip-3.9 install --upgrade pgmax
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pgmax in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (0.1.0)
Requirement already satisfied: jupyter<2.0.0,>=1.0.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from pgmax) (1.0.0)
Requirement already satisfied: jaxlib<0.2.0,>=0.1.67 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from pgmax) (0.1.76)
Requirement already satisfied: jax<0.3.0,>=0.2.14 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from pgmax) (0.2.28)
Requirement already satisfied: numpy<2.0.0,>=1.20.3 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pgmax) (1.21.4)
Requirement already satisfied: scipy<2.0.0,>=1.6.3 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from pgmax) (1.8.0)
Requirement already satisfied: matplotlib<4.0.0,>=3.4.2 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from pgmax) (3.5.1)
Requirement already satisfied: absl-py in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jax<0.3.0,>=0.2.14->pgmax) (1.0.0)
Requirement already satisfied: opt_einsum in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jax<0.3.0,>=0.2.14->pgmax) (3.3.0)
Requirement already satisfied: typing_extensions in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jax<0.3.0,>=0.2.14->pgmax) (3.10.0.2)
Requirement already satisfied: flatbuffers<3.0,>=1.12 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jaxlib<0.2.0,>=0.1.67->pgmax) (2.0)
Requirement already satisfied: ipykernel in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter<2.0.0,>=1.0.0->pgmax) (6.9.0)
Requirement already satisfied: jupyter-console in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter<2.0.0,>=1.0.0->pgmax) (6.4.0)
Requirement already satisfied: notebook in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter<2.0.0,>=1.0.0->pgmax) (6.4.8)
Requirement already satisfied: ipywidgets in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter<2.0.0,>=1.0.0->pgmax) (7.6.5)
Requirement already satisfied: qtconsole in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter<2.0.0,>=1.0.0->pgmax) (5.2.2)
Requirement already satisfied: nbconvert in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter<2.0.0,>=1.0.0->pgmax) (6.4.2)
Requirement already satisfied: python-dateutil>=2.7 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from matplotlib<4.0.0,>=3.4.2->pgmax) (2.8.2)
Requirement already satisfied: packaging>=20.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from matplotlib<4.0.0,>=3.4.2->pgmax) (21.3)
Requirement already satisfied: pyparsing>=2.2.1 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from matplotlib<4.0.0,>=3.4.2->pgmax) (2.4.7)
Requirement already satisfied: pillow>=6.2.0 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from matplotlib<4.0.0,>=3.4.2->pgmax) (8.4.0)
Requirement already satisfied: fonttools>=4.22.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from matplotlib<4.0.0,>=3.4.2->pgmax) (4.29.1)
Requirement already satisfied: cycler>=0.10 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from matplotlib<4.0.0,>=3.4.2->pgmax) (0.11.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from matplotlib<4.0.0,>=3.4.2->pgmax) (1.3.2)
Requirement already satisfied: six>=1.5 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from python-dateutil>=2.7->matplotlib<4.0.0,>=3.4.2->pgmax) (1.16.0)
Requirement already satisfied: traitlets<6.0,>=5.1.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (5.1.1)
Requirement already satisfied: nest-asyncio in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (1.5.4)
Requirement already satisfied: ipython>=7.23.1 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (8.0.1)
Requirement already satisfied: jupyter-client<8.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (7.1.2)
Requirement already satisfied: debugpy<2.0,>=1.0.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (1.5.1)
Requirement already satisfied: appnope in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.1.2)
Requirement already satisfied: tornado<7.0,>=4.2 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (6.1)
Requirement already satisfied: matplotlib-inline<0.2.0,>=0.1.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.1.3)
Requirement already satisfied: pickleshare in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.7.5)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (3.0.28)
Requirement already satisfied: setuptools>=18.5 in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (59.1.1)
Requirement already satisfied: backcall in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.2.0)
Requirement already satisfied: decorator in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (4.4.2)
Requirement already satisfied: jedi>=0.16 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.18.1)
Requirement already satisfied: pygments in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (2.9.0)
Requirement already satisfied: stack-data in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.1.4)
Requirement already satisfied: pexpect>4.3 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (4.8.0)
Requirement already satisfied: black in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (22.1.0)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jedi>=0.16->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.8.3)
Requirement already satisfied: pyzmq>=13 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter-client<8.0->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (22.3.0)
Requirement already satisfied: entrypoints in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter-client<8.0->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.4)
Requirement already satisfied: jupyter-core>=4.6.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jupyter-client<8.0->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (4.9.1)
Requirement already satisfied: ptyprocess>=0.5 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from pexpect>4.3->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.7.0)
Requirement already satisfied: wcwidth in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.2.5)
Requirement already satisfied: mypy-extensions>=0.4.3 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from black->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.4.3)
Requirement already satisfied: click>=8.0.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from black->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (8.0.3)
Requirement already satisfied: pathspec>=0.9.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from black->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.9.0)
Requirement already satisfied: platformdirs>=2 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from black->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (2.5.0)
Requirement already satisfied: tomli>=1.1.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from black->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (2.0.1)
Requirement already satisfied: nbformat>=4.2.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipywidgets->jupyter<2.0.0,>=1.0.0->pgmax) (5.1.3)
Requirement already satisfied: widgetsnbextension~=3.5.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipywidgets->jupyter<2.0.0,>=1.0.0->pgmax) (3.5.2)
Requirement already satisfied: jupyterlab-widgets>=1.0.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipywidgets->jupyter<2.0.0,>=1.0.0->pgmax) (1.0.2)
Requirement already satisfied: ipython-genutils~=0.2.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from ipywidgets->jupyter<2.0.0,>=1.0.0->pgmax) (0.2.0)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbformat>=4.2.0->ipywidgets->jupyter<2.0.0,>=1.0.0->pgmax) (4.4.0)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter<2.0.0,>=1.0.0->pgmax) (0.18.1)
Requirement already satisfied: attrs>=17.4.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter<2.0.0,>=1.0.0->pgmax) (21.4.0)
Requirement already satisfied: prometheus-client in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from notebook->jupyter<2.0.0,>=1.0.0->pgmax) (0.13.1)
Requirement already satisfied: jinja2 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from notebook->jupyter<2.0.0,>=1.0.0->pgmax) (3.0.3)
Requirement already satisfied: Send2Trash>=1.8.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from notebook->jupyter<2.0.0,>=1.0.0->pgmax) (1.8.0)
Requirement already satisfied: terminado>=0.8.3 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from notebook->jupyter<2.0.0,>=1.0.0->pgmax) (0.13.1)
Requirement already satisfied: argon2-cffi in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from notebook->jupyter<2.0.0,>=1.0.0->pgmax) (21.3.0)
Requirement already satisfied: argon2-cffi-bindings in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from argon2-cffi->notebook->jupyter<2.0.0,>=1.0.0->pgmax) (21.2.0)
Requirement already satisfied: cffi>=1.0.1 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from argon2-cffi-bindings->argon2-cffi->notebook->jupyter<2.0.0,>=1.0.0->pgmax) (1.15.0)
Requirement already satisfied: pycparser in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi->notebook->jupyter<2.0.0,>=1.0.0->pgmax) (2.21)
Requirement already satisfied: MarkupSafe>=2.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from jinja2->notebook->jupyter<2.0.0,>=1.0.0->pgmax) (2.0.1)
Requirement already satisfied: defusedxml in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (0.7.1)
Requirement already satisfied: jupyterlab-pygments in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (0.1.2)
Requirement already satisfied: testpath in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (0.5.0)
Requirement already satisfied: pandocfilters>=1.4.1 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (1.5.0)
Requirement already satisfied: nbclient<0.6.0,>=0.5.0 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (0.5.10)
Requirement already satisfied: bleach in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (4.1.0)
Requirement already satisfied: mistune<2,>=0.8.1 in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (0.8.4)
Requirement already satisfied: webencodings in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from bleach->nbconvert->jupyter<2.0.0,>=1.0.0->pgmax) (0.5.1)
Requirement already satisfied: qtpy in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from qtconsole->jupyter<2.0.0,>=1.0.0->pgmax) (2.0.1)
Requirement already satisfied: pure-eval in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.2.2)
Requirement already satisfied: executing in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (0.8.2)
Requirement already satisfied: asttokens in /Users/nathaniel/Library/Python/3.9/lib/python/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter<2.0.0,>=1.0.0->pgmax) (2.0.5)

@StannisZhou
Copy link
Contributor

StannisZhou commented Feb 15, 2022

OK it's because of the use of python 3.9. Latest version of the package has support for python 3.7 and 3.8 at the moment. Support for python 3.9 and 3.10 shouldn't cause problems but unfortunately is not currently included. We will make some tests and include support.

For now, one option is to create a virtual environment with python 3.8 and install the package. A simple way to do this is with anaconda:

  1. Install miniconda
  2. Do
conda create -n pgmax-venv python=3.8
conda activate pgmax-venv
pip install pgmax==0.2.2
  1. Run any experiments within the newly created venv.

@StannisZhou StannisZhou added the enhancement New feature or request label Feb 15, 2022
@StannisZhou StannisZhou changed the title Jax error on importing Add support for Python 3.9 and 3.10 Feb 15, 2022
@StannisZhou
Copy link
Contributor

As a temporary workaround you can also do pip install git+https://github.com/StannisZhou/PGMax.git@python. Will open a PR when things are more thoroughly tested.

@nathanielvirgo
Copy link
Author

Thank you, using 3.8 works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants