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

Add logging to MESA #2506

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Add logging to MESA #2506

wants to merge 8 commits into from

Conversation

quaquel
Copy link
Member

@quaquel quaquel commented Nov 13, 2024

This is WIP, but showcases how we can add logging to MESA. It adds a new logger module with a couple of helper functions, and two decorators (one for adding logging to functions, an another for adding logging to methods).

Its use is illustrated in solara_viz and model, and the boltzman wealth example shows it use. It is WIP.

Current log output in stderr:

[MESA.mesa.visualization.solara_viz DEBUG] calling SolaraViz with (<mesa.examples.basic.boltzmann_wealth_model.model.BoltzmannWealth object at 0x107ff3590>,) and {'components': [<function make_mpl_space_component.<locals>.MakeSpaceMatplotlib at 0x16b12e5c0>, <function make_mpl_plot_component.<locals>.MakePlotMatplotlib at 0x16b12ed40>], 'model_params': {'seed': {'type': 'InputText', 'value': 42, 'label': 'Random Seed'}, 'n': {'type': 'SliderInt', 'value': 50, 'label': 'Number of agents:', 'min': 10, 'max': 100, 'step': 1}, 'width': 10, 'height': 10}, 'name': 'Boltzmann Wealth Model'}
[MESA.mesa.visualization.solara_viz DEBUG] calling do_reset with () and {}
[MESA.mesa.visualization.solara_viz DEBUG] creating new <class 'mesa.examples.basic.boltzmann_wealth_model.model.BoltzmannWealth'> instance with {'width': 10, 'height': 10, 'seed': 42, 'n': 50}
[MESA.mesa.model DEBUG] calling Model.__init__ with () and {'seed': 42}
[MESA.mesa.model DEBUG] calling Model.register_agent with (<mesa.examples.basic.boltzmann_wealth_model.agents.MoneyAgent object at 0x16b5edc50>,) and {}
[MESA.mesa.model DEBUG] calling Model.register_agent with (<mesa.examples.basic.boltzmann_wealth_model.agents.MoneyAgent object at 0x16b5edc10>,) and {}
[MESA.mesa.model DEBUG] calling Model.register_agent with (<mesa.examples.basic.boltzmann_wealth_model.agents.MoneyAgent object at 0x16b5eda10>,) and {}
[MESA.mesa.model DEBUG] calling Model.register_agent with (<mesa.examples.basic.boltzmann_wealth_model.agents.MoneyAgent object at 0x16b5ed990>,) and {}
[MESA.mesa.model DEBUG] calling Model.register_agent with (<mesa.examples.basic.boltzmann_wealth_model.agents.MoneyAgent object at 0x16b5ed950>,) and {}

feedback welcome.

I will add

  • - include the arguments/keyword arguments for model initialization
  • - add the steps counter so you know at which step you are
  • - add the unique_id of the agent registering.

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔴 +16.5% [+15.0%, +18.3%] 🔵 -0.7% [-0.8%, -0.5%]
BoltzmannWealth large 🔴 +18.3% [+17.7%, +18.9%] 🔵 -1.8% [-3.8%, +0.0%]
Schelling small 🔴 +18.3% [+18.1%, +18.6%] 🔵 -0.8% [-1.1%, -0.6%]
Schelling large 🔴 +19.0% [+18.5%, +19.6%] 🔵 -0.6% [-1.3%, +0.1%]
WolfSheep small 🔴 +13.5% [+13.2%, +13.8%] 🔵 +3.0% [+2.8%, +3.1%]
WolfSheep large 🔴 +14.0% [+13.1%, +15.0%] 🔵 +3.5% [+2.0%, +5.0%]
BoidFlockers small 🔴 +8.1% [+7.6%, +8.6%] 🔵 +0.1% [-0.6%, +0.8%]
BoidFlockers large 🔴 +7.4% [+6.8%, +8.0%] 🔵 -0.4% [-1.1%, +0.0%]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant