Skip to content

Adds Altair plot component and some other fixes #2644

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

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

Conversation

nissu99
Copy link
Contributor

@nissu99 nissu99 commented Jan 26, 2025

#2435

  • - rename make_space_altair to something like make_altair_space_component
  • - add make_altair_plot_component
  • - Add support for all spaces. This means including the hexgrid and network transformation of the x and y coordinates.
  • - Have a generic get_agent_data method

@quaquel @EwoutH I’ve added a new component, make_altair_plot_component. Could you kindly check if it aligns well with the project?

P.S working on space support.

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +1.3% [+0.4%, +2.2%] 🔵 -0.3% [-0.5%, -0.2%]
BoltzmannWealth large 🔵 -1.2% [-1.8%, -0.6%] 🔵 -0.5% [-1.6%, +0.7%]
Schelling small 🔵 -0.7% [-1.0%, -0.5%] 🔵 +0.8% [+0.6%, +0.9%]
Schelling large 🔵 -0.7% [-1.1%, -0.3%] 🔵 -0.9% [-1.3%, -0.5%]
WolfSheep small 🔵 +0.1% [-0.1%, +0.3%] 🔵 +1.1% [+0.9%, +1.2%]
WolfSheep large 🔵 +0.9% [+0.3%, +1.5%] 🔵 +1.9% [+1.2%, +2.5%]
BoidFlockers small 🔵 -0.7% [-1.3%, -0.2%] 🔵 +1.8% [+1.6%, +2.0%]
BoidFlockers large 🔵 -0.1% [-0.5%, +0.4%] 🔵 +1.9% [+1.6%, +2.3%]

@nissu99 nissu99 changed the title ADDS ALTAIR PLOT COMPONENT AND SOME OTHER FIXES #2435 ADDS ALTAIR PLOT COMPONENT AND SOME OTHER FIXES Jan 26, 2025
@EwoutH EwoutH requested review from Corvince and quaquel January 26, 2025 10:41
@EwoutH
Copy link
Member

EwoutH commented Jan 26, 2025

Thanks for the PR! A few of the automated checks broke, could you look into what caused that?

I will leave the review to others.

@tpike3
Copy link
Member

tpike3 commented Jan 26, 2025

@nissu99 also please look at #2643 and #2641 As you are @sanika-n are working in the same space

As it looks like you two are looking over the entire altair implementation I would also recommend looking at #2642 discussion

It is always good to collaborate and think together you may address some larger visualization challenges.

@nissu99
Copy link
Contributor Author

nissu99 commented Jan 27, 2025

@tpike3 When I run the tests locally, they don't fail, but they are failing here.

image

@tpike3
Copy link
Member

tpike3 commented Jan 27, 2025

@tpike3 When I run the tests locally, they don't fail, but they are failing here.

image

I am not sure why your tests are passing locally, however for tests to pass they need to updated. It is expecting None and now getting Chart, because you added post process.

__ ERROR collecting tests/test_components_matplotlib.py _____________
tests/test_components_matplotlib.py:[20](https://github.com/projectmesa/mesa/actions/runs/12984364297/job/36207123671?pr=2644#step:6:21): in <module>
    from mesa.visualization.mpl_space_drawing import (
mesa/visualization/__init__.py:13: in <module>
    from .components import make_plot_component, make_space_component
mesa/visualization/components/__init__.py:7: in <module>
    from .altair_components import (
mesa/visualization/components/altair_components.py:93: in <module>
    post_process: Callable[[alt.Chart], alt.Chart] | None = None,
E   AttributeError: 'NoneType' object has no attribute 'Chart'

@nissu99
Copy link
Contributor Author

nissu99 commented Jan 27, 2025

@tpike3 When I run the tests locally, they don't fail, but they are failing here.
image

I am not sure why your tests are passing locally, however for tests to pass they need to updated. It is expecting None and now getting Chart, because you added post process.

__ ERROR collecting tests/test_components_matplotlib.py _____________
tests/test_components_matplotlib.py:[20](https://github.com/projectmesa/mesa/actions/runs/12984364297/job/36207123671?pr=2644#step:6:21): in <module>
    from mesa.visualization.mpl_space_drawing import (
mesa/visualization/__init__.py:13: in <module>
    from .components import make_plot_component, make_space_component
mesa/visualization/components/__init__.py:7: in <module>
    from .altair_components import (
mesa/visualization/components/altair_components.py:93: in <module>
    post_process: Callable[[alt.Chart], alt.Chart] | None = None,
E   AttributeError: 'NoneType' object has no attribute 'Chart'

Thank You, the issue got resolved by adding altair to the toml file.

@nissu99
Copy link
Contributor Author

nissu99 commented Jan 30, 2025

@quaquel @tpike3 i was making a generic get_agent_data function ,should i remove all the old functions like _get_agent_data_new_discrete_space or keeping them will be right?

@quaquel
Copy link
Member

quaquel commented Jan 30, 2025

Removing stuff that has become redundant is fine.

@nissu99
Copy link
Contributor Author

nissu99 commented Jan 31, 2025

@quaquel i have added all the stuff,can you review it?

@quaquel
Copy link
Member

quaquel commented Jan 31, 2025

I'll try to review it over the weekend, but I am rather bussy at the moment. This is a part of the code base I am not intimately familiar with and his been a while since I used Altair, so reviewing will take more time than parts of the code base I know inside out.

@nissu99
Copy link
Contributor Author

nissu99 commented Feb 17, 2025

@Sahil-Chhoker can you check the changes?

@nissu99
Copy link
Contributor Author

nissu99 commented Feb 17, 2025

This PR added Altair Plot support ,worked on a generic data extracting function , created different functions for drawing different types of grids similar to that in matplot _space and tried to make overall api as similar as that of mpl_space api.

@Corvince Corvince changed the title ADDS ALTAIR PLOT COMPONENT AND SOME OTHER FIXES Adds Altair plot component and some other fixes Feb 18, 2025
@nissu99
Copy link
Contributor Author

nissu99 commented Feb 18, 2025

@nissu99 very sorry for misleading you but the generic agent data collection needs to be changed to be like the one used in matplotlib.

No worries ,this is how we learn.

@nissu99
Copy link
Contributor Author

nissu99 commented Feb 18, 2025

@Sahil-Chhoker Sorry for the inconvenience. I will test more carefully this time.

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 1, 2025

@Sahil-Chhoker i have made the changes .

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 2, 2025

I have done a basic review, the grid drawing can wait, let's go step by step. Our first step here should be to finalize the agent data collecting logic, therefore why is the agent data collecting logic not made into a function like is done in matplotlib part? Also does this implementation cover all the grids (again compare with this)

stuff like vernoi grid has not been added ,will have to look into it to properly add it.

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 2, 2025

@nissu99 I can see why you got confused, I think he meant the generic function should be called in the respective draw functions and hence agnet_portrayal was passed to the draw functions. Again if you look at the matplotlib side you will get it. I think the exact same method can be used to get the data, can you try importing the method from the matplotlib side and using it to test if that works

I thought ,later he wants to make some universal function which can be reused.

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 2, 2025

You don't have to worry about the new API, its still in discussion.

i tried using the collect_agent_data function it does not give the desired results.

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 2, 2025

will ha

How did you test it, can you please elaborate how is it not working?

i used the internal examples ,somehow it shows no agent showing ,it is not able to extract the data ,will have to properly look into it to understand the issue well.

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 2, 2025

image

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 8, 2025

@Sahil-Chhoker sorry for not getting back ,just got my college holidays started , i think the extraction is the fault here
when i printed the collect_agent_data returned values it was an empty array .

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 8, 2025

Its working fine for me, can you test again. I don't think its a difficult task, you just replace the agent data collection logic with the collect_agent_data function call inside the grid draw logic.

i get that , it is not working for OrthogonalMooreGrid somehow,for others it works fine.

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 9, 2025

It worked ,i made a dumb mistake ,should i make a commit for changing the extraction logic?

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 11, 2025

I will change all the experimental to discrete_space ,I agree the changes have increased and i understand it is becoming very hard to review , is the extraction logic fine ?

@Corvince
Copy link
Contributor

And again I strongly recommend you to break this PR into smaller once.

Maybe to clarify what this means: Just open a series of new PRs, one after another. So start with some minimal changes as a single PR, which includes the groundwork for the rest. Once this PR is merged, open the next PR with changes to some other function/grid/whatever. And so on. Its more tedious this way, but overall it will speed things up. Right now the PR is too big to properly review, because it requires code review, which is already almost too much, but also manually testing everything.

You can also just leave this PR open for now as a reference.

@nissu99
Copy link
Contributor Author

nissu99 commented Mar 12, 2025

And again I strongly recommend you to break this PR into smaller once.

Maybe to clarify what this means: Just open a series of new PRs, one after another. So start with some minimal changes as a single PR, which includes the groundwork for the rest. Once this PR is merged, open the next PR with changes to some other function/grid/whatever. And so on. Its more tedious this way, but overall it will speed things up. Right now the PR is too big to properly review, because it requires code review, which is already almost too much, but also manually testing everything.

You can also just leave this PR open for now as a reference.

Thank You for clarity ,will be making individual PR's .

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

Successfully merging this pull request may close these issues.

6 participants