Conversation
|
Performance benchmarks:
|
|
It can also contain |
107eaf6 to
14abde7
Compare
|
@Sahil-Chhoker Added it as you suggested. |
|
@DipayanDasgupta I'm seeing indentation problems in your code, fix that please. |
|
A small suggestion i had is since we’re now handling multiple deprecated kwargs ( deprecated = {
"space_kwargs": self.draw_space_kwargs,
"agent_kwargs": self.draw_agent_kwargs,
}
for key, target in deprecated.items():
if key in kwargs:
val = kwargs.pop(key)
if isinstance(val, dict):
target.update(val)This keeps the logic simple and avoids adding more conditional blocks as new legacy kwargs come up. |
14abde7 to
69cc2f9
Compare
|
@Sahil-Chhoker @souro26 Thank you both for the constructive feedback! I've updated the PR to address all the points raised:
The implementation is now much cleaner and fully robust against legacy kwargs. Please let me know if there are any other improvements needed before merging! |
Sahil-Chhoker
left a comment
There was a problem hiding this comment.
Thanks @DipayanDasgupta for the PR and @souro26 for helping in the logic, just a couple comments after that this PR is good to go from my side.
mesa/visualization/space_renderer.py
Outdated
| """Render the complete space with structure, agents, and property layers. | ||
|
|
||
| Args: | ||
| self: The SpaceRenderer instance. |
There was a problem hiding this comment.
Remove this comment, self is automatically passed.
1358976 to
672e4ad
Compare
672e4ad to
618db48
Compare
|
@quaquel @Sahil-Chhoker I've made the recommended changes , if there's anything else to be done before its good to merge, please do let me know. |
Summary
This PR adds a safeguard to
SpaceRenderer.renderto prevent a hardAttributeErrorcrash when the deprecatedspace_kwargsargument is passed.Bug / Issue
Closes #3216
Context:
Currently, if a user (or a legacy script/tutorial) passes
space_kwargstorenderer.render(), the method blindly merges it intokwargsand passes it to the backend drawer.What happened: Matplotlib raises
AttributeError: Line2D.set() got an unexpected keyword argument 'space_kwargs'because the dictionary key wasn't unpacked.What was expected: The renderer should handle the deprecated argument gracefully (by unpacking its contents) or at least not crash the entire application.
Implementation
Modified
mesa/visualization/space_renderer.pyinside therendermethod:space_kwargsexists inkwargs.self.draw_space_kwargs(which is the correct destination for these parameters).space_kwargsfromkwargsto prevent it from being passed downstream to the backend (Matplotlib/Altair) where it causes the crash.Testing
I created a local reproduction script to verify the fix:
Reproduction Code:
Results:
AttributeError: Line2D.set() got an unexpected keyword argument 'space_kwargs'.Additional Notes
While PR #3223 and #3231 updated the tutorials to use the new API, the underlying library code remained fragile. This fix ensures that users who copy-paste old code or haven't updated their scripts yet will encounter a warning rather than a hard crash, improving the DevEx.