-
Notifications
You must be signed in to change notification settings - Fork 27
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
Numpy errors are supressed by default #177
Comments
At least I can say that the reason for this setting is that many of the formulas would raise warnings all the time, due to intermediate states of the calculation, even though the final results are finite (not NaN or Inf). You can see in this one that The default should probably be to suppress the warnings, but it would be nice to give users control over it. How should that be, a global setting or a context manager? The setting would have to get into every compute submodule. |
Ok, I see. Both ideas seem ok:
import numpy as np
import vector
v1 = vector.obj(pt=1, phi=0, eta=1, E=1)
v2 = vector.obj(pt=1, phi=np.pi, eta=1, E=1)
np.errstate(all="ignore"): # ignore the error that the following line should generate
new_vector = v1 + v2
print(new_vector.mass) # this should print -1.23, but due to the coordinate system, will be -inf Searching the
import numpy as np
import vector
vector.show_errors = False
v1 = vector.obj(pt=1, phi=0, eta=1, E=1)
v2 = vector.obj(pt=1, phi=np.pi, eta=1, E=1)
new_vector = v1 + v2
print(new_vector.mass) I'm not sure what is the best way to give users control over it, but if it's the case that many of the formulas would raise warnings all the time1 then the global setting might be better. Footnotes
|
A third possibility would be to put an Also, we'd have to decide whether to call out infinity as being as bad as not a number. I think infinity is more benign than not a number: it appears in cases that—if there were any small errors—would be large numbers instead of infinity, and they do the right things in
This is true for all the NumPy warnings, just because that's how warnings work in Python. (For that reason, I don't see them as being very helpful. They tell you that something bad happened, but by not stopping the program and but roasting themselves, they don't tell you where or how many times the bad thing happened. And then, if the bad thing is in an intermediate step and expected, they become useless noise. On the other hand, these warnings can also be turned into errors, which are useful if they can be suppressed when they're expected. |
I think there should at least be an option to have infinity shown as a warning. But I do see the utility you mentioned of not marking infinity as a bad number. Are you thinking of a global verbosity config? |
I guess it should have the same or a similar interface to |
Some coordinate systems can not represent some vectors. For example, if adding two vectors in pt,phi,eta,E coordinates that have opposite azimuthal components that add to zero, the resulting longitudinal coordinate eta will be infinity:
By default, such errors are suppressed in the library
vector/src/vector/_compute/lorentz/add.py
Line 201 in 69d0b1d
Without that line, the default Numpy error would be shown
I think it would be better if the user is made aware of the error by default (rather than suppressing by default). Additionally, that leaves the choice of suppressing errors or not to the user, by adding
numpy.errstate(all="ignore")
in their code.The text was updated successfully, but these errors were encountered: