Skip to content
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

Update docstring of SimEvent #2417

Merged
merged 4 commits into from
Oct 25, 2024
Merged

Update docstring of SimEvent #2417

merged 4 commits into from
Oct 25, 2024

Conversation

quaquel
Copy link
Member

@quaquel quaquel commented Oct 25, 2024

In response to this feedback on the beta, this PR adds a notes to SimEvent to explicitly point out that using lambda's in SimEvent won't work.

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +2.9% [+1.4%, +4.5%] 🔵 -0.6% [-0.8%, -0.5%]
BoltzmannWealth large 🔵 -1.0% [-1.3%, -0.8%] 🔵 -0.9% [-1.3%, -0.6%]
Schelling small 🔵 -0.3% [-0.7%, +0.0%] 🔵 -0.6% [-0.7%, -0.5%]
Schelling large 🔵 +0.1% [-0.8%, +1.0%] 🔵 -2.0% [-3.9%, -0.3%]
WolfSheep small 🔵 -1.9% [-2.1%, -1.7%] 🔵 -1.8% [-2.0%, -1.5%]
WolfSheep large 🔵 -2.8% [-4.4%, -1.7%] 🟢 -6.0% [-8.3%, -3.8%]
BoidFlockers small 🟢 -3.9% [-4.3%, -3.5%] 🔵 -1.0% [-1.7%, -0.3%]
BoidFlockers large 🔵 -3.2% [-3.8%, -2.5%] 🔵 -0.5% [-0.9%, -0.1%]

@EwoutH
Copy link
Member

EwoutH commented Oct 25, 2024

Thanks! @jtcooper10, would this solve your point raised?

@quaquel quaquel merged commit 3225dbb into projectmesa:main Oct 25, 2024
10 of 12 checks passed
@Corvince
Copy link
Contributor

Just out of curiosity, why does it use a weak reference at all?

@jtcooper10
Copy link

Thanks! @jtcooper10, would this solve your point raised?

I think so! The note being here will help to save from any future head-scratching about lambdas.

@quaquel
Copy link
Member Author

quaquel commented Oct 25, 2024

Just out of curiosity, why does it use a weak reference at all?

Imagine an event is scheduled to invoke some_agent.method, but this agent is, for some other reason, removed from the simulation. If we don't use a weakref, the agent cannot be garbage collected. There is a SimEvent.cancel method that could be used if some_agent.method was scheduled by some_agent itself. Basically, you could track all events some_agent has scheduled and cancel all of those. However, some_agent.method can also be scheduled by other objects. How are they to be informed of the fact that some_agent is being removed from the simulation and that therefore the events has to be canceled? All these problems are avoided by using a weakref in SimEvent.

@Corvince
Copy link
Contributor

Ah, yes of course! Thanks for detailing it out, made it very clear

@EwoutH EwoutH added the docs Release notes label label Oct 26, 2024
@quaquel quaquel deleted the docs branch November 4, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants