Skip to content

TyperError when model reporter is a partial function #1871

@wang-boyu

Description

@wang-boyu

Describe the bug

$ python3 scripts/run.py --campus ub

Traceback (most recent call last):
  File "/Users/boyu/GitHubProjects/mesa-examples/gis/agents_and_networks/scripts/run.py", line 57, in <module>
    server = mesa.visualization.ModularServer(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/boyu/GitHubProjects/mesa-examples/venv/lib/python3.11/site-packages/mesa/visualization/ModularVisualization.py", line 355, in __init__
    self.reset_model()
  File "/Users/boyu/GitHubProjects/mesa-examples/venv/lib/python3.11/site-packages/mesa/visualization/ModularVisualization.py", line 382, in reset_model
    self.model = self.model_cls(**model_params)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/boyu/GitHubProjects/mesa-examples/gis/agents_and_networks/src/model/model.py", line 127, in __init__
    self.datacollector.collect(self)
  File "/Users/boyu/GitHubProjects/mesa-examples/venv/lib/python3.11/site-packages/mesa/datacollection.py", line 182, in collect
    self.model_vars[var].append(reporter())
                                ^^^^^^^^^^
TypeError: get_num_commuters_by_status() missing 1 required positional argument: 'model'

Expected behavior

The example model is expected to run without errors.

To Reproduce

Run the https://github.com/projectmesa/mesa-examples/tree/main/gis/agents_and_networks example model with latest Mesa, Mesa-Geo and Mesa-Viz-Tornado

Additional context

In the example model, the model reporters are partial functions:

https://github.com/projectmesa/mesa-examples/blob/10985d44091b9ba1ecebd013d2d2252e2116649b/gis/agents_and_networks/src/model/model.py#L21-L41

https://github.com/projectmesa/mesa-examples/blob/10985d44091b9ba1ecebd013d2d2252e2116649b/gis/agents_and_networks/src/model/model.py#L111-L126

But the support for partial functions was dropped in 64ce416 while dealing with attribute strings.

As a result, when partial functions are used, they are added in this way:

https://github.com/projectmesa/mesa/blob/2505ba408fa1d9e20046c2184406e869c1e4d4eb/mesa/datacollection.py#L200-L203

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions