Add Search and Rescue example: overlapping meta-agents + scenario sweep - #491
Open
shipitdev wants to merge 1 commit into
Open
Add Search and Rescue example: overlapping meta-agents + scenario sweep#491shipitdev wants to merge 1 commit into
shipitdev wants to merge 1 commit into
Conversation
Fills the empty Continuous Space section of the README with the first example to exercise Mesa 4's meta-agent membership backend beyond static, single-membership groups, and the first to use the scenarios runner. Responders self-organise into crews, task forces and an incident command, all held in the membership backend rather than on the agents. A medic is a `member` of its home crew and `on_call` to the medical pool at the same time, gaining a third `attached` edge when another crew borrows it, so overlap and relation labels are load-bearing rather than decorative. Hierarchy depth is read structurally via `at_level`. The sweep runs 240 scenarios over crew size and specialist policy and asserts the sequential and process-pool execution backends agree, which is the point of the pluggable executor. Result: pooling scarce specialists beats embedding them at every crew size, while smaller crews rescue more at the cost of a wider span of control. The README records several Mesa 4 sharp edges found while building this: `MetaAgent.step` shadowing a `step` on the class passed as `mesa_agent_type`, `extract_class` raising StopIteration when a group name is reused after all groups of that name are dissolved, `TableDataSet` re-snapshotting its whole table per collection, and portrayal fields needing to be set on every agent to avoid a ragged-array IndexError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
examples/search_and_rescue, filling the README's empty Continuous Space Examples section. It's the first example to exercise the meta-agent membership backend beyond static single-membership groups, and the first to use Responders sweep a continuous space to reach casualties before their survival deadlines, organising into crews, task forces and an incident command. All of that structure lives in the membership backend rather than on the agents, which is what makes the overlap possible:memberon_callattachedA medic holds all three at once, and
Crew.responders()enforces that exactly one crew commands it at a time. Hierarchy depth is read structurally viaat_level()rather than stored —span_of_controlis a query against the graph, not a counter.This complements rather than duplicates the existing meta-agent examples:
warehousecovers relation labels on as static structure, andalliance_formationcoversfind_combinations. Neither usesat_level,dissolve,query_memberships, or runtime formation and teardown.Results
experiment.pyruns 240 scenarios (6 crew sizes × 2 policies × 20 replications) and asserts the sequential andProcessPoolExecutorbackends agree — 0 mismatches.Notes for reviewers
The example README documents several Mesa 4 sharp edges I hit while building this, in case they're useful beyond this PR:
MetaAgent.stepshadows astepdefined on the class passed asmesa_agent_type, since groups are built astype(name, (MetaAgent, *bases)). Crew behaviour is namedadvance()to avoid it.extract_classraisesStopIterationwhen a group name is reused after every group of that name has been dissolved — theagents_by_typebucket is retained but empty, so the name lookup succeeds andnext(iter(...))then fails. Worked around here with unique task-force names; happy to open a separate core issue with a minimal repro if that's wanted.TableDataSet.datareturns the whole accumulated table on every collection, so it re-snapshots if registered with a recorder. This example records a model-level time series instead.edgecolorson only some of them yields a ragged array and anIndexErrorin the matplotlib backend.ipyvuetify<3is pinned inrequirements.txtbecause solara 1.61 can't drive the ipyvue 3.x line ("GlobalVue.use is not a function").Test plan
pytest examples/search_and_rescue/tests/— 26 passedpytest test_examples.py— the new model constructs with no arguments andrun_for(10)leavestime == 10.0solara run app.pyverified in a browser: space renders, crews form, medics visibly change crew colour when seconded and change back on release, plots updatepython experiment.py --compare— 240 runs, both execution backends agreeruff checkandruff formatclean