projectmesa / mesa-frames

Extension of mesa for performance and scalability
https://projectmesa.github.io/mesa-frames
Apache License 2.0
14 stars 5 forks source link

Benchmark result of docs/scripts/readme_plot.py, native expression vs concise/simple API #22

Closed rht closed 4 months ago

rht commented 4 months ago

For both pandas and Polars, there are at least 3 ways to do things for each steps. But they can be roughly split into 2: using native expression and using a simpler, more concise API. We should split further into 4 agents:

  1. MoneyAgentPolarsNative
  2. MoneyAgentPolarsConcise
  3. MoneyAgentPandasNative
  4. MoneyAgentPandasConcise

and benchmark them. Because:

  1. researchers who want to speed up their code further could see if the effort is worth it
  2. it could become a how-to guide on speeding up the code further via the native expression
rht commented 4 months ago

@adamamer20 https://github.com/adamamer20/mesa-frames/blob/bf1ccd9328f260a746c21a6bad7e15a7a6898dc3/docs/scripts/readme_plot.py#L132-L136 doesn't seem to work. I got this error

  File "/github/projectmesa/mesa-frames/docs/scripts/readme_plot.py", line 163, in give_money
    .then(pl.col("wealth") + new_wealth["wealth"])
                             ~~~~~~~~~~^^^^^^^^^^
  File "/code/venv/lib/python3.11/site-packages/polars/dataframe/frame.py", line 1183, in __getitem__
    return get_df_item_by_key(self, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/venv/lib/python3.11/site-packages/polars/_utils/getitem.py", line 160, in get_df_item_by_key
    return df.get_column(key)
           ^^^^^^^^^^^^^^^^^^
  File "/code/venv/lib/python3.11/site-packages/polars/dataframe/frame.py", line 7557, in get_column
    return wrap_s(self._df.get_column(name))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ColumnNotFoundError: wealth
adamamer20 commented 4 months ago

This is a good idea, we can also check the performance overhead of mesa-frames. I corrected the bug in main, i will make the necessary changes in #23.

rht commented 4 months ago

Closed via #23 and #24.