Skip to content

work around numpy 1.14.0 bug in einsum - #7105

Merged
bsipocz merged 3 commits into
astropy:masterfrom
eteq:fix-7051
Jan 22, 2018
Merged

bsipocz merged 3 commits into
astropy:masterfrom
eteq:fix-7051

Conversation

@eteq

@eteq eteq commented Jan 21, 2018

Copy link
Copy Markdown
Member

This fixes #7051 by explicitly setting the optimize keyword of einsum to False, only for numpy v1.14.0 , as the underlying bug will be fixed in 1.14.1 (numpy/numpy#10371).

In passing I note that there may be a factor of ~2x speedup in 1.14.1 though, where einsum defaults to optimize=True (probably because BLAS is now used in einsum). So 👏 there!

@eteq eteq added this to the v2.0.4 milestone Jan 21, 2018
@eteq
eteq requested a review from mhvk January 21, 2018 06:03
@astropy-bot

astropy-bot Bot commented Jan 21, 2018 •

Copy link
Copy Markdown

Hi there @eteq 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

Everything looks good from my point of view! 👍

If there are any issues with this message, please report them here.

@eteq eteq changed the title workaround numpy 1.14.0 bug in einsum work around numpy 1.14.0 bug in einsum Jan 21, 2018
@mhvk

mhvk commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

@eteq - the fix is definitely OK, though I wonder why in this place one isn't using matmul - maybe it predates my adding a backport for that.

@bsipocz

bsipocz commented Jan 21, 2018

Copy link
Copy Markdown
Member

@eteq @mhvk - how do we know that numpy/numpy#10371 will be released in 1.14.1? It's milestoned to 1.15.0, though there were some backport labelling going on that I'm clearly not familiar with.

@mhvk

mhvk commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

@bsipocz - that one has been backported (numpy/numpy#10396). The numpy workflow is that any PR that should be backported gets labelled as such, and when that is done, the label is removed.

@bsipocz

bsipocz commented Jan 21, 2018

Copy link
Copy Markdown
Member

@mhvk - Thank you, this is very useful to know I didn't notice backports are done in separate PRs.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a bit more thought: for 2.0.4, this seems the best and easiest bug-fix, so let's just get it in. For 3.1, it may be worth reworking in terms of matmul -- we probably need to look into it anyway since there is a comment just below that the differentials should be sped up.

(And I'd also like to think a bit about defining a __rmatmul__ that takes care of it: matrix @ representation would seem pretty unambiguous).

@mhvk

mhvk commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

The test failure is strange - why is numpy 1.14 not found?

@saimn

saimn commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

The bug happens only with Python 2, so this could go directly on the v2.0.X branch ? Also another way to fix it without having to check the numpy version would be to use str('...ij,j...->i...').

@bsipocz

bsipocz commented Jan 22, 2018

Copy link
Copy Markdown
Member

@saimn - This was also an issue not only on python2, but on appveyor, too: https://ci.appveyor.com/project/Astropy/astropy/build/1.0.9904#L5357

I'm inclined to merge it now, and deal with the numpy install issue separately.

@bsipocz

bsipocz commented Jan 22, 2018

Copy link
Copy Markdown
Member

Or, actually there is one related test failure, I wonder it can be dealt with here or it has to be in a new PR, too?
https://travis-ci.org/astropy/astropy/jobs/331381898#L5158

@saimn

saimn commented Jan 22, 2018

Copy link
Copy Markdown
Contributor

Hmm i think the Appveyor failure is a different beast, i.e. not the one reported initially in #7051. And it looks like the remaining Travis error is the same thing.

@bsipocz

bsipocz commented Jan 22, 2018

Copy link
Copy Markdown
Member

Hmm, this one now needs a rebase, I may do it in ~15 mins, after everything else is merged and ready to be backported.

@bsipocz

bsipocz commented Jan 22, 2018

Copy link
Copy Markdown
Member

Rebased, and I've also added a fix for the PEP8 issue I accidentally introduced by editing #7104 on github...

@bsipocz bsipocz mentioned this pull request Jan 22, 2018
@bsipocz

bsipocz commented Jan 22, 2018

Copy link
Copy Markdown
Member

OK, this is now only have the numpy dev issue mentioned above, and I suggest to fix that in a separate PR.

@bsipocz
bsipocz merged commit a26e0d0 into astropy:master Jan 22, 2018
bsipocz added a commit that referenced this pull request Jan 22, 2018
work around numpy 1.14.0 bug in einsum
@eteq
eteq deleted the fix-7051 branch January 22, 2018 20:08
@eteq

eteq commented Jan 22, 2018 •

Copy link
Copy Markdown
Member Author

To close the loop on the above discussions, @siamn and @mhvk - #7109 fixed the numpy travis install problem. I think that also moved the numpy 1.14 testing to one of the other builds, so that strongly implies to me all is good here.

@mhvk

mhvk commented Jan 22, 2018

Copy link
Copy Markdown
Contributor

OK, great!

bsipocz added a commit that referenced this pull request Jan 22, 2018
work around numpy 1.14.0 bug in einsum
@rjs3273

rjs3273 commented Jan 23, 2018

Copy link
Copy Markdown

I may have found another instance of this same issue. einsum() is also called in astropy/coordinates/builtin_frames/utils.py and is causing me very similar looking "TypeError: For this input type lists must contain either int or Ellipsis" errors.

To replicate the error I can simply follow the "Barycentric and Heliocentric Light Travel Time Corrections" example in the astropy docs
http://docs.astropy.org/en/stable/time/#barycentric-and-heliocentric-light-travel-time-corrections.

from astropy import time, coordinates as coord, units as u
ip_peg = coord.SkyCoord("23:23:08.55", "+18:24:59.3",unit=(u.hourangle, u.deg), frame='icrs')
greenwich = coord.EarthLocation.of_site('greenwich')
times = time.Time([56325.95833333, 56325.978254], format='mjd',scale='utc', location=greenwich)
ltt_bary = times.light_travel_time(ip_peg)

gives the error message

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/coordinates/builtin_frames/utils.py", line 125, in norm
return p/np.sqrt(np.einsum('...i,...i', p, p))[..., np.newaxis]
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/einsumfunc.py", line 1087, in einsum
einsum_call=True)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/einsumfunc.py", line 688, in einsum_path
input_subscripts, output_subscript, operands = _parse_einsum_input(operands)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/einsumfunc.py", line 432, in _parse_einsum_input
raise TypeError("For this input type lists must contain "

Simply inserting "optimize=False" in the einsum() call fixes the error.

I am running numpy 1.14.0, astropy 2.0.3, python 2.7 on MacOS 10.13.2

@mhvk

mhvk commented Jan 24, 2018

Copy link
Copy Markdown
Contributor

At least that is the only other occurrence in astropy!

@rjs3273

rjs3273 commented Jan 24, 2018 via email

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

numpy TypeError on coordinate transform (TypeError: For this input type lists must contain either int or Ellipsis)

5 participants