Base class#
A scenario is a generator of
World.Sub-classes should override
init_world()with a custom initialization that is performed each time a world is sampled (e.g., during an experiment).They can also be customized by adding groups using
add_group()and/or initializers usingadd_init, although these are not exposed to YAML.A group of agents that can be generated and added to the world.
Generate and add agents to the world.
- Parameters:
world – The world
seed – An optional random seed
Adds a group.
- Parameters:
group – The group
Adds a world initializer.
- Parameters:
initializer – The initializer
- Returns:
The associated key
Adds a property sampler.
- Parameters:
name – The name of the property
value – The sampler
Applies the initializers from
initsShould be called after
init_world()to complete the initialization, asmake_worlddoes automatically.- Parameters:
world – The world
Remove all groups
Removed all initializers
Clears the property samplers
Dumps the object to a YAML-string.
- Returns:
The YAML representation
- Return type:
Gets the value of the specified property.
- Parameters:
name – The name of the property
- Raise:
RuntimeError A runtime error if no property is found.
- Returns:
The value of the property
Gets a group.
- Parameters:
index – The index
- Returns:
The group or null if the index is not defined.
Gets the type of a property.
- Parameters:
name – The name of the property
- Returns:
The property type name or an empty string if the property is not defined.
Checks whether a property exists.
- Parameters:
name – The name of the property
- Returns:
True if the property exists
Check whether a type name has been registered.
- Parameters:
type – The associated type name.
- Returns:
True if the type name has been registered.
Initializes the world.
Users can specialize this method to specialize a scenario but should call
make_worldwhen creating a world.- Parameters:
world – The world
seed – The random seed
Load a scenario from a YAML string.
- Parameters:
value – the YAML string.
- Returns:
The loaded scenario or
Noneif loading fails.- Return type:
Scenario| None
Create an object of a sub-class selected by name.
- Parameters:
type – The associated type name.
- Returns:
An object of a registered sub-class or
Nonein case the desired name is not found.
Creates and initialize a world.
- Parameters:
seed – The random seed
Returns the json-schema that includes registered components.
- Returns:
“anyOf” json-schema of all registered components.
- Return type:
Remove the added group.
- Parameters:
group – The group
Remove the added group.
- Parameters:
index – The index
Remove the last added world initializer.
- Parameters:
key – The key
Removes a property sampler.
- Parameters:
name – The name of the property
Returns the json-schema of a component
Returns an empty dictionary if a not registered type is requested.
- Parameters:
reference_register_schema – Whether to reference registered components schema in the base class schema.
type (str) – An optional registered type. If not specified, it returns the schema of the base class.
- Returns:
A json-schema of the registered class
- Return type:
Set the value of a named property. Fails silently if no property can be found or if the value has a non-compatible type.
- Parameters:
name – The name of the property
value – The desired value for the property
Sets world attributes from scenario properties.
Sets an attribute with the current value for each (registered) property.
- Parameters:
world – The world
Sets a world initializer.
- Parameters:
key – The key
initializer – The initializer
Sets the yaml representation
- Type:
BoundingBox | None
An optional bounding box
- Type:
Whether to generate worlds where collisions between any entities are ignored
- Type:
dict[str, Callable[[World, SupportsInt | None], None]]
The world initializers.
- Type:
The name associated to the type of an object