swarmsim.world.World#
Base world class.
See also
- class swarmsim.world.World.AbstractWorldConfig(size: tuple[float, ...] | numpy.ndarray = (0, 0), metrics: list = <factory>, agents: list = <factory>, spawners: list = <factory>, objects: list = <factory>, goals: list = <factory>, stop_at: int | collections.abc.Callable | None = None, background_color: tuple[int, int, int] = (0, 0, 0), seed: int | None = None, metadata: dict = <factory>, flags: dict[str, int] = <factory>)[source]#
- Attributes:
- radius
- seed
- stop_at
Methods
as_dict
asdict
create_world
from_dict
from_yaml
save_yaml
- background_color: tuple[int, int, int] = (0, 0, 0)[source]#
The background color of the world. Default is black.
- class swarmsim.world.World.World(config)[source]#
Base world class.
Methods
as_config_dict
as_dict
asdict
attach_gui
draw
evaluate
from_config
handle_key_press
set_seed
setup
step
step_agents
step_metrics
step_objects
step_spawners
- metrics: list[AbstractMetric][source]#
Metrics to calculate behaviors.
- swarmsim.world.World.World_from_config(config: dict)[source]#
Returns a new world instance from the given config.
- Parameters:
config (dict | WorldConfig) –
The config to create the world from.
The config should either be a dict with a
'type'
key, or an instance ofAbstractWorldConfig
with anassociated_type
field (which can be set using@~swarmsim.config.associated_type
).The Configuration System will be used to lookup the class for the world type.
- Returns:
A new world of type
config['associated_type']
orconfig.associated_type
.- Return type:
- swarmsim.world.World.config_from_dict(d: dict)[source]#
Create a world config dataclass from a dict.
- Parameters:
d (dict) –
The dict to create the world config from.
Must have a ‘type’ key that specifies the world type as a string.
- Returns:
Returns a dataclass of the world config. The type of the dataclass is determined by the ‘type’ key in the dict.
- Return type:
dataclass
- Raises:
ValueError – Raised if the dict does not have a ‘type’ key.
IndexError – Raised if the world type is not found in the registry.
- swarmsim.world.World.config_from_yaml(path: str | PathLike)[source]#
Load a YAML file and return a config object.
- swarmsim.world.World.config_from_yamls(s: str | Any)[source]#
Load a YAML string or stream and return a config object.
Functions
|
Returns a new world instance from the given config. |
Create a world config dataclass from a dict. |
|
|
Load a YAML file and return a config object. |
Load a YAML string or stream and return a config object. |
Classes
|
|
|
Base world class. |