Environment
- class sorrel.environment.Environment(world: W, config: DictConfig | dict | list, stop_if_done: bool = False)
An abstract wrapper class for running experiments with agents and environments.
- world
The world that the experiment includes.
- Type:
W
- config
The configurations for the experiment.
- Type:
omegaconf.dictconfig.DictConfig
- stop_if_done
Whether to end the epoch if the world is done. Defaults to False.
Note
Some default methods provided by this class, such as run_experiment, require certain config parameters to be defined. These parameters are listed in the docstring of the method.
- Type:
bool
Methods
Abstract Methods
- abstractmethod Environment.setup_agents() None
This method should create a list of agents, and assign it to self.agents.
- abstractmethod Environment.populate_environment() None
This method should populate self.world.map.
Note that self.world.map is already created with the specified dimensions, and every space is filled with the default entity of the environment, as part of self.world.create_world() when this experiment is constructed. One simply needs to place the agents and any additional entitites in self.world.map.
Non-Abstract Methods
- Environment.reset() None
Reset the experiment, including the environment and the agents.
- Environment.take_turn() None
Performs a full step in the environment.
This function iterates through the environment and performs transition() for each entity, then transitions each agent.
- Environment.run_experiment(animate: bool = True, logging: bool = True, logger: Logger | None = None, output_dir: Path | None = None) None
Run the experiment.
- Required config parameters:
experiment.epochs: The number of epochs to run the experiment for.
experiment.max_turns: The maximum number of turns each epoch.
(Only if animate is true) experiment.record_period: The time interval at which to record the experiment.
If animate is true, animates the experiment every self.config.experiment.record_period epochs.
If logging is true, logs the total loss and total rewards each epoch.
- Parameters:
animate – Whether to animate the experiment. Defaults to True.
logging – Whether to log the experiment. Defaults to True.
logger – The logger to use. Defaults to a ConsoleLogger.
output_dir – The directory to save the animations to. Defaults to “./data/” (relative to current working directory).