sustaingym.algorithms.base#

Module Contents#

Classes#

BaseAlgorithm

Base abstract class for running an agent in an environment.

RLLibAlgorithm

Wrapper for RLLib RL agent.

RandomAlgorithm

Random action.

class sustaingym.algorithms.base.BaseAlgorithm(env: gymnasium.Env | pettingzoo.ParallelEnv, multiagent: bool = False)[source]#

Base abstract class for running an agent in an environment.

Subclasses are expected to implement the get_action() method.

Parameters:
  • env (gymnasium.Env | pettingzoo.ParallelEnv) – environment to run algorithm on

  • multiagent (bool) – whether the environment is multiagent

abstract get_action(observation: dict[str, Any]) numpy.ndarray | dict[str, numpy.ndarray][source]#

Returns an action based on gym observations.

Parameters:

observation (dict[str, Any]) –

Return type:

numpy.ndarray | dict[str, numpy.ndarray]

reset() None[source]#

Resets the algorithm at the end of each episode.

Return type:

None

run(seeds: collections.abc.Sequence[int] | int) pandas.DataFrame[source]#

Runs the scheduling algorithm and returns the resulting rewards.

Runs the scheduling algorithm for the date period of event generation and returns the resulting reward.

Parameters:

seeds (collections.abc.Sequence[int] | int) – if a list, on each episode run, self.env is reset using the seed. If an integer, a list is created using range(seeds) and used to reset the env instead.

Returns:

results – DataFrame of length len(seeds) or seeds containing reward info

column                  dtype
seed                    int
return                  float64
Return type:

pandas.DataFrame

class sustaingym.algorithms.base.RLLibAlgorithm(env: gymnasium.Env | pettingzoo.ParallelEnv, algo: ray.rllib.algorithms.algorithm.Algorithm, multiagent: bool = False)[source]#

Bases: BaseAlgorithm

Wrapper for RLLib RL agent.

Parameters:
  • env (gymnasium.Env | pettingzoo.ParallelEnv) –

  • algo (ray.rllib.algorithms.algorithm.Algorithm) –

  • multiagent (bool) –

get_action(observation: dict[str, Any]) numpy.ndarray | dict[str, numpy.ndarray][source]#

Returns output of RL model.

Parameters:

observation (dict[str, Any]) –

Return type:

numpy.ndarray | dict[str, numpy.ndarray]

class sustaingym.algorithms.base.RandomAlgorithm(env: gymnasium.Env | pettingzoo.ParallelEnv, multiagent: bool = False)[source]#

Bases: BaseAlgorithm

Random action.

Parameters:
  • env (gymnasium.Env | pettingzoo.ParallelEnv) –

  • multiagent (bool) –

get_action(observation: dict[str, Any]) Any[source]#

Returns random action.

Parameters:

observation (dict[str, Any]) –

Return type:

Any