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

tests: Resolve warnings by removing scheduler and updating arguments #2329

Merged
merged 6 commits into from
Sep 26, 2024

Conversation

EwoutH
Copy link
Member

@EwoutH EwoutH commented Sep 26, 2024

This PR updates several test files to resolve warnings and deprecations introduced in Mesa 3.0. The changes align the tests with the new AgentSet functionality and the removal of schedulers.

Changes

1. Remove scheduler from batch_run tests

The schedule parameter and related code were removed from the MockModel in test_batch_run.py. This aligns with the deprecation of schedulers in favor of AgentSet functionality.

Example:

# Old
self.schedule = BaseScheduler(self) if schedule is None else schedule
self.schedule.add(MockAgent(self, agent_val))

# New
MockAgent(self, agent_val)

Related PR: #1926

2. Remove scheduler from datacollector tests

The schedule attribute and related methods were removed from the MockModel in test_datacollector.py. The step method now uses self.agents.do("step") instead of self.schedule.step().

Example:

# Old
self.schedule = BaseScheduler(self)
self.schedule.step()

# New
self.agents.do("step")

Related PR: #1926

3. Replace n with at_most in AgentSet select

In test_agent.py, the deprecated n parameter in AgentSet.select() was replaced with at_most.

Example:

# Old
agentset.select(test_function, n=2)

# New
agentset.select(test_function, at_most=2)

Related PR: #2253

4. Replace scheduler in lifespan tests

In test_lifespan.py, the RandomActivation scheduler was removed, and the step method now uses self.agents.shuffle_do("step"). The order of stepping and data collection was also adjusted to align with the new structure.

Example:

# Old
self.schedule = RandomActivation(self)
self.schedule.step()
self.datacollector.collect(self)

# New
self.agents.shuffle_do("step")
self.datacollector.collect(self)

Related PR: #1926

5. Rename Agent classes to not start with Test

Agent classes in test files were renamed to avoid starting with "Test" to prevent confusion with test methods.

Example:

# Old
class TestAgent(Agent):

# New
class AgentTest(Agent):

This change improves clarity and adheres to common naming conventions for test classes.

Summary

These updates resolve warnings and deprecations introduced in Mesa 3.0, particularly related to the removal of schedulers and the new AgentSet functionality. The changes ensure that our tests are up-to-date with the latest Mesa API and best practices.

@EwoutH EwoutH added the testing Release notes label label Sep 26, 2024
Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.0% [-2.0%, -0.1%] 🔵 +0.2% [-0.1%, +0.6%]
BoltzmannWealth large 🔵 -0.7% [-1.4%, -0.0%] 🔵 -1.1% [-1.8%, -0.4%]
Schelling small 🔵 -1.2% [-1.7%, -0.6%] 🔵 -0.8% [-1.3%, -0.3%]
Schelling large 🔵 -1.0% [-2.1%, -0.1%] 🔵 -1.4% [-2.1%, -0.7%]
WolfSheep small 🔵 +0.0% [-0.4%, +0.5%] 🔵 +0.6% [+0.4%, +0.8%]
WolfSheep large 🔵 +2.3% [+0.3%, +4.4%] 🔵 +5.2% [+2.1%, +8.4%]
BoidFlockers small 🔵 +1.4% [+0.8%, +2.1%] 🔵 +1.3% [+0.6%, +1.9%]
BoidFlockers large 🔵 +2.3% [+1.2%, +3.8%] 🔵 +0.8% [+0.4%, +1.2%]

Also adhere to the new structure of stepping first and then collecting
resolves:

tests/test_agent.py:12
  /home/runner/work/mesa/mesa/tests/test_agent.py:12: PytestCollectionWarning: cannot collect test class 'TestAgent' because it has a __init__ constructor (from: tests/test_agent.py)
    class TestAgent(Agent):
tests/test_agent.py:20
  /home/runner/work/mesa/mesa/tests/test_agent.py:20: PytestCollectionWarning: cannot collect test class 'TestAgentDo' because it has a __init__ constructor (from: tests/test_agent.py)
    class TestAgentDo(Agent):
@EwoutH
Copy link
Member Author

EwoutH commented Sep 26, 2024

Done, this PR resolves almost all open warnings in the tests.

@EwoutH EwoutH merged commit 17cd62a into projectmesa:main Sep 26, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants