Skip to content

Commit

Permalink
Rename JupyterViz to SolaraViz (projectmesa#2187)
Browse files Browse the repository at this point in the history
* Rename JupyterViz to SolaraViz

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
rht and pre-commit-ci[bot] authored Jul 29, 2024
1 parent 01477fc commit 92e744b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions docs/tutorials/visualization_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@
},
"outputs": [],
"source": [
"from mesa.visualization import JupyterViz\n",
"from mesa.visualization import SolaraViz\n",
"\n",
"page = JupyterViz(\n",
"page = SolaraViz(\n",
" BoltzmannWealthModel,\n",
" model_params,\n",
" measures=[\"Gini\"],\n",
Expand Down Expand Up @@ -164,7 +164,7 @@
"metadata": {},
"outputs": [],
"source": [
"page = JupyterViz(\n",
"page = SolaraViz(\n",
" BoltzmannWealthModel,\n",
" model_params,\n",
" measures=[\"Gini\"],\n",
Expand Down Expand Up @@ -223,7 +223,7 @@
"metadata": {},
"outputs": [],
"source": [
"page = JupyterViz(\n",
"page = SolaraViz(\n",
" BoltzmannWealthModel,\n",
" model_params,\n",
" measures=[\"Gini\", make_histogram],\n",
Expand Down
4 changes: 2 additions & 2 deletions mesa/cookiecutter-mesa/{{cookiecutter.snake}}/app.pytemplate
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Configure visualization elements and instantiate a server
"""
from mesa.visualization import JupyterViz
from mesa.visualization import SolaraViz

from {{ cookiecutter.snake }}.model import {{ cookiecutter.model }}, {{ cookiecutter.agent }} # noqa

Expand All @@ -18,7 +18,7 @@ def circle_portrayal_example(agent):

model_params = {"num_agents": 10, "width": 10, "height": 10}

page = JupyterViz(
page = SolaraViz(
{{cookiecutter.model}},
model_params,
measures=["num_agents"],
Expand Down
4 changes: 2 additions & 2 deletions mesa/visualization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .jupyter_viz import JupyterViz, Slider, make_text
from .jupyter_viz import JupyterViz, Slider, SolaraViz, make_text

__all__ = ["JupyterViz", "make_text", "Slider"]
__all__ = ["JupyterViz", "make_text", "Slider", "SolaraViz"]
9 changes: 6 additions & 3 deletions mesa/visualization/jupyter_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Mesa models, allowing users to watch models run step-by-step and interact with model parameters.
Key features:
- JupyterViz: Main component for creating visualizations, supporting grid displays and plots
- SolaraViz: Main component for creating visualizations, supporting grid displays and plots
- ModelController: Handles model execution controls (step, play, pause, reset)
- UserInputs: Generates UI elements for adjusting model parameters
- Card: Renders individual visualization elements (space, measures)
Expand All @@ -17,7 +17,7 @@
Usage:
1. Define an agent_portrayal function to specify how agents should be displayed
2. Set up model_params to define adjustable parameters
3. Create a JupyterViz instance with your model, parameters, and desired measures
3. Create a SolaraViz instance with your model, parameters, and desired measures
4. Display the visualization in a Jupyter notebook or run as a Solara app
See the Visualization Tutorial and example models for more details.
Expand Down Expand Up @@ -85,7 +85,7 @@ def Card(


@solara.component
def JupyterViz(
def SolaraViz(
model_class,
model_params,
measures=None,
Expand Down Expand Up @@ -202,6 +202,9 @@ def do_reseed():
)


JupyterViz = SolaraViz


@solara.component
def ModelController(model, play_interval, current_step, reset_counter):
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_jupyter_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import solara

import mesa
from mesa.visualization.jupyter_viz import JupyterViz, Slider, UserInputs
from mesa.visualization.jupyter_viz import Slider, SolaraViz, UserInputs


class TestMakeUserInput(unittest.TestCase):
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_call_space_drawer(mocker):
# initialize with space drawer unspecified (use default)
# component must be rendered for code to run
solara.render(
JupyterViz(
SolaraViz(
model_class=mesa.Model,
model_params={},
agent_portrayal=agent_portrayal,
Expand All @@ -116,7 +116,7 @@ def test_call_space_drawer(mocker):
for falsy_value in [None, False, 0]:
mock_space_matplotlib.reset_mock()
solara.render(
JupyterViz(
SolaraViz(
model_class=mesa.Model,
model_params={},
agent_portrayal=agent_portrayal,
Expand All @@ -129,7 +129,7 @@ def test_call_space_drawer(mocker):
# specify a custom space method
altspace_drawer = Mock()
solara.render(
JupyterViz(
SolaraViz(
model_class=mesa.Model,
model_params={},
agent_portrayal=agent_portrayal,
Expand Down

0 comments on commit 92e744b

Please sign in to comment.