Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
e1cd30a
Add abstract name property and rename method to AgentSetDF for enhanc…
adamamer20 Aug 29, 2025
b385314
Refactor agent retrieval in ModelDF to use dictionary access for impr…
adamamer20 Aug 29, 2025
69b56c1
Enhance AgentSetPolars with unique naming and renaming capabilities
adamamer20 Aug 29, 2025
f04cfcf
Add abstract base class for agent sets accessors with comprehensive API
adamamer20 Aug 29, 2025
af0f270
Implement AgentSetsAccessor class for enhanced agent set management a…
adamamer20 Aug 29, 2025
4c60083
Add KeyBy literal for common option types in type definitions
adamamer20 Aug 29, 2025
637f560
Refactor AgentSetsAccessor to use direct access to agent sets for imp…
adamamer20 Aug 29, 2025
f823400
Fix type hint in constructor and improve default handling in get meth…
adamamer20 Aug 30, 2025
f190d86
Remove redundant test for agent sets by type in Test_AgentsDF
adamamer20 Aug 30, 2025
85effbc
Add rename method to AgentSetsAccessor for agent set renaming with co…
adamamer20 Aug 30, 2025
53cd1d2
Refactor name handling in AgentSetPolars to simplify uniqueness manag…
adamamer20 Aug 30, 2025
3cf2c06
Implement unique name generation and canonicalization for agent sets …
adamamer20 Aug 30, 2025
a6e92ab
Enhance type handling in AgentSetsAccessor to provide detailed error …
adamamer20 Aug 30, 2025
4aaaf47
Enhance error handling in AgentsDF by providing available agent set n…
adamamer20 Aug 30, 2025
d649301
Add mesa package to development dependencies in uv.lock
adamamer20 Aug 30, 2025
951d5b6
Refactor __getitem__ method in AgentSetsAccessor to return matching a…
adamamer20 Aug 30, 2025
c5c8430
Add comprehensive tests for AgentSetsAccessor methods to ensure corre…
adamamer20 Aug 30, 2025
624c7a4
Merge branch 'main' of https://github.com/projectmesa/mesa-frames int…
adamamer20 Aug 30, 2025
d0a592a
Rename AgentSetsAccessorBase to AbstractAgentSetsAccessor for consist…
adamamer20 Aug 30, 2025
cf16fb6
Refactor AgentSetsAccessor to extend AbstractAgentSetsAccessor for im…
adamamer20 Aug 30, 2025
95bb9af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 30, 2025
823732b
Refactor error handling in __getitem__ to use a set for available age…
adamamer20 Aug 30, 2025
ebbbf6b
Enhance code readability and organization by adding whitespace for cl…
adamamer20 Aug 30, 2025
f1ac41d
Merge branch '146-enhancement-consider-using-a-key-based-structure-fo…
adamamer20 Aug 30, 2025
7f5844a
Enhance docstring clarity and type annotations in AbstractAgentSetsAc…
adamamer20 Aug 30, 2025
930cd77
Enhance docstring clarity and type annotations in AgentSetsAccessor; …
adamamer20 Aug 30, 2025
bf5786a
Refactor docstring in AgentsDF.rename to clarify purpose and improve …
adamamer20 Aug 30, 2025
66b7054
Enhance docstring clarity and type annotations in AbstractAgentSetsAc…
adamamer20 Aug 30, 2025
cf56a7d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 30, 2025
7c2afac
Enhance type annotations and overloads in AbstractAgentSetsAccessor; …
adamamer20 Aug 30, 2025
686dfa5
Refactor type annotations in AbstractAgentSetsAccessor; replace Agent…
adamamer20 Aug 30, 2025
92ff76e
Refactor AgentSetsAccessor methods; replace mapping method with dict …
adamamer20 Aug 30, 2025
af24eb2
Merge branch '146-enhancement-consider-using-a-key-based-structure-fo…
adamamer20 Aug 30, 2025
bba59cc
Add rename method to AbstractAgentSetsAccessor for agent set renaming…
adamamer20 Aug 30, 2025
c54f9d9
Refactor rename method in AgentSetsAccessor; streamline docstring and…
adamamer20 Aug 30, 2025
c83e9e5
Refactor rename method in AbstractAgentSetsAccessor; improve type ann…
adamamer20 Aug 30, 2025
0f640fb
Refactor _rename_set method in AgentsDF; enhance functionality for si…
adamamer20 Aug 30, 2025
cab89a2
Refactor AbstractAgentSetsAccessor and AgentSetsAccessor; remove 'obj…
adamamer20 Aug 30, 2025
a652892
Add tests for AgentsDF's contains and remove methods; handle empty it…
adamamer20 Aug 30, 2025
6ed2419
Enhance tests for AgentSetsAccessor; add validation for key retrieval…
adamamer20 Aug 30, 2025
f53b464
Refactor keys method in AbstractAgentSetsAccessor for consistency; im…
adamamer20 Aug 30, 2025
d866171
Update return type of keys method in AbstractAgentSetsAccessor to exc…
adamamer20 Aug 30, 2025
006c1ab
Enhance _make_unique_name method in AgentsDF with detailed docstring;…
adamamer20 Aug 30, 2025
f7ef412
Implement camel_case_to_snake_case function for converting camelCase …
adamamer20 Aug 30, 2025
c209c1b
Refactor AgentSetPolars to convert proposed name to snake_case if in …
adamamer20 Aug 30, 2025
e603996
Refactor camel_case_to_snake_case function for consistency in regex s…
adamamer20 Aug 30, 2025
d38351e
Refactor _camel_to_snake function for consistent regex string delimit…
adamamer20 Aug 30, 2025
8f9fa54
Enhance AgentContainer type hints to support string and collection of…
adamamer20 Aug 30, 2025
f80083c
Refactor AgentSetPolars to improve readability of name assignment; fo…
adamamer20 Aug 30, 2025
231e3bd
Refactor tests to use updated Model and AgentSet classes
adamamer20 Aug 31, 2025
8d7fe14
Refactor agent set imports and introduce AgentSetRegistry
adamamer20 Aug 31, 2025
a814dd8
Refactor import statements for better readability in space.py and age…
adamamer20 Aug 31, 2025
5dbe6f5
Fix formatting in AGENTS.md for MESA_FRAMES_RUNTIME_TYPECHECKING vari…
adamamer20 Aug 31, 2025
79e94e5
Update type hints in AbstractAgentSetRegistry to reference abstract a…
adamamer20 Aug 31, 2025
09cb336
Introduce AbstractAgentSet class and refactor imports for consistency
adamamer20 Aug 31, 2025
ab80df0
Update type hints in AbstractAgentSetRegistry to reference concrete A…
adamamer20 Aug 31, 2025
7878392
Refactor import statements in agentset.py for improved readability
adamamer20 Sep 1, 2025
47a5413
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2025
dfa2287
Update docstring in AbstractAgentSet and improve type hints in Abstra…
adamamer20 Sep 1, 2025
ad53071
Merge branch '171-enhancement-rename-agentsetdf-to-abstractagentsetdf…
adamamer20 Sep 1, 2025
c672924
Remove AbstractAgentSetsAccessor class and its associated methods fro…
adamamer20 Sep 1, 2025
5f2f0b3
Remove TestAgentSetsAccessor class and its associated tests from test…
adamamer20 Sep 1, 2025
4dff1d8
Rename test class from Test_ModelDF to Test_Model for consistency
adamamer20 Sep 1, 2025
927014c
Add abstract agent set classes and concrete agent set registry implem…
adamamer20 Sep 1, 2025
1396bc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2025
324a6c7
Merge branch '171-enhancement-rename-agentsetdf-to-abstractagentsetdf…
adamamer20 Sep 1, 2025
fccf344
Refactor GridPolars to Grid and update related references across the …
adamamer20 Sep 1, 2025
886c5f7
Merge branch '171-enhancement-rename-agentsetdf-to-abstractagentsetdf…
adamamer20 Sep 1, 2025
c8d77e2
Remove concrete implementation of AgentSetsAccessor for codebase cleanup
adamamer20 Sep 1, 2025
eaec185
Remove camel_case_to_snake_case function for codebase cleanup
adamamer20 Sep 1, 2025
6b1f3ad
Rename SpaceDF to Space and update related references for consistency
adamamer20 Sep 1, 2025
f46fbb9
Rename MoneyAgentDFConcise to MoneyAgentConcise and MoneyAgentDFNativ…
adamamer20 Sep 3, 2025
3cdd5c1
Update rename method documentation to reflect delegation to AgentSetR…
adamamer20 Sep 3, 2025
5f217b0
Remove unused properties from AgentSetRegistry for codebase cleanup
adamamer20 Sep 3, 2025
ca54b40
Update space type annotations to reflect Space object instead of Mult…
adamamer20 Sep 3, 2025
cc1f133
Fix get_unique_ids function to correctly cast unique_id series from m…
adamamer20 Sep 3, 2025
9cb79c2
Refactor space property type annotation to use Space instead of Space…
adamamer20 Sep 3, 2025
89454e2
Update copyright year in conf.py to use current year dynamically
adamamer20 Sep 3, 2025
36f132a
Rename MoneyAgentDF and MoneyModelDF classes to MoneyAgents and Money…
adamamer20 Sep 3, 2025
0771ef3
Add tests for CustomModel and its step functionality
adamamer20 Sep 3, 2025
a234bc8
Update space property type hint to use Space instead of SpaceDF for c…
adamamer20 Sep 3, 2025
95e2196
Simplify name assignment in AgentSet constructor for improved readabi…
adamamer20 Sep 3, 2025
028c91f
Format list comprehensions for improved readability in AgentSetRegist…
adamamer20 Sep 3, 2025
e4737d9
Rename parameter in ExampleModel constructor from 'agents' to 'sets' …
adamamer20 Sep 3, 2025
ec1a357
Reorder DataCollector import to avoid circular import error
adamamer20 Sep 3, 2025
26312a8
Merge branch '171-enhancement-rename-agentsetdf-to-abstractagentsetdf…
adamamer20 Sep 3, 2025
a3e2c56
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 3, 2025
040e00c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 3, 2025
9afda44
Remove unused import of camel_case_to_snake_case in agentset.py
adamamer20 Sep 3, 2025
d06139a
Merge branch '146-enhancement-consider-using-a-key-based-structure-fo…
adamamer20 Sep 3, 2025
5750a4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 3, 2025
9a0ecc8
Merge branch 'main' into 171-enhancement-rename-agentsetdf-to-abstrac…
adamamer20 Sep 3, 2025
ae1390b
Add conftest.py to enable beartype runtime checking for tests
adamamer20 Sep 4, 2025
fd6f13b
Fix import order by adding a newline for clarity in __init__.py
adamamer20 Sep 4, 2025
ed8dc61
Enhance type hinting for agent parameters in Space and AbstractDiscre…
adamamer20 Sep 4, 2025
d9dc746
Refactor agent type checks to use AbstractAgentSetRegistry for improv…
adamamer20 Sep 4, 2025
b72e34b
Refactor AgentSet constructor and name property for improved clarity …
adamamer20 Sep 4, 2025
84f186f
precommit
Ben-geo Sep 5, 2025
d50b00f
Replace MoneyAgentDF with MoneyAgents in MoneyModel constructor for c…
adamamer20 Sep 10, 2025
98f4859
Rename MoneyAgentDF to MoneyAgents for consistency in agent set imple…
adamamer20 Sep 10, 2025
d3402ee
Update tutorial to reflect renaming of agent classes from MoneyAgentP…
adamamer20 Sep 10, 2025
2d4854f
Refactor MoneyModel and MoneyAgents classes for consistency and clari…
adamamer20 Sep 10, 2025
dcee916
Update DataCollector tutorial with execution results and fix agent we…
adamamer20 Sep 10, 2025
0828832
Refactor agent and model classes for consistency: rename MoneyModel t…
adamamer20 Sep 10, 2025
2cd4e00
Fix agent type reference in SugarscapePolars model: update from AntPo…
adamamer20 Sep 10, 2025
73fa761
Fix model_reporters lambda function in ExampleModel to correctly sum …
adamamer20 Sep 10, 2025
4e02ffc
Refactor agent and model classes for consistency: update references f…
adamamer20 Sep 10, 2025
3637a35
Fix missing newline at end of file in ExampleModel documentation
adamamer20 Sep 10, 2025
2826c5c
Remove unused import of Model in agentset.py
adamamer20 Sep 10, 2025
deeea1b
Merge branch '146-enhancement-consider-using-a-key-based-structure-fo…
adamamer20 Sep 10, 2025
2579e8b
Merge branch '171-enhancement-rename-agentsetdf-to-abstractagentsetdf…
adamamer20 Sep 10, 2025
475c4cb
Fix class name in documentation: update Space to AbstractSpace for cl…
adamamer20 Sep 10, 2025
ff15a0b
Merge branch '171-enhancement-rename-agentsetdf-to-abstractagentsetdf…
adamamer20 Sep 10, 2025
4ef6dfc
Refactor AbstractAgentSet class: remove inheritance from AbstractAgen…
adamamer20 Sep 10, 2025
50548de
Add method overloads for do and implement remove method in AgentSet c…
adamamer20 Sep 10, 2025
e08c928
Refactor AbstractAgentSet class: add remove method and improve agent …
adamamer20 Sep 10, 2025
809570d
Refactor AbstractAgentSetRegistry: update discard, add, and contains …
adamamer20 Sep 12, 2025
9ced330
Refactor type aliases in types_.py: reorganize imports, enhance Agent…
adamamer20 Sep 12, 2025
5b79c35
Refactor import statement in agentsetregistry.py: rename AbstractAgen…
adamamer20 Sep 12, 2025
6baec28
Refactor AgentSetRegistry: streamline imports, rename parameters for …
adamamer20 Sep 12, 2025
7f78887
Refactor AbstractAgentSetRegistry: add abstract methods keys, items, …
adamamer20 Sep 12, 2025
37d8922
Refactor AgentSetRegistry: add keys, items, and values methods for en…
adamamer20 Sep 12, 2025
33aa536
Refactor contains method in AgentSetRegistry: optimize type checks an…
adamamer20 Sep 12, 2025
e641f12
Refactor AgentSetRegistry: streamline method for resolving agent sets…
adamamer20 Sep 12, 2025
f847a57
Refactor AgentSetRegistry: simplify key retrieval logic and enhance e…
adamamer20 Sep 12, 2025
7588966
Refactor AgentSetRegistry: implement _resolve_selector method for imp…
adamamer20 Sep 12, 2025
6b7be9d
Refactor AgentSetRegistry: optimize agent removal logic and normalize…
adamamer20 Sep 12, 2025
e45efbe
Refactor AgentSetRegistry: add replace method for bulk updating of ag…
adamamer20 Sep 12, 2025
267e64b
Refactor AgentSetRegistry: simplify index key generation logic using …
adamamer20 Sep 12, 2025
963f949
Refactor AbstractAgentSetRegistry: update parameter names and types f…
adamamer20 Sep 12, 2025
073b6db
Refactor AgentSet: update model parameter type for improved clarity
adamamer20 Sep 12, 2025
a8b615e
Refactor get_unique_ids: update implementation for clarity and correc…
adamamer20 Sep 12, 2025
26eaefc
Refactor AgentSet: enhance agent removal logic with validation for un…
adamamer20 Sep 14, 2025
8afca27
Refactor AgentSetRegistry: improve agent set name assignment logic fo…
adamamer20 Sep 14, 2025
a43da1a
Refactor Model: update step method to use public registry API for inv…
adamamer20 Sep 14, 2025
ccbd8a0
Refactor Space: improve agent ID validation and handling using public…
adamamer20 Sep 14, 2025
4b832e1
Add comprehensive tests for AgentSetRegistry functionality
adamamer20 Sep 14, 2025
393a5db
Enhance agent reporter functionality: support string collections and …
adamamer20 Sep 14, 2025
500bc23
Refactor agent reporter lambda functions to use sets parameter for we…
adamamer20 Sep 14, 2025
6f62e99
Refactor test assertions in TestAgentSetRegistry for improved readabi…
adamamer20 Sep 14, 2025
95cf996
Refactor DataCollector model reporters for improved efficiency and re…
adamamer20 Sep 14, 2025
352f2af
Fix execution counts in DataCollector tutorial notebook for consistency
adamamer20 Sep 14, 2025
4a2018e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 15, 2025
065bea8
Implement rename functionality for AgentSet and AgentSetRegistry with…
adamamer20 Sep 15, 2025
03575eb
Refactor test assertion in TestAgentSetRegistry to use set literal fo…
adamamer20 Sep 15, 2025
5e6dd9a
Enhance parameter documentation for agent handling and rename functio…
adamamer20 Sep 15, 2025
1c3a63b
Merge branch '146-enhancement-consider-using-a-key-based-structure-fo…
adamamer20 Sep 15, 2025
647f5b6
Update documentation to clarify usage of AgentSetRegistry and improve…
adamamer20 Sep 15, 2025
cb139b1
fix ss_polars
adamamer20 Sep 15, 2025
5c68bd8
formatting
adamamer20 Sep 15, 2025
2c43b3f
Merge branch 'main' of https://github.com/projectmesa/mesa-frames int…
adamamer20 Sep 19, 2025
7c53eb8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2025
cdcdfc8
fix: remove conflict markers by preferring OURS from 2c43b3f5e9283be5…
adamamer20 Sep 19, 2025
d7d5ca8
remove old test_agents.py
adamamer20 Sep 19, 2025
5f89f07
feat: add abstract rename method to AbstractAgentSet for consistent n…
adamamer20 Sep 19, 2025
acf9c50
feat: add abstract set method to AbstractAgentSet for updating agent …
adamamer20 Sep 19, 2025
2935894
Remove obsolete OLD_concrete_accessors.py and OLD_concrete_agents.py …
adamamer20 Sep 19, 2025
0e1044c
refactor: streamline key management methods in AgentSetRegistry and e…
adamamer20 Sep 19, 2025
4187380
feat: enhance key handling in AbstractAgentSetRegistry for string keys
adamamer20 Sep 19, 2025
4ef1a25
refactor: remove unused _skip_copy attribute from CopyMixin
adamamer20 Sep 19, 2025
073bb90
refactor: improve key handling and update logic in AgentSetRegistry
adamamer20 Sep 19, 2025
dccc834
fix: specify exception type in DataCollector to improve error handling
adamamer20 Sep 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions docs/general/user-guide/1_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ You can access the underlying DataFrame where agents are stored with `self.df`.

## Model 🏗️

To add your AgentSet to your Model, you should also add it to the sets with `+=` or `add`.
To add your AgentSet to your Model, use the registry `self.sets` with `+=` or `add`.

NOTE: Model.sets are stored in a class which is entirely similar to AgentSet called AgentSetRegistry. The API of the two are the same. If you try accessing AgentSetRegistry.df, you will get a dictionary of `[AgentSet, DataFrame]`.
Note: All agent sets live inside `AgentSetRegistry` (available as `model.sets`). Access sets through the registry, and access DataFrames from the set itself. For example: `self.sets["Preys"].df`.

Example:

Expand All @@ -43,7 +43,8 @@ class EcosystemModel(Model):
def step(self):
self.sets.do("move")
self.sets.do("hunt")
self.prey.do("reproduce")
# Access specific sets via the registry
self.sets["Preys"].do("reproduce")
```

## Space: Grid 🌐
Expand Down Expand Up @@ -76,18 +77,23 @@ Example:
class ExampleModel(Model):
def __init__(self):
super().__init__()
self.sets = MoneyAgent(self)
# Add the set to the registry
self.sets.add(MoneyAgents(100, self))
# Configure reporters: use the registry to locate sets; get df from the set
self.datacollector = DataCollector(
model=self,
model_reporters={"total_wealth": lambda m: lambda m: list(m.sets.df.values())[0]["wealth"].sum()},
model_reporters={
"total_wealth": lambda m: m.sets["MoneyAgents"].df["wealth"].sum(),
},
agent_reporters={"wealth": "wealth"},
storage="csv",
storage_uri="./data",
trigger=lambda m: m.schedule.steps % 2 == 0
trigger=lambda m: m.steps % 2 == 0,
)

def step(self):
self.sets.step()
# Step all sets via the registry
self.sets.do("step")
self.datacollector.conditional_collect()
self.datacollector.flush()
```
4 changes: 3 additions & 1 deletion docs/general/user-guide/2_introductory-tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
" self.sets += agents_cls(N, self)\n",
" self.datacollector = DataCollector(\n",
" model=self,\n",
" model_reporters={\"total_wealth\": lambda m: m.agents[\"wealth\"].sum()},\n",
" model_reporters={\n",
" \"total_wealth\": lambda m: m.sets[\"MoneyAgents\"].df[\"wealth\"].sum()\n",
" },\n",
" agent_reporters={\"wealth\": \"wealth\"},\n",
" storage=\"csv\",\n",
" storage_uri=\"./data\",\n",
Expand Down
82 changes: 41 additions & 41 deletions docs/general/user-guide/4_datacollector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 6,
"id": "9a63283cbaf04dbcab1f6479b197f3a8",
"metadata": {
"editable": true
Expand All @@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "72eea5119410473aa328ad9291626812",
"metadata": {
"editable": true
Expand All @@ -63,33 +63,33 @@
" │ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
" │ i64 ┆ str ┆ i64 ┆ f64 ┆ i64 │\n",
" ╞══════╪═════════════════════════════════╪═══════╪══════════════╪══════════╡\n",
" │ 2 ┆ 162681765859364298619846106603… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 4 ┆ 162681765859364298619846106603… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 6 ┆ 162681765859364298619846106603… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 8 ┆ 162681765859364298619846106603… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 10 ┆ 162681765859364298619846106603… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 2 ┆ 332212815818606584686857770936… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 4 ┆ 332212815818606584686857770936… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 6 ┆ 332212815818606584686857770936… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 8 ┆ 332212815818606584686857770936… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" │ 10 ┆ 332212815818606584686857770936… ┆ 0 ┆ 1000.0 ┆ 1000 │\n",
" └──────┴─────────────────────────────────┴───────┴──────────────┴──────────┘,\n",
" 'agent': shape: (5_000, 4)\n",
" ┌────────────────────┬──────┬─────────────────────────────────┬───────┐\n",
" │ wealth_MoneyAgents ┆ step ┆ seed ┆ batch │\n",
" │ --- ┆ --- ┆ --- ┆ --- │\n",
" │ f64 ┆ i32 ┆ str ┆ i32 │\n",
" ╞════════════════════╪══════╪═════════════════════════════════╪═══════╡\n",
" │ 0.0 ┆ 2 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 3.0 ┆ 2 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 1.0 ┆ 2 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 3.0 ┆ 2 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 6.0 ┆ 2 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 3.0 ┆ 2 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 0.0 ┆ 2 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 2.0 ┆ 2 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 1.0 ┆ 2 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 0.0 ┆ 2 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ … ┆ … ┆ … ┆ … │\n",
" │ 4.0 ┆ 10 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 1.0 ┆ 10 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 162681765859364298619846106603… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" │ 0.0 ┆ 10 ┆ 332212815818606584686857770936… ┆ 0 │\n",
" └────────────────────┴──────┴─────────────────────────────────┴───────┘}"
]
},
"execution_count": 19,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -120,8 +120,8 @@
" self.dc = DataCollector(\n",
" model=self,\n",
" model_reporters={\n",
" \"total_wealth\": lambda m: list(m.sets.df.values())[0][\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(list(m.sets.df.values())[0]),\n",
" \"total_wealth\": lambda m: m.sets[\"MoneyAgents\"].df[\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(m.sets[\"MoneyAgents\"]),\n",
" },\n",
" agent_reporters={\n",
" \"wealth\": \"wealth\", # pull existing column\n",
Expand Down Expand Up @@ -175,7 +175,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"id": "5f14f38c",
"metadata": {},
"outputs": [
Expand All @@ -185,7 +185,7 @@
"[]"
]
},
"execution_count": 20,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -198,8 +198,8 @@
"model_csv.dc = DataCollector(\n",
" model=model_csv,\n",
" model_reporters={\n",
" \"total_wealth\": lambda m: list(m.sets.df.values())[0][\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(list(m.sets.df.values())[0]),\n",
" \"total_wealth\": lambda m: m.sets[\"MoneyAgents\"].df[\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(m.sets[\"MoneyAgents\"]),\n",
" },\n",
" agent_reporters={\n",
" \"wealth\": \"wealth\",\n",
Expand All @@ -226,7 +226,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"id": "8763a12b2bbd4a93a75aff182afb95dc",
"metadata": {
"editable": true
Expand All @@ -238,7 +238,7 @@
"[]"
]
},
"execution_count": 21,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -249,8 +249,8 @@
"model_parq.dc = DataCollector(\n",
" model=model_parq,\n",
" model_reporters={\n",
" \"total_wealth\": lambda m: list(m.sets.df.values())[0][\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(list(m.sets.df.values())[0]),\n",
" \"total_wealth\": lambda m: m.sets[\"MoneyAgents\"].df[\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(m.sets[\"MoneyAgents\"]),\n",
" },\n",
" agent_reporters={\n",
" \"wealth\": \"wealth\",\n",
Expand Down Expand Up @@ -279,7 +279,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"id": "7cdc8c89c7104fffa095e18ddfef8986",
"metadata": {
"editable": true
Expand All @@ -290,8 +290,8 @@
"model_s3.dc = DataCollector(\n",
" model=model_s3,\n",
" model_reporters={\n",
" \"total_wealth\": lambda m: list(m.sets.df.values())[0][\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(list(m.sets.df.values())[0]),\n",
" \"total_wealth\": lambda m: m.sets[\"MoneyAgents\"].df[\"wealth\"].sum(),\n",
" \"n_agents\": lambda m: len(m.sets[\"MoneyAgents\"]),\n",
" },\n",
" agent_reporters={\n",
" \"wealth\": \"wealth\",\n",
Expand Down Expand Up @@ -319,7 +319,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 11,
"id": "938c804e27f84196a10c8828c723f798",
"metadata": {
"editable": true
Expand Down Expand Up @@ -381,7 +381,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 12,
"id": "59bbdb311c014d738909a11f9e486628",
"metadata": {
"editable": true
Expand Down Expand Up @@ -410,7 +410,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 13,
"id": "8a65eabff63a45729fe45fb5ade58bdc",
"metadata": {
"editable": true
Expand All @@ -426,7 +426,7 @@
" white-space: pre-wrap;\n",
"}\n",
"</style>\n",
"<small>shape: (5, 5)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>step</th><th>seed</th><th>batch</th><th>total_wealth</th><th>n_agents</th></tr><tr><td>i64</td><td>str</td><td>i64</td><td>f64</td><td>i64</td></tr></thead><tbody><tr><td>2</td><td>&quot;732054881101029867447298951813…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>4</td><td>&quot;732054881101029867447298951813…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>6</td><td>&quot;732054881101029867447298951813…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>8</td><td>&quot;732054881101029867447298951813…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>10</td><td>&quot;732054881101029867447298951813…</td><td>0</td><td>100.0</td><td>100</td></tr></tbody></table></div>"
"<small>shape: (5, 5)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>step</th><th>seed</th><th>batch</th><th>total_wealth</th><th>n_agents</th></tr><tr><td>i64</td><td>str</td><td>i64</td><td>f64</td><td>i64</td></tr></thead><tbody><tr><td>2</td><td>&quot;540832786058427425452319829502…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>4</td><td>&quot;540832786058427425452319829502…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>6</td><td>&quot;540832786058427425452319829502…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>8</td><td>&quot;540832786058427425452319829502…</td><td>0</td><td>100.0</td><td>100</td></tr><tr><td>10</td><td>&quot;540832786058427425452319829502…</td><td>0</td><td>100.0</td><td>100</td></tr></tbody></table></div>"
],
"text/plain": [
"shape: (5, 5)\n",
Expand All @@ -435,15 +435,15 @@
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ i64 ┆ str ┆ i64 ┆ f64 ┆ i64 │\n",
"╞══════╪═════════════════════════════════╪═══════╪══════════════╪══════════╡\n",
"│ 2 ┆ 732054881101029867447298951813… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 4 ┆ 732054881101029867447298951813… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 6 ┆ 732054881101029867447298951813… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 8 ┆ 732054881101029867447298951813… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 10 ┆ 732054881101029867447298951813… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 2 ┆ 540832786058427425452319829502… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 4 ┆ 540832786058427425452319829502… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 6 ┆ 540832786058427425452319829502… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 8 ┆ 540832786058427425452319829502… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"│ 10 ┆ 540832786058427425452319829502… ┆ 0 ┆ 100.0 ┆ 100 │\n",
"└──────┴─────────────────────────────────┴───────┴──────────────┴──────────┘"
]
},
"execution_count": 25,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
13 changes: 8 additions & 5 deletions examples/sugarscape_ig/ss_polars/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ def __init__(
self.add(agents)

def eat(self):
# Only consider cells currently occupied by agents of this set
cells = self.space.cells.filter(pl.col("agent_id").is_not_null())
self[cells["agent_id"], "sugar"] = (
self[cells["agent_id"], "sugar"]
+ cells["sugar"]
- self[cells["agent_id"], "metabolism"]
)
mask_in_set = cells["agent_id"].is_in(self.index)
if mask_in_set.any():
cells = cells.filter(mask_in_set)
ids = cells["agent_id"]
self[ids, "sugar"] = (
self[ids, "sugar"] + cells["sugar"] - self[ids, "metabolism"]
)

def step(self):
self.shuffle().do("move").do("eat")
Expand Down
8 changes: 6 additions & 2 deletions examples/sugarscape_ig/ss_polars/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ def __init__(
sugar=sugar_grid.flatten(), max_sugar=sugar_grid.flatten()
)
self.space.set_cells(sugar_grid)
self.sets += agent_type(self, n_agents, initial_sugar, metabolism, vision)
# Create and register the main agent set; keep its name for later lookups
main_set = agent_type(self, n_agents, initial_sugar, metabolism, vision)
self.sets += main_set
self._main_set_name = main_set.name
if initial_positions is not None:
self.space.place_agents(self.sets, initial_positions)
else:
self.space.place_to_empty(self.sets)

def run_model(self, steps: int) -> list[int]:
for _ in range(steps):
if len(list(self.sets.df.values())[0]) == 0:
# Stop if the main agent set is empty
if len(self.sets[self._main_set_name]) == 0: # type: ignore[index]
return
empty_cells = self.space.empty_cells
full_cells = self.space.full_cells
Expand Down
Loading
Loading