swarmsim.world.World#

Base world class.

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

agents: list[source]#

The list of agent configs for the world

Type:

list

as_dict()[source]#
asdict()[source]#
background_color: tuple[int, int, int] = (0, 0, 0)[source]#

The background color of the world. Default is black.

Type:

tuple[int, int, int]

create_world()[source]#
flags: dict[str, int][source]#
classmethod from_dict(env)[source]#
classmethod from_yaml(path)[source]#
goals: list[source]#
metadata: dict[source]#
metrics: list[source]#

The list of metrics configs for the world

Type:

list

objects: list[source]#

The list of objects configs for the world

Type:

list

property radius[source]#
save_yaml(path)[source]#
seed: int | None = None[source]#

The seed to use for the world. If None, the world will be seeded based on system time.

Type:

int | None

size: tuple[float, ...] | ndarray = (0, 0)[source]#
spawners: list[source]#

The list of spawner configs for the world

Type:

list

stop_at: int | Callable | None = None[source]#

The maximum number of steps to run the simulation.

Type:

int | Callable | None

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

as_config_dict()[source]#
as_dict()[source]#
asdict()[source]#
attach_gui(gui: AbstractGUI)[source]#
draw(screen, offset=None)[source]#
evaluate(steps: int, output_capture: OutputTensorConfig | None = None, screen=None)[source]#
classmethod from_config(c)[source]#
handle_key_press(event)[source]#
metrics: list[AbstractMetric][source]#

Metrics to calculate behaviors.

objects: list[Agent][source]#

The list of world objects.

population: list[Agent][source]#

List of agents in the world.

rng: Generator[source]#

Random number generator. Also may be used to seed RNG for agents, spawners, etc.

set_seed(seed)[source]#
setup(step_spawners=True)[source]#
spawners: list[Spawner][source]#

List of spawners which create agents or objects.

step()[source]#
step_agents()[source]#
step_metrics()[source]#
step_objects()[source]#
step_spawners()[source]#
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 of AbstractWorldConfig with an associated_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'] or config.associated_type.

Return type:

World

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

World_from_config(config)

Returns a new world instance from the given config.

config_from_dict(d)

Create a world config dataclass from a dict.

config_from_yaml(path)

Load a YAML file and return a config object.

config_from_yamls(s)

Load a YAML string or stream and return a config object.

Classes

AbstractWorldConfig(size, ...)

World(config)

Base world class.