Fix inconsistent model state when add_agent! is called with out-of-bounds position#1197
Fix inconsistent model state when add_agent! is called with out-of-bounds position#1197Vyshnavi0702 wants to merge 4 commits intoJuliaDynamics:mainfrom
Conversation
|
Hi! This PR fixes the inconsistent model state when Please let me know if any changes or additional tests are needed. |
Datseris
left a comment
There was a problem hiding this comment.
Hi, thanks for the PR! try-catch must be avoided in any performance-relevant code. Is also unecessary here. You can check manually whether the agent is within the allowed and if not then return the alternative clause.
|
the condition should be checked before |
|
Bump here. |
…nt! implementation
|
Hi! I have updated the implementation to avoid try/catch as suggested and resolved the merge conflicts. All tests pass locally. Please let me know if further changes are needed. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1197 +/- ##
===========================================
+ Coverage 70.12% 84.84% +14.71%
===========================================
Files 42 42
Lines 2718 2936 +218
===========================================
+ Hits 1906 2491 +585
+ Misses 812 445 -367 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Datseris
left a comment
There was a problem hiding this comment.
This PR adds a lot of unecessary white spaces in various files unrelated to the PR, and as such the Runic tests fail. Please remove these.
|
I cleaned the PR and removed unrelated file changes. Please let me know if any further changes are needed. |
Datseris
left a comment
There was a problem hiding this comment.
This PR doesn't achieve anything. It certainly does not change any code functionality. Here you have replaced add_agent_own_pos! with the source code of the function. Naturally this doesn't change anything, it's exactly the same code.
The fact that tests are missing from this PR reflects this: you need to add tests that actually test that the issue is solved, by copying the code from the original issue.
Summary
Fixes an inconsistency where
add_agent!throws aBoundsErrorforout-of-bounds coordinates but still leaves the agent inside the model
container, resulting in an invalid model state.
Fix
Wrap the call to
add_agent_own_pos!in atry/catchblock and removethe partially added agent from the container if space insertion fails,
then rethrow the error.
Result
Notes
One unrelated visualization test error remains due to upstream Makie
changes and is not caused by this fix.