-
Notifications
You must be signed in to change notification settings - Fork 279
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
Make sure positions are in code_length in get_radius function. #4091
Conversation
Good catch. I note that |
Once upon a time in the long past we talked about having some types of unit arrays that were "IndexArrays" (@jzuhone worked on this for a while) where the units were immutable internally to the array. Because of the amount of time we spend doing stuff like unit checks and unit conversions even internally in |
Good points. I'll do this. |
Is this test failure related? |
It's not. It's just a random failure. I note that it's the third time I'm seeing it this week, so maybe we'll need to do something about it, but for now let's just try again |
I had commented on this on the closed PR but perhaps it can help the discussion here?: Perhaps we are mixing two concepts?
The positive side effect that it also avoid unnecessary computation which saves a little time. Is there already the concept of "original_units" ? I.e. give us a simple way to check in what units the data was provided? |
The closest we have to this is the field info container (e.g.,
In theory, |
yt/fields/field_functions.py
Outdated
@@ -18,8 +18,11 @@ def get_radius(data, field_prefix, ftype): | |||
if any(data.ds.periodicity): | |||
rdw = radius2.v | |||
for i, ax in enumerate("xyz"): | |||
pos = data[ftype, f"{field_prefix}{ax}"] | |||
if str(pos.units) != "code_length": | |||
pos.convert_to_units("code_length") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now we're converting in place, changing the data outputted by ytree. Are we certain this isn't going to cause problems in ytree ?
Also I don't think I understand why it can't be changed in ytree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we can guarantee that every yt frontend is reading particle positions in "code_length", the problem will not be limited to ytree. It makes me nervous that we are not checking units before operating on memory views.
I'm happy to switch it back to making a copy. Would the solution I proposed above be better? That is, should we check the units of the position field using the field info container and the convert the other variables to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we can guarantee that every yt frontend is reading particle positions in "code_length", the problem will not be limited to ytree. It makes me nervous that we are not checking units before operating on memory views.
ok that makes sense.
I'm happy to switch it back to making a copy.
I think it'd be the best option because it's the most conservative approach for these edge cases where we're not sure what to expect, and also an incentive for frontend development to use "code_lenght"
more uniformly since it allows to use the fast track where no copy is performed.
Would the solution I proposed above be better? That is, should we check the units of the position field using the field info container and the convert the other variables to that?
I guess I don't have strong opinions there. I think the current solution is already good in that it is probably the simplest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with sticking with the simplest solution for now. I'll switch thing back to using a copy and forgo any further optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is now in an uncontroversial state that should preserve both backward compatibility for ytree and recent optimization when available.
PR Summary
PR #4079 changed results for particle_radius calculation within a yt frontend embedded in ytree. After some digging, I discovered that positions for that frontend are returned in "unitary" units which, for that data, are not the same as "code_length". Unless we have a specification requiring positions to be returned in "code_length" for all frontends, this change is probably necessary. This may be quietly failing for other frontends.
PR Checklist