Constrained Markov Game (CMG)¶
masa.common.constraints.multi_agent.cmg.Budget
dataclass
¶
Shared cumulative-cost budget over a subset of agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
Maximum allowed cumulative cost for this budget. |
required |
agents
|
tuple[str, ...]
|
Subset of agents from |
required |
name
|
str | None
|
Optional metric prefix. If omitted, a generated name is used. |
None
|
Notes
Agent memberships are deduplicated while preserving order. Budgets may overlap, so a single agent may contribute to more than one budget.
__post_init__ ¶
Source code in masa/common/constraints/multi_agent/cmg.py
masa.common.constraints.multi_agent.cmg.ConstrainedMarkovGame ¶
ConstrainedMarkovGame(possible_agents: Sequence[str], budgets: Sequence[Budget], cost_fn: CostFn = dummy_cost_fn)
Cumulative-cost monitor for a labelled parallel PettingZoo environment.
Source code in masa/common/constraints/multi_agent/cmg.py
reset ¶
Reset per-agent and per-budget cumulative costs for a new episode.
Source code in masa/common/constraints/multi_agent/cmg.py
update ¶
Update the monitor from a mapping of agent ids to active labels.
Source code in masa/common/constraints/multi_agent/cmg.py
satisfied ¶
Return True when every budget remains within its cap.
step_metric ¶
Return per-step metrics for agents and budgets.
Source code in masa/common/constraints/multi_agent/cmg.py
episode_metric ¶
Return end-of-episode cumulative metrics for agents and budgets.
Source code in masa/common/constraints/multi_agent/cmg.py
masa.common.constraints.multi_agent.cmg.ConstrainedMarkovGameEnv ¶
ConstrainedMarkovGameEnv(env: ParallelEnv, budgets: Sequence[Budget], cost_fn: CostFn = dummy_cost_fn, **kw: Any)
Bases: ParallelEnv
PettingZoo parallel wrapper that updates a ConstrainedMarkovGame.
Source code in masa/common/constraints/multi_agent/cmg.py
_constraint
instance-attribute
¶
_constraint = ConstrainedMarkovGame(possible_agents=self.possible_agents, budgets=budgets, cost_fn=cost_fn)
budgets
property
¶
Return the immutable CMG budget definitions used by this wrapper.
__getattr__ ¶
reset ¶
Reset the wrapped env and seed the constraint from initial agent labels.
Source code in masa/common/constraints/multi_agent/cmg.py
step ¶
Step the wrapped env and update the constraint from per-agent labels.
Source code in masa/common/constraints/multi_agent/cmg.py
state ¶
render ¶
close ¶
observation_space ¶
action_space ¶
constraint_step_metrics ¶
constraint_episode_metrics ¶
_labels_by_agent ¶
_labels_by_agent(infos: Mapping[str, Mapping[str, Any] | None]) -> dict[str, set[str] | frozenset[str]]
Extract and validate infos[agent]['labels'] for all possible agents.