Title: Implement a minimal swimmer agent-based model under swimmer_abm.model
Description:
Build a small agent-based model consisting of two simple classes, Swimmer and Model, inside a Python package named swimmer_abm. The implementation should be self-contained (standard library only) and should support deepcopy out of the box via simple, picklable attributes.
What to implement
Swimmer class
Attributes:
pos: float, initial position (default 0.0)
velocity: float, movement speed (default 1.0)
Methods:
swim(dt: float) -> None: updates pos by velocity * dt
Model class
Initialization:
init(nswimmers: int) creates a list self.swimmers containing nswimmers Swimmer objects with default pos=0.0 and velocity=1.0
Methods:
step(dt: float) -> None: updates all swimmers by calling swimmer.swim(dt)
Representation:
str() -> str: returns a human-readable string; the exact content is not important as long as it returns a string
Project layout
Create a Python package swimmer_abm with a module swimmer_abm/model.py containing the above classes.
Include an empty init.py in swimmer_abm to make it a package.
Requirements that ensure tests pass
Model(nswimmers=3) creates exactly 3 swimmers accessible via model.swimmers
After calling model.step(dt) with dt=1, each swimmer’s position advances by velocity * dt (with velocity=1.0 by default)
The test that deep-copies a swimmer, calls swimmer.swim(dt) on the copy, then runs model.step(dt) and compares the copied swimmer’s pos to model.swimmers[0].pos should succeed (i.e., both equal velocity * dt, assuming initial pos is 0)
str(model) returns a string (i.e., isinstance(str(model), str) is True)
Notes
The implementation should be self-contained, with no external dependencies beyond the standard library.
Deepcopy should work out of the box for Swimmer by using simple, picklable attributes.
How to run tests (suggested)
Run the test suite (e.g., pytest) in the repository root after implementing the package:
pip install -e .
pytest -q
Alternatively, run your preferred test runner that validates the acceptance criteria above.