Skip to content

Move virus_on_a_network to discrete_space#2688

Merged
quaquel merged 3 commits intomesa:mainfrom
quaquel:virus
Feb 15, 2025
Merged

Move virus_on_a_network to discrete_space#2688
quaquel merged 3 commits intomesa:mainfrom
quaquel:virus

Conversation

@quaquel
Copy link
Copy Markdown
Member

@quaquel quaquel commented Feb 13, 2025

This moves virus_on_a_network to discrete_space and cleans up the code.

@quaquel quaquel added example Changes the examples or adds to them. trigger-benchmarks Special label that triggers the benchmarking CI labels Feb 13, 2025
@quaquel quaquel added trigger-benchmarks Special label that triggers the benchmarking CI and removed trigger-benchmarks Special label that triggers the benchmarking CI labels Feb 13, 2025
@github-actions

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +1.7% [+0.8%, +2.6%] 🔵 +0.9% [+0.7%, +1.0%]
BoltzmannWealth large 🔵 +0.0% [-0.6%, +0.5%] 🔵 +1.7% [+1.1%, +2.2%]
Schelling small 🔵 +0.1% [-0.2%, +0.4%] 🔵 +0.9% [+0.8%, +1.1%]
Schelling large 🔵 -3.8% [-10.6%, -0.4%] 🔵 +1.4% [+0.5%, +2.4%]
WolfSheep small 🔵 +1.3% [+0.8%, +1.7%] 🔵 +1.2% [+1.0%, +1.3%]
WolfSheep large 🔵 +1.0% [+0.0%, +2.1%] 🔵 +5.1% [+2.4%, +8.3%]
BoidFlockers small 🔵 +0.8% [-0.0%, +1.8%] 🔵 -1.5% [-1.7%, -1.3%]
BoidFlockers large 🔵 +0.2% [-0.3%, +0.6%] 🔵 -1.3% [-1.5%, -1.1%]

@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

Copy link
Copy Markdown
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one potential improvement comment and one potential follow-up.

Comment on lines +71 to +74
infected_nodes = CellCollection(
self.random.sample(list(self.grid.all_cells), self.initial_outbreak_size),
random=self.random,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocking, but might be interesting if we can make this API-wise a bit cleaner.

Copy link
Copy Markdown
Member Author

@quaquel quaquel Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you are suggesting. I could rewrite the example to not use a CellCollection, but this kept the code closer to the original code and illustrates how users can create their own CellCollection.

infected_nodes = self.random.sample(list(self.grid.all_cells), self.initial_outbreak_size)
for node in infected_nodes:
    for agent in node.agents
        a.state = State.INFECTED

Comment on lines +36 to +39
for agent in self.cell.neighborhood.agents:
if (agent.state is State.SUSCEPTIBLE) and (
self.random.random() < self.virus_spread_chance
):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use agents.select() for this?

Copy link
Copy Markdown
Member Author

@quaquel quaquel Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. cell.neighborhood.agents is a list, not an AgentSet. I have tested changing this in discrete_space to agentset and it results in massive performance loss.

@quaquel quaquel merged commit 8f62b5d into mesa:main Feb 15, 2025
10 checks passed
@quaquel quaquel deleted the virus branch February 15, 2025 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

example Changes the examples or adds to them. trigger-benchmarks Special label that triggers the benchmarking CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants