-
Notifications
You must be signed in to change notification settings - Fork 11
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
BUMBANUMBA #36
BUMBANUMBA #36
Conversation
Ok. I also need some advice with the docs, because that's what failed the second time around. How should I fix that? |
I marked this as a draft because of two things. I will have to learn a little bit more about the summary for modules so that the module with the jitted functions becomes documented. Also, it looks like this branch is not producing the correct results. I just looked at a picture of the results two steps in, and something is different than |
Hi @ericbarefoot, awesome effort.
Yeah, I can verify this branch produces different results, based on my PR for a consistency test. I thought maybe this was because your branch uses a non-jitted I don't think it matters what you decide to name the file with all these new jitted functions. It could make sense to change the name since I'm gonna send you a PR now that jits the |
Nevermind, I think that part actually is fine lol |
Hey @amoodie I just went spelunking to find the bugs that were messing with water and sediment routing. I found and fixed them, but it affects some of the things in your PR, which I didn't want to change further to find the problem. Can you rebase your branch on ef18f96? This is a rebase of the changes I made on the new stuff in develop. That way I can easily include your fixes to the docs and the other list typing stuff. |
This makes them available outside the object, which is important in some cases, and the class just gets them from here. feat: make shared_tools into a module, not a class. This is in preparation for jitting, since we want them to be standalone functions. feat: break out step that updates water parcel positions These functions now become helper utility functions in shared_tools, and are wrapped by update_Q, which handles them all, and passes them what they need. refactor: break out sed functions into smaller functions This modularizes the code and makes it easier to compile. feat: jit the functions apply jit to functions, and fix some type problems that came along with refactoring. refactor: move next step calculation to jitted functions The next slowest operation was getting the indexes of the next cells, so I moved that to a jitted function too. refactor: jit the calculation of weight array for the water fix: move random number generation into numba Copy of what @amoodie did in DeltaRCM#27 fix: some broken tests to test the shared tools portion. fix: add numba to requirements fix: move all inlet picking into the random_pick function There's essentially no difference between the random_pick function and the random_pick_inlet function other than there is no preference given for the inlet cells, so you can pick whichever one, so I just adjust the mechanism to use the existing random pick machinery. fix: water and sediment routing bugs that caused inconsistent behavior There were two issues with the refactoring. One was that water routing developed a flat flow field because I wasn't adding each passing water parcel to the Q field. The other was related to sediment parcel routing, where I had transcribed the i and j of stepping incorrectly in the jitted functions.
This reverts commit b5e3bcf.
Updated sediment routing to use the same weight choosing function as water, and fixed the water so that any non-disallowed cell is given equal weight if all weight is zero
also repair broken test
Hey all: I think this is ready to go now. I wrote a whole bunch of tests for the new jitted functions today. Turns out, the coveralls doesn't say lines are "covered" if the code is compiled prior to running, so we can think about how to address that if you all would like to make sure we continue to increase coverage always. |
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 tried messing around with an environment variable to the coverage job on travis (NUMBA_DISABLE_JIT
) I thought would fix this coverage issue, but apparently it does not, based on some comments around github. I think we could open an issue to keep checking on it and see if a fix comes along.
Based on 092d98c, you were able to fix the bug without changing the test_consistent
? Nice. And did you run that yaml configuration I had given you to verify the bug is resolved?
Otherwise, looks good to me 👍
As far as I can tell, it's close enough yeah. I was surprised too.
Yup. no more strange zig zagging paths, and it makes it through without erroring out. |
Thinking about it a bit more, I guess it makes sense. The test never had the bug (only ran for one small timestep), so why would it be affected by the bug being fixed‽
Cool, anyway yeah lgtm, not sure if Jay wants to look or not. |
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.
Great effort! This is all really clean and easy to follow.
More a note than any commentary on this PR, but in general we should probably try running longer "test" simulations for large changes to check for longer-term stability as those types of checks are not going to be possible via unit testing or any continuous integration method.
self.iwalk = np.array([[-1, 0, 1], | ||
[-1, 0, 1], | ||
[-1, 0, 1]]) | ||
self.iwalk = shared_tools.get_iwalk() | ||
|
||
self.jvec = np.array([[-sqrt05, -1, -sqrt05], |
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.
If iwalk
and jwalk
are moved to shared_tools
(which is fine by me) does it make sense to also move over all of the other walk/vector arrays like jvec
and so forth?
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.
Yeah, I think I see a larger 'reorganize and tidy' PR on the horizon, where we once again move stuff into separate classes. I think this relates to the milestones for splitting out the hydrodynamics and morphodynamics code into separate modular classes, with a utils
or similar module that they both access. I think moving a bunch of the stuff like the definitions of these arrays into something like utils
makes a lot of sense.
Oh, and regarding the coverage not including compiled code I also did a cursory search and did not find a solution that looks like it will work for us. The closest thing I found was this, which pretty much required writing a |
Numba speedup
I was interested in what @amoodie did in #27, so I started messing around with it too once #29 was merged. In particular, with more modular functions, how could a lot of things be moved into a
utils
-like module, jitted, and then called that way.I basically took a profile of the code, and just started jitting the things that took the longest, to see how fast we could get. So far, I have pulled out and jitted the following:
There are quite a few more things that take a significant fraction of the computational time, and could also go into jitted functions. However, I'm stopping here for now, because with the default parameters, I see about a 25x speedup from the develop branch with these adjustments. Using this script, I get about 9.54s per iteration for develop, and 0.36s per iteration after jitted functions are compiled.
Needs
I'd like y'all's feedback on the organization. Basically, I'm not sure about placing these things in a separate utils, so maybe you can comment @amoodie, if it would be good to move the things that belong to water into the
water_tools
file, but have them as standalone jitted functions in thewater_tools
module.Some other ideas I have that may make this organization more intuitive and the long function calls more palatable:
shared_tools
toutils
like @amoodie didutils
module as getter functions. I kinda did this for theself.iwalk
andself.jwalk
attributes, which are initialized now using a getter function fromshared_tools
. The idea is that if these getters become compiled themselves, we could have them called inside jitted functions and not have to supply them in the arguments.Thoughts??