-
Notifications
You must be signed in to change notification settings - Fork 32
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
Optimize Face Bounds Computation #877
Conversation
ASV BenchmarkingBenchmark Comparison ResultsBenchmarks that have improved:
Benchmarks that have stayed the same:
Benchmarks that have got worse:
|
For the first step in optimizing, I've looked at decorating some of the commonly called functions with Next step will be to eliminate any unnecessary coordinate conversion calls, such as This might look like us providing both the def _point_within_gca(pt_latlon,
pt_xyz,
gca_a_latlon,
gca_a_xyz,
gca_b_latlon,
gca_b_xyz,
is_directed=False): Hopefully once we've moved these conversions out of each function call, we can see if the remaining logic can be decorated with |
Line 77 in 1790e0e
I had a question about this and other parts of the code where the Cartesian coordinates are converted to latlon in radians. Are we able to use the |
I have also been considering this design today. It will be highly beneficial to call the coordinate conversion only once, both for performance and accuracy. We can extract all functions that take node coordinates as input and ensure that both Cartesian and spherical coordinates are required as parameters.
That is another reason why I have been advocating for better documentation and conventions for the coordinate system. Currently, we have the following coordinate systems:
Before we attempt to rewrite everything, we must ensure which coordinate systems we are using across the entire project. |
Agreed, was thinking of this as well.
We have some documentation here in our user guide. https://uxarray.readthedocs.io/en/latest/user-guide/representation.html Any suggestions on how we could improve this?
Wondering if it would make sense to include a Hopefully the normalization inconsistencies will be resolved with #878 |
I think what we've discovered so far is that the degrees are solely for the users, while all calculations use radians since the |
That's a good catch!
We use -180 to 180 since it makes certain visualizations tasks (i.e. projections and the use of the
This isn't fully the case. Many of our internal functions (i.e. BallTree) use degrees.
One option could be to use Scipy's degree implementations, but I'm not sure how much this implementation differs from Numpy's https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.sindg.html#scipy.special.sindg |
Would you mind explaining this code snippet for me? Lines 288 to 292 in 1790e0e
|
Sure, I wonder if you want to hop into a quick call? |
I understand the benefits of using the -180 to 180 range for visualization tasks and consistency with existing datasets. My algorithms do not expose the longitude range to users, nor do they modify existing longitudes, so this shouldn't pose a significant issue. However, I wanted to bring this up because if we require functions to take
Is this because we directly use the
I compared the source code for Scipy's
I haven't delved deeply into the internal workings of both functions, but we could perform a simple benchmark to compare their running times and compatibility if needed. |
After some further optimizations, this is the point that I've gotten to. Looks like the FMA DisabledFMA Enabled~14.1s Execution Time Do you think anything from here could possible act as an alternative to using |
From the benchmarks run above, looks like almost a 8-10x improvement in performance across the board with these changes. I was also able to compute the bounds on a 30km MPAS atmosphere grid (655k Faces, 1,310,000 nodes) in about 40 seconds, which is a significant improvement and wouldn't of been possible without these optimizations. |
I've been giving this case a lot of thought, considering my research findings and the intricacies of floating point operations. Given the technical details involved with floating point operations, I won't delve into too much detail to avoid overwhelming you. Here's a summary of my thoughts:
Rationale:
Conclusion:Since FMA isn't currently ready for the Python package, we can focus on the general case first and handle the ill-conditioned cases later. The package should primarily use normal floating point operations, and when an ill-conditioned case arises, it's not overly time-consuming to apply the more accurate operations to this subset. If you have any questions or need further clarification, please don't hesitate to ask. I'm more than happy to discuss and explain everything. |
I think this option makes the most sense to me and would fit the expectations of our users also.
I wouldn't say that we are not allowed, it's more something that we haven't explored yet. It might be worth considering. I appreciate the write up and glad that we're making some good improvements both to the performance and accuracy of our operators. |
Merging this so that we can continue our work with #785 Overall, was able to get about a 10-12x performance improvement by using |
Thank you very much for your excellent jobs! And I will open another issue and PR about our rewriting decisions for the helper functions. |
Sounds good! |
Closes #730
Overview
allclose
,isclose
,cross
,dot
) that were used by helper functions when building the face boundsExpected Usage