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

gis: update four examples to use solara viz #211

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

wang-boyu
Copy link
Member

@wang-boyu wang-boyu commented Sep 28, 2024

Partly addresses #154.

Update the following four gis examples to use the new solara visualization:

  • agents_and_networks
  • geo_schelling
  • geo_schelling_points
  • geo_sir

Update their dependency of mesa-geo to v0.9.0a0.

Also update the folder structure of the geo_sir model from

geo_sir
├── agents.py
├── model.py
├── app.py
├── ...

to

geo_sir
├── geo_sir
│   ├── __init__.py
│   ├── agents.py
│   └── model.py
├── app.py
├── ...

to be consistent with other gis examples.

@EwoutH
Copy link
Member

EwoutH commented Sep 28, 2024

Awesome work!

If others don’t get to it, I will review Monday.

```

Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and press `Start`.
Then open your browser to [http://127.0.0.1:8765/](http://127.0.0.1:8765/) and press `Start`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no "Start" button anymore. It is "▶".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! Fixed now.

@wang-boyu wang-boyu force-pushed the gis/solara-viz branch 2 times, most recently from 14872eb to ad1e606 Compare September 28, 2024 14:49
@wang-boyu
Copy link
Member Author

Also updated the agents_networks example model. Won't update any other examples in this PR.

@wang-boyu wang-boyu changed the title gis: update three examples to use solara viz gis: update four examples to use solara viz Sep 28, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it the other way around, and keep everything in a gis/geo_sir.

Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, this looks really nice!

Also great that you cleaned some old files up.

Go ahead and merge!

@EwoutH
Copy link
Member

EwoutH commented Oct 3, 2024

Personally, I would highly prefer adoption this structure for all examples. It's by far the most straightforward and clearly arranged one.

geo_sir
├── agents.py
├── model.py
├── app.py

@wang-boyu
Copy link
Member Author

I had some difficulties in using the flat folder structure. If model.py and agents.py are inside gis/geo_sir together with app.py, then solara run app.py gives the following errors:

    from .agents import PersonAgent
ImportError: attempted relative import with no known parent package
   from .agents import NeighbourhoodAgent, PersonAgent
ImportError: attempted relative import with no known parent package

I will then have to change all the imports from .agent to agents, for example:

# from
from .agents import NeighbourhoodAgent, PersonAgent

# to
from agents import NeighbourhoodAgent, PersonAgent

Then solara run app.py runs fine. However, tests cases will throw errors:

___________________________________________________ ERROR collecting test_gis_examples.py ___________________________________________________
ImportError while importing test module '/Users/boyu/GitHubProjects/mesa-examples/test_gis_examples.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/Cellar/python@3.12/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_gis_examples.py:30: in <module>
    @pytest.mark.parametrize("model_class", get_models("gis"))
test_gis_examples.py:17: in get_models
    module = importlib.import_module(module_name)
/usr/local/Cellar/python@3.12/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
gis/geo_sir/model.py:7: in <module>
    from agents import NeighbourhoodAgent, PersonAgent
E   ModuleNotFoundError: No module named 'agents'
========================================================== short test summary info ==========================================================
ERROR test_gis_examples.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

So I simply use the updated folder structure that works for both solara and tests.

@wang-boyu
Copy link
Member Author

With the approvals I'll go ahead and merge this, so that users can have a working frontent for these examples. Thanks for looking into this @rht @EwoutH.

@wang-boyu wang-boyu merged commit 9897884 into projectmesa:main Oct 6, 2024
3 checks passed
@wang-boyu wang-boyu deleted the gis/solara-viz branch October 6, 2024 14:36
@EwoutH
Copy link
Member

EwoutH commented Oct 6, 2024

Awesome! I would be totally fine with you merging faster/earlier, if you feel that would speed up your development of these models.

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.

3 participants