Skip to content

Meta agents #2575

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cd33057
meta_agents
tpike3 Dec 28, 2024
593bbe7
Merge branch 'projectmesa:main' into meta-agents
tpike3 Dec 28, 2024
5bc7b95
Meta-Agents
tpike3 Dec 29, 2024
a87d382
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 29, 2024
c7c8311
refactor meta-agent
tpike3 Dec 31, 2024
3b9fa59
Merge branch 'main' into meta-agents
tpike3 Jan 6, 2025
3529b7d
Basic bugfix for bug ContinuousSpace.get_neighbors (#2599)
quaquel Jan 6, 2025
1b0ad15
[pre-commit.ci] pre-commit autoupdate (#2601)
pre-commit-ci[bot] Jan 7, 2025
70375d1
Reimplementation of Continuous Space (#2584)
quaquel Jan 10, 2025
804ea95
reimplementation of draw_voroinoi (#2608)
quaquel Jan 10, 2025
16261f5
Add render interval slider to control visualization update frequency …
HMNS19 Jan 10, 2025
80a4f2b
Add docs for continuous space (#2613)
quaquel Jan 11, 2025
3f460cf
Update release notes and version for 3.1.3 (#2612)
EwoutH Jan 11, 2025
291da0e
remove remnants of mesa cli (#2617)
quaquel Jan 14, 2025
7eacc72
remove any reference to using --pre (#2618)
quaquel Jan 14, 2025
6e44ad4
added color-bar
sanika-n Jan 16, 2025
4aa9513
Documentation (#2630)
Spartan-71 Jan 19, 2025
910e99b
benchmarks.yml: Install SciPy and use uv for pip install (#2633)
EwoutH Jan 20, 2025
c24f13c
Adding a copy option at the top of the code written in the docs
PrashantChoudhary13579 Jan 18, 2025
fbb3e58
Add sphinx-copybutton to documentation dependencies in pyproject.toml
PrashantChoudhary13579 Jan 20, 2025
8477af0
Change Hexgrid._connect_cells_2d to use x,y coordinates (#2632)
quaquel Jan 20, 2025
802aa63
bugfix for draw_property_layer (#2639)
quaquel Jan 23, 2025
76b0bc4
meta_agents
tpike3 Dec 28, 2024
f231add
Meta-Agents IP
tpike3 Mar 6, 2025
09fd684
Meta-Agents IP2
tpike3 Mar 6, 2025
a486d6c
integrate main
tpike3 Mar 16, 2025
e444a6e
update meta agents
tpike3 Mar 18, 2025
13caec5
Merge branch 'main' into meta-agents
tpike3 Mar 25, 2025
f732051
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 25, 2025
ffd4507
Updates
tpike3 Mar 26, 2025
47112d3
Merge branch 'main' into meta-agents
tpike3 Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/apis/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ This namespace contains experimental features. These are under development, and
.. automodule:: experimental.continuous_space.continuous_space_agents
:members:
```

## Continuous Space

```{eval-rst}
.. automodule:: experimental.continuous_space.continuous_space
:members:
```

```{eval-rst}
.. automodule:: experimental.continuous_space.continuous_space_agents
:members:
```
212 changes: 195 additions & 17 deletions docs/tutorials/visualization_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,115 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/javascript": [
"\n",
" window.jupyter_python_executable = '\\r\\r';\n",
" window.jupyter_widget_checks_silent = true;\n",
" window.jupyter_widget_checks_libraries = [{\"python\": \"ipyvuetify\", \"classic\": \"jupyter-vuetify/extension\", \"lab\": \"jupyter-vuetify\"}, {\"python\": \"ipyvue\", \"classic\": \"jupyter-vue/extension\", \"lab\": \"jupyter-vue\"}];\n",
" "
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div class=\"jupyter-widget-checks-container\">\n",
" <script>\n",
" (function () {\n",
" console.log(\"Checking for jupyter-widgets extensions\")\n",
" const inLab = window._JUPYTERLAB !== undefined;\n",
" const silent = jupyter_widget_checks_silent;\n",
" const containers = document.getElementsByClassName('jupyter-widget-checks-container');\n",
" const rootEl = containers[containers.length - 1];\n",
" const libraries = window.jupyter_widget_checks_libraries;\n",
"\n",
" function getBaseUrl() {\n",
" const labConfigData = document.getElementById(\"jupyter-config-data\");\n",
" if (labConfigData) {\n",
" /* lab and Voila */\n",
" return JSON.parse(labConfigData.textContent).baseUrl;\n",
" }\n",
" let base = document.body.dataset.baseUrl || document.baseURI;\n",
" return base;\n",
" }\n",
"\n",
" function checkLibrary(extensions, library) {\n",
" let installed = false;\n",
" let ok = true;\n",
" if (inLab) {\n",
" installed = _JUPYTERLAB[library.lab] !== undefined\n",
" } else {\n",
" installed = extensions[library.classic] !== undefined;\n",
" let enabled = extensions[library.classic] === true;\n",
" }\n",
" const div = document.createElement(\"div\")\n",
" if (installed) {\n",
" if (!silent) {\n",
" div.innerHTML = `Extension ${library.python} is installed at the server ✅`\n",
" rootEl.appendChild(div)\n",
" }\n",
" } else {\n",
" div.innerHTML = `Extension ${library.python} is <b>NOT</b> installed at the server ❌.`\n",
" rootEl.appendChild(div)\n",
" ok = false;\n",
" }\n",
" return ok;\n",
" }\n",
"\n",
" async function check() {\n",
" const url = `${getBaseUrl()}api/config/notebook`\n",
" const response = (await fetch(url));\n",
" const data = await response.json()\n",
" const extensions = data[\"load_extensions\"];\n",
" var ok = true;\n",
" let needsInstall = [];\n",
" libraries.forEach((library) => {\n",
" if (!checkLibrary(extensions, library)) {\n",
" ok = false;\n",
" needsInstall.push(library.python)\n",
" console.log(\"Needs install\", library.python)\n",
" }\n",
" })\n",
" console.log(ok, needsInstall)\n",
" if (!ok) {\n",
" const div = document.createElement(\"div\")\n",
" const div2 = document.createElement(\"div\")\n",
" div.innerHTML = `Run <code>${jupyter_python_executable} -m pip install ${needsInstall.join(\" \")}</code>. Refresh the page after installation.`\n",
" div2.innerHTML = `Visit <a href=\"https://solara.dev/documentation/getting_started/troubleshoot\" target=\"_blank\">https://solara/dev/documentation/getting_started/troubleshoot</a> for more information.`\n",
" rootEl.appendChild(div)\n",
" rootEl.appendChild(div2)\n",
" }\n",
" }\n",
" check()\n",
" })();\n",
" </script>\n",
"</div>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mesa version: 3.2.0.dev\n"
]
}
],
"source": [
"import mesa\n",
"from mesa.visualization import SolaraViz, make_plot_component, make_space_component\n",
Expand Down Expand Up @@ -179,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -199,7 +305,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -233,9 +339,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e5937d177a5e49a18c1fc57a2cbbbf23",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
],
"text/plain": [
"Cannot show ipywidgets in text"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Create initial model instance\n",
"money_model = MoneyModel(n=50, width=10, height=10) # keyword arguments\n",
Expand Down Expand Up @@ -270,7 +394,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -299,9 +423,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7c0c0f82c1ca462abafd48f3bee60099",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
],
"text/plain": [
"Cannot show ipywidgets in text"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Create initial model instance\n",
"money_model = MoneyModel(n=50, width=10, height=10)\n",
Expand Down Expand Up @@ -338,7 +480,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -350,7 +492,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -386,7 +528,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -406,7 +548,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -419,14 +561,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-29T19:38:49.471838Z",
"start_time": "2024-10-29T19:38:47.897295Z"
}
},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b16003c82a72456b932cdcd89da268e5",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
],
"text/plain": [
"Cannot show ipywidgets in text"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"page = SolaraViz(\n",
" money_model,\n",
Expand All @@ -447,14 +607,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-29T19:38:49.505725Z",
"start_time": "2024-10-29T19:38:49.472599Z"
}
},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ab1835364c534d56800ce8eae7699c70",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
],
"text/plain": [
"Cannot show ipywidgets in text"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Histogram(money_model)"
]
Expand Down
21 changes: 11 additions & 10 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,23 @@ class Agent:
# so, unique_id is unique relative to a model, and counting starts from 1
_ids = defaultdict(functools.partial(itertools.count, 1))

def __init__(self, model: Model, *args, **kwargs) -> None:
def __init__(
self, model: Model, *args, key_by_name: bool = False, **kwargs
) -> None:
"""Create a new agent.

Args:
model (Model): The model instance in which the agent exists.
args: passed on to super
kwargs: passed on to super

Notes:
to make proper use of python's super, in each class remove the arguments and
keyword arguments you need and pass on the rest to super

key_by_name (bool): If True, use Agent.__name__ as the key in the model's agents_by_type dictionary.
args: Passed on to super.
kwargs: Passed on to super.
"""
super().__init__(*args, **kwargs)

self.model: Model = model
self.unique_id: int = next(self._ids[model])
self.pos: Position | None = None
self.model.register_agent(self)
self.model.register_agent(self, key_by_name=key_by_name)

def remove(self) -> None:
"""Remove and delete the agent from the model.
Expand Down Expand Up @@ -103,7 +101,10 @@ def create_agents(cls, model: Model, n: int, *args, **kwargs) -> AgentSet[Agent]
"""

class ListLike:
"""Helper class to make default arguments act as if they are in a list of length N."""
"""Make default arguments act as if they are in a list of length N.

This is a helper class.
"""

def __init__(self, value):
self.value = value
Expand Down
Loading
Loading