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

Some scripts (plot_spherical.py, cpplint.py, ...) are incompatible with Python 3 #169

Closed
beiwang2003 opened this issue Oct 12, 2018 · 3 comments
Assignees
Labels
enhancement Improve an existing Athena++ component good first issue Ideal for developers looking to dive into the Athena++ codebase visualization Visualization scripts included in repository wontfix No action planned
Milestone

Comments

@beiwang2003
Copy link
Contributor

beiwang2003 commented Oct 12, 2018

Bug report

The current plotting script /vis/python/plot_spherical.py only works with Python 2. When using Python 3, it reports the following error message:

[beiwang@tigercpu python]$ python --version
Python 3.6.5 :: Anaconda, Inc.
[beiwang@tigercpu python]$ python plot_spherical.py ../../bin/236bcf9_result/simple_torus.prim.00010.athdf rho rho_10.png --logc --vmin=1.0e-6 --vmax=1.0e0
/usr/licensed/anaconda3/5.2.0/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Traceback (most recent call last):
  File "plot_spherical.py", line 378, in <module>
    main(**vars(args))
  File "plot_spherical.py", line 170, in main
    vals_left = 0.5 * (data[kwargs['quantity']][(nx3/2)-1, :, :]
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

(need to test the other scripts in vis/python/ for compatibility)

Version info

  • Compiler and version:
module list
  1) anaconda3/5.2.0                    5) hdf5/intel-16.0/intel-mpi/1.8.16
  2) intel-mkl/2019.0/0/64              6) intel-advisor/2019.0-570901
  3) intel/19.0/64/19.0.0.117           7) intel-vtune/2019.0-570779/64
  4) intel-mpi/intel/2018.3/64
  • Hardware and cluster name (if applicable): The login node of Tigercpu
@felker felker added this to the v1.1.x milestone Oct 12, 2018
@felker felker added enhancement Improve an existing Athena++ component visualization Visualization scripts included in repository labels Oct 12, 2018
@felker felker changed the title python 2 and python 3 incompatibility in vis/python Scripts in vis/python/ are incompatible with Python 3 Oct 12, 2018
@felker
Copy link
Contributor

felker commented Oct 12, 2018

I made sure that all .py files in tst/ were compatible with both Python 2 and 3 in #48, but I never checked the remaining Python source code in vis/python/.

Since we document in the Wiki that both are supported, we should either update the documentation or extend these scripts to Python 3 if it is straightforward. Low priority, though.

@felker
Copy link
Contributor

felker commented Oct 16, 2018

@chaochinyang correctly pointed out to me that the C++ style linting script provided by Google, tst/style/cpplint.py, is also incompatible with Python 3. This can be a problem if the shebang

#!/usr/bin/env python

points to a Python 3 distribution, since the script will check the first file piped to program, '../../src/athena.hpp', and then silently die without checking/reporting any style errors. Although, such a system would technically not be in accordance with PEP 394 which suggests:

If the python command is installed, it should invoke the same version of Python as the python2command (however, note that some distributions have already chosen to have python implement the python3 command)

When invoked, python2 should run some version of the Python 2 interpreter, and python3 should run some version of the Python 3 interpreter.

Nevertheless, the current "silent failure" should be addressed. Some options:

  • There are third-party patches (some use the six module) that make it compatible for both Python 2 and 3.
  • Could change shebang to #!/usr/bin/env python2, but I assume that many systems/package distributions still don't follow PEP 394 and only install a python binary. (EDIT: I later made this change in af3f7ba on 2018-11-02)
  • Hardcode a Python 3 trap in cpplint.py
  • Document any restriction to Python 2

Info on the copy of cpplint.py in Athena++:

  • Added to repository in commit 4efd31a on 2018-04-18
  • Matches google/styleguide version from 2018-04-03:
    google/styleguide@1b206ee
  • Even though Google's version of their linter has a Python 2 vs. Python 3 switch at the top of the file:
try:
  xrange          # Python 2
except NameError:
  xrange = range  # Python 3

it does not claim compatibility with Python 3 at this time (although there is little-to-no documentation of this, see google/styleguide#277).

@felker felker changed the title Scripts in vis/python/ are incompatible with Python 3 Some scripts (plot_spherical.py, cpplint.py, ...) are incompatible with Python 3 Oct 16, 2018
@felker felker self-assigned this Oct 16, 2018
felker added a commit that referenced this issue Nov 2, 2018
- Not compatible with Python 3, see #169. Follow PEP 394 and reserve "python"
  for scripts that are compatible with both Py2 and Py3.

- Remove artificial C++ style error in field.hpp

- This is the first change from upstream cpplint.py
google/styleguide@1b206ee

Calling "python -u" in cpplint_athena.sh has fixed the previously
jumbled stdout and stderr from cpplint.py calls to sys.stdout.write()
and sys.stderr.write() in the Jenkins log. However, unbuffered writes
may have been an issue with regression test crashes in macOS and on
Travis CI (see #47), but it was most likely a red herring due to the
known O_NONBLOCK bug in MPICH's mpirun(). Monitor this.

See if Jenkins log now contains pure output from git ls-tree command.
@felker felker added the good first issue Ideal for developers looking to dive into the Athena++ codebase label Jan 22, 2019
@stale
Copy link

stale bot commented Apr 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve an existing Athena++ component good first issue Ideal for developers looking to dive into the Athena++ codebase visualization Visualization scripts included in repository wontfix No action planned
Projects
None yet
Development

No branches or pull requests

3 participants