-
Notifications
You must be signed in to change notification settings - Fork 280
Gravity simulation with Choclo as engine #1285
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
Conversation
Don't force values to be np.float32, Numba will cast them automatically when trying to write to the preallocated matrix.
When defining the decorated functions as attributes of the class, then every new simulation is created, they need to be recompiled.
Move the test for gravity inversions to pure pytest. Use parametrization to run the same test using geoana and choclo. Add a `random_seed` to `make_synthetic_data` to avoid tests failing randomly.
Add tests for sanity checks of the engine and some other attributes. Add tests for running the forward in parallel and serial. Add test for conversion factor.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1285 +/- ##
==========================================
- Coverage 82.36% 82.35% -0.02%
==========================================
Files 164 165 +1
Lines 25099 25239 +140
==========================================
+ Hits 20674 20785 +111
- Misses 4425 4454 +29 ☔ View full report in Codecov by Sentry. |
Remove the `random_seed` argument added to the `make_synthetic_data` method. The change was moved to a separate PR to check the reason why some tests were failing in CI.
This reverts commit dfec5d8.
|
@santisoler : does this mean SimPEG PF will support GPU with this change? |
Not with the changes in this PR. I'm using Numba, but running the simulation in CPU. |
jedman
left a comment
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.
fantastic work @santisoler , this addition dramatically improves the performance of the gravity simulation. looking forward to propagating it to the magnetic simulation too!
|
Hi @domfournier! Thanks for those suggestions. I've applied some of them, specially the ones related to reducing code duplication. I've also replied the other ones explaining better my design decisions. I think we can move forward with this PR if you are happy with it, and continue the discussion about design on a future PR. Specially the one I'm going to open implementing the mag simulation. |
domfournier
left a comment
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.
Thanks for the changes. Looking good on this side.
Sounds good yea, we can generalize on the second round for mag. Looking forward to testing the speedup! |
jcapriot
left a comment
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've been playing around a bit with numba myself the last couple days. I like that it's able to jit a lot of the functions in here so we start avoiding the costly operations of initializing new (rather large) numpy arrays and also avoid the stacking operation. Avoiding the costly multiprocessing step here is great too. I've been looking into updating geoana as well so those functions could be used inside numba's functions. At that point the speed is roughly the same between the two (geoana vs choclo).
Eventually we should put in the simplifications when you have gxx, gyy, and gzz, but as those are not currently in the code (for accuracy reasons) no reason to add them in now.
| raise TypeError(f"Invalid mesh of type {self.mesh.__class__.__name__}.") | ||
| return cell_nodes | ||
|
|
||
| def _get_tensormesh_cell_nodes(self): |
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.
Let's get a new version of discretize out and tagged so we don't need to include this bit.
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.
Sure!
|
Thanks @jcapriot for the review! Yes, numba has neat things indeed!
Yes. We might want to add some optimizations to this simulation when having multiple components of acceleration or tensor. These are also relevant for the mag simulation that's coming shortly. |
Use the new `discretize.TensorMesh.cell_nodes` instead of the private method that was in the simulation. Increase the minimum version of discretize in `setup.py` and `environment_test.yml`.
|
@jcapriot I've updated the simulation to use the new |
jcapriot
left a comment
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.
Throughout the documentation, instead of writing array write either numpy.ndarray (or array_like where appropriate). Also, it could be worth it to run a comparison with the most recent geoana with the jittable prism kernels now available there.
|
@jcapriot do you think we should change anything else on this PR, or is it ready to be merged? |
The only thing I would change is the actual argument named after I feel like the default behavior (in the future) should be: If I also think we should probably advertise it as being |
|
I am really excited to get this in, congrats @santisoler! This accomplishes a major goal of having a concrete connection between the Fatiando and SimPEG communities and the benchmarks you have shown are impressive! We now have a couple of implementations, and that can be useful for a number of reasons, including testing. I think the discussion about the default behaviour is an important one. Again, nice work Santi! |
|
Oh yeah, I fully support keeping |
|
Considering the work you've been doing in allowing geoana kernels to be called within Numba jitted functions, it makes sense to rename the argument to
I'm sorry for making that impression. The main difference in performance doesn't come from |
|
I just merged this! 🚀 Thanks a lot for the reviews, help and comments. I'm looking forward to open the PR for the mag simulation now! I'll keep this branch up for a while, so I don't break any environment in case someone was using it. But I'll eventually delete it, so please install the latest version on |
|
💥 So excited to see this come in! |
* main: Fix minor flake8 warning (simpeg#1307) Gravity simulation with Choclo as engine (simpeg#1285)
Summary
Add the option to use Choclo as the engine for running the gravity simulations, considerably reducing the computation time of the forward simulations and the creation of the sensitivity matrix. Add Choclo as one of the optional dependencies. Update and extend tests for the gravity simulation using pytest. By default, the simulation will use
geoanaas the engine. Users can alternatively choosechocloinstead if it's installed.PR Checklist
expect style.
to a Pull Request
@simpeg/simpeg-developerswhen ready for review.Reference issue
What does this implement/fix?
Additional information