-
Notifications
You must be signed in to change notification settings - Fork 9
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
Change weight calculations for water and sediment routing #29
Change weight calculations for water and sediment routing #29
Conversation
The goal was to get the water routing functions in order of how they are called during a timestep, and bring called functions closer to their calling functions.
As originally written, the code would calculate the weighted probability of stepping to a given cell on the fly, meaning that this computation happened every time parcels stepped forward. This change moves the computation of the probabilities to the front of the operation, meaning that before any water parcels route, we pre-compute all the random walk probabilities. I also incorporated elements of the random walk choice making itself, which turned out to be an expensive procedure. Now, the `get_weight_at_cell()` function should return a flattened 1D array that contains the cumulative weights. this array is reshaped to be a 3x3 array giving the window around the current cell.
Some things were written in list comprehensions that were better expressed more succinctly. I did this and eliminated an unneccesary self.count attribute
Two more list comprehensions exported to functions, the distance and new step calculators.
mentioned by @amoodie in DeltaRCM#28, this is a change to the defaults. only changed defaults, not the other stuff
documentation says that topo diffusion should happen after sand deposition, but before mud deposition.
Also, I did no documentation or new tests. Again, like #27 this is meant to be for feedback, not merging as-is. |
Coolio, I think it makes sense to do this before any jitting. It'll be no problem to implement that after.
|
ahh so you changed functionality, so my suggestion above about the testing will fail, I think. I see this is related to #9, so I guess we want to make the change, and I can remake the test file in the future. |
I am a bit behind on some of the "new" changes you all are proposing but will be catching up soon. But with regards to this, I was never sure if that change in order was made intentionally to solve some other instability or what. It seems like it must have been done intentionally. |
I actually just made this change based on the documentation. I'm fine to move it back actually. Let's put this in a different issue and I can scrub this from this PR. I think a new issue, and some subsequent work would be good to figure if this should be here or not. |
What do you think @elbeejay ? |
Interesting. I tried changing it back, and it fails anyway. Let me go commit by commit and see if I can figure out what changes it. EDIT: the test in the consistency check fails on my develop @amoodie. |
I have no preference either way. I can see the value in both proposed solutions. It is such a small thing for someone to change to suit their needs anyway. With regards to the routing and order of diffusion, there doesn't seem to be any explanation for the change. Topographic diffusion used to be implemented after the routing of coarse particles al la the Matlab order of operations (old commit). But after the |
lol yeah it's failing on mine now too 👀 The more I think about it though, based on what you said in your now edited comment about the number of times |
Defer to future investigation in DeltaRCM#30 if we want to change these.
Groovy, so I'll go ahead and merge this, then we can think about integrating numba for additional speedup for fun and profit. |
Change weight calculations for water and sediment routing
Overview
This is a rival to #27, where I implement some things that @amoodie and I have also talked about, but do no
jit
-ting on the code. Instead, I basically took the perspective that calculating the probability weights for neighbors of a cell is too expensive to do every step of the way, so if possible, it should be computed beforehand. For the water calculations, this makes a lot of sense, since the probability field for water only depends on the surface and the inertial component of flow. These are updated five times throughout every timestep, and 2000 water parcels route using the same field. Here, I move it to the top of every water iteration loop, and pre-compute probabilities for the whole array. I also took some of the process for selecting the random pick into the weighting function itself, so that no sums need to be calculated to pick.This kind of scheme isn't possible with the sediment, because erosion and deposition change the probability field with every step, so unfortunately, we have to calculate weights on the fly. I made the random pick function compatible across both too.
Speedup
The net result of this is a pretty hefty speedup, since so much computation time is spent moving water around. These little tweaks give me ~ a 50% speedup. Using @amoodie's script:
I get about 2:45 min on my old-a$$ laptop when I run on our
develop
. I get about 1:10 min with this PR.I think this and #27 are compatible. One thing to consider, is that I think
numba
has a@jitclass
decorator, and we could maybe do that withutils
or something?Small sidenote: @amoodie, I implemented one aspect of #28, just changing the default yaml. If you'd like to, I'm happy to incorporate the other stuff here too, but wanted feedback on this, rather than that.