gym_acnportal.gym_acnsim.envs.custom_envs¶
This package contains customizable gym environments that wrap simulations.
Module Contents¶
Classes¶
A simulator environment with customizable observations, action |
|
A simulator environment that subclasses CustomSimEnv, with |
Functions¶
|
A simulator environment with the following characteristics: |
|
A simulator environment with the same characteristics as the |
-
class
gym_acnportal.gym_acnsim.envs.custom_envs.CustomSimEnv(interface: Optional[GymTrainedInterface], observation_objects: List[SimObservation], action_object: gym_acnportal.gym_acnsim.envs.action_spaces.SimAction, reward_functions: List[Callable[[BaseSimEnv], float]])¶ Bases:
gym_acnportal.gym_acnsim.envs.base_env.BaseSimEnvA simulator environment with customizable observations, action spaces, and rewards.
Observations are specified as objects, where each object specifies a function to generate a space from a simulation interface and a function to generate an observation from a simulation interface.
Action spaces are specified as functions that generate a space from a simulation interface.
Rewards are specified as functions that generate a number (reward) from an environment.
Users may define their own objects/functions to input to this environment, use the objects/functions defined in the gym_acnsim package, or use an environment factory function defined in the sim_prototype_env module.
-
observation_objects:List[SimObservation]¶
-
observation_space:spaces.Dict¶
-
action_object:SimAction¶
-
action_space:spaces.Space¶
-
reward_functions:List[Callable[[BaseSimEnv], float]]¶
-
property
interface(self) → gym_acnportal.gym_acnsim.interfaces.GymTrainedInterface¶ Get the current Interface of the environment.
- Returns:
GymTrainedInterface: The current Interface of the environment.
-
abstract
render(self, mode='human')¶ Renders the environment. Implements gym.Env.render().
-
action_to_schedule(self) → Dict[str, List[float]]¶ Convert an agent action to a schedule to be input to the simulator.
- Returns:
- schedule (Dict[str, List[float]]): Dictionary mapping
station ids to a schedule of pilot signals.
-
observation_from_state(self) → Dict[str, np.ndarray]¶ Construct an environment observation from the state of the simulator using the environment’s observation construction functions.
- Returns:
- observation (Dict[str, np.ndarray]): An environment
observation generated from the simulation state
-
reward_from_state(self) → float¶ Calculate a reward from the state of the simulator
- Returns:
- reward (float): a reward generated from the simulation
state
-
done_from_state(self) → bool¶ Determine if the simulation is done from the state of the simulator
- Returns:
done (bool): True if the simulation is done, False if not
-
info_from_state(self) → Dict[Any, Any]¶ Give information about the environment using the state of the simulator. In this case, all the info about the simulator is given by returning a dict containing the simulator’s interface.
- Returns:
- info (Dict[str, GymTrainedInterface]): The interface between
the environment and Simulator.
-
-
gym_acnportal.gym_acnsim.envs.custom_envs.default_observation_objects:List[SimObservation]¶
-
gym_acnportal.gym_acnsim.envs.custom_envs.default_action_object:SimAction¶
-
gym_acnportal.gym_acnsim.envs.custom_envs.default_reward_functions:List[Callable[[BaseSimEnv], float]]¶
-
gym_acnportal.gym_acnsim.envs.custom_envs.make_default_sim_env(interface: Optional[GymTrainedInterface] = None) → gym_acnportal.gym_acnsim.envs.custom_envs.CustomSimEnv¶ A simulator environment with the following characteristics:
The action and observation spaces are continuous.
An action in this environment is a pilot signal for each EVSE, within the minimum and maximum EVSE rates.
An observation is a dict consisting of fields (times are 1-indexed in the observations):
- arrivals: arrival time of the EV at each EVSE (or 0 if there’s
no EV plugged in)
- departures: departure time of the EV at each EVSE (or 0 if
there’s no EV plugged in)
- demand: energy demand of the EV at each EVSE (unoccupied
EVSEs have demand 0)
constraint_matrix: matrix of aggregate current coefficients magnitudes: magnitude vector constraining aggregate currents timestep: timestep of the simulation
- The reward is calculated as follows:
- If no constraints (on the network or on the EVSEs) were
violated by the action,
- a reward equal to the total charge delivered (in A) is
returned
- If any constraint violation occurred, a negative reward equal
to the magnitude of the violation is returned.
Network constraint violations are scaled by the number of EVs Finally, a user-input reward function is added to the total
reward.
The simulation is considered done if the event queue is empty.
-
class
gym_acnportal.gym_acnsim.envs.custom_envs.RebuildingEnv(interface: Optional[GymTrainedInterface], observation_objects: List[SimObservation], action_object: gym_acnportal.gym_acnsim.envs.action_spaces.SimAction, reward_functions: List[Callable[[BaseSimEnv], float]], interface_generating_function: Optional[Callable[], GymTrainedInterface]] = None)¶ Bases:
gym_acnportal.gym_acnsim.envs.custom_envs.CustomSimEnvA simulator environment that subclasses CustomSimEnv, with the extra property that the entire simulation is rebuilt within the environment when __init__ or reset are called
This is especially useful if the network or event queue have stochastic elements.
-
classmethod
from_custom_sim_env(cls, env: gym_acnportal.gym_acnsim.envs.custom_envs.CustomSimEnv, interface_generating_function: Optional[Callable[], GymTrainedInterface]] = None) → gym_acnportal.gym_acnsim.envs.custom_envs.RebuildingEnv¶
-
reset(self) → Dict[str, np.ndarray]¶ Resets the state of the simulation and returns an initial observation. Resetting is done by setting the interface to the simulation to an interface to the simulation in its initial state.
- Returns:
observation (np.ndarray): the initial observation.
-
abstract
render(self, mode='human')¶ Renders the environment. Implements gym.Env.render().
-
classmethod
-
gym_acnportal.gym_acnsim.envs.custom_envs.make_rebuilding_default_sim_env(interface_generating_function: Optional[Callable[], GymTrainedInterface]]) → gym_acnportal.gym_acnsim.envs.custom_envs.RebuildingEnv¶ A simulator environment with the same characteristics as the environment returned by make_default_sim_env except on every reset, the simulation is completely rebuilt using interface_generating_function.
See make_default_sim_env for more info.