Repository navigation
New strategy to choose optimal cutoff in Grid.move_to_empty - #1565
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1565 +/- ##
==========================================
+ Coverage 81.65% 82.00% +0.34%
==========================================
Files 18 18
Lines 1401 1389 -12
Branches 272 272
==========================================
- Hits 1144 1139 -5
+ Misses 211 206 -5
+ Partials 46 44 -2
☔ View full report in Codecov by Sentry. |
|
This likely depends on the Python version as well? Did you try on 3.10? 3.11 has perf improvements. |
|
sure, forgot to mention, I used python 3.11.1
Il Lun 19 Dic 2022, 03:28 rht ***@***.***> ha scritto:
… This likely depends on the Python version as well? Did you try on 3.10?
3.11 has perf improvements.
—
Reply to this email directly, view it on GitHub
<#1565 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQH6VXZY3LVANTTTK4YXLFTWN7B4RANCNFSM6AAAAAATCH5CRI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
What are the 2 numbers for 3.10? |
|
There is a minimal difference 3.10 -> 0.388, 3.11 -> 0.384 It has almost no impact on the cutoff values |
|
example: 3.10 -> prediction at 100 -> 54.159 3.10 -> prediction at 10000 ->9726.317 I'd use the 3.11 values for everything, the difference in the prediction is very minimal |
|
I see, then we can use 3.11, but needs to add comment saying that the number is for 3.11 only. One issue is that only you can quickly update the numbers to reflect 3.12, unless there is a standalone script that benchmarks and outputs the numbers. Why does Agents.jl need only a single cutoff number, but 2 in Mesa? |
|
Agent.jl cutoff value uses a more roughly approximation, the way with 2 values reflects the fact that there is not just 1 parameter which controls the time of execution of the two branches, but we have two independent parameters, in the sense that one can have an arbitrary value given the value of the other one, they are:
That's why we have 2 parameters instead of just 1, using just the density is not a complete way to compute the cutoff. For the other question, the cutoff value can be easily updated running the code above, but you are right, it is actually necessary to add the last part which transforms the parameters, I'll change the code adding that part. |
|
ok, now the code is complete, it prints the exact parameters values! |
|
any comments on this one @rht? |
|
The benchmark code could be made clearer. First/second branch should be renamed to the actual method naming, maybe "random_retries" and "with_empties" or something. The perf improvement is only for the case when the density is almost 100% (and so there is no rush to merge this), but I think the main contribution of this PR is in the rigor for calculating cutoff. Not sure if a GH comment is a good place to "store" the code for the cutoff finder. |
|
We can put maybe a cleaned-up version in the tests folder? |
|
what about this last proposal @rht? |
|
The tests folder doesn't make sense to me. The benchmarking code doesn't count as a test. But I haven't come up with a better location either, hence why I didn't answer your question. I think a benchmark or misc folder would be fine though. This doesn't affect the API at all, and so can always be safely moved to a separate repo when it becomes too big. My default would be misc/benchmark_grid_move_to_empty_cutoff.py. Is there a way to abstract out the |
|
Rebased. For future update, the benchmark code should live in |

I calculated the optimal cutoff for move_to_empty...but it wasn't as simple as I was expecting :-)
The problem is that a unique optimal cutoff value doesn't exist because, while the first branch has fixed time of execution if you fix a density (number of empty cells over the total number of cells), the second one doesn't since it operates on the empty cells iterating on them so the relevant parameter here is exclusively the number of empty cells which is not unique if the density is fixed. This means that, given a certain number of total cells, we need to find what is the optimal value of empty cells so as to switch between the two branches/algorithms. This is done through the following piece of code:
which produced the following prediction function with the optimal cutoff values from the powers of 2 between 5 and 23:
The prediction function was chosen so that the limiting value was 1 and the function was always increasing as one would expect.
Things to notice in the code which produces the output:
calc_exec_time_randrangewas used to check ifrandom.randrangehad a variable time of execution in relation to the range of values, this didn't happen, it is almost constant, so we can say that the only relevant parameter for the time of the first branch is the density of the grid;find_curve_for_first_branchis used to find the curve of times of execution for the first branch in the case of maximum value of number of total cells (2**23 is used in the code). You just need to calculate this curve one time because for each density there is (roughly) only one corresponding value of time of execution;find_curve_for_second_branchwas used to find the curve of timings for the second branch; notice that it starts to search from the value given infrom_val = 0 if not all_values else all_values[-1][1]because the optimal cutoff is always increasing more and more the value of the total number of cells increases;func(x, a, b)was then transformed in the modified code because I realized a simpler expression was possible.Hope that is not impossible to follow along the code!