envs package¶
Submodules¶
envs.bat_env_fwd_view module¶
- class envs.bat_env_fwd_view.BatteryEnvFwd(env_config)[source]¶
Bases:
Env
- CO2_footprint(dc_load, ci, a_t, discharge_energy)[source]¶
Calculates carbon footprint
- Parameters:
dc_load (float) – Total energy consumption of the DC.
ci (float) – Carbon intensity at current time step.
a_t (string) – Agent’s action.
discharge_energy (float) – Amount of energy to be discharged
- Returns:
Carbon footprint produced at the current time step (gCO2e)
- Return type:
CO2_footprint (float)
- charging_rate_modifier(battery)[source]¶
Calculates the battery state depending on the charging rate
- Parameters:
battery (batt.Battery2) – Battery model
- Returns:
Battery charging rate
- Return type:
charging_rate (float)
- discharging_rate_modifier(battery)[source]¶
Calculates the battery state depending on the discharging rate
- Parameters:
battery (batt.Battery2) – Battery model
- Returns:
Battery discharging rate
- Return type:
discharging_rate (float)
- reset(*, seed=None, options=None)[source]¶
Reset BatteryEnvFwd to initial state.
- Parameters:
seed (int, optional) – Random seed.
options (dict, optional) – Environment options.
- Returns:
Current state of the environmment info (dict): A dictionary that containing additional information about the environment state
- Return type:
temp_state (List[float])
- set_dcload(dc_load)[source]¶
Set the current DC energy consumption
- Parameters:
float (dc_load) – DC energy consumption.
- step(action_id)[source]¶
Step function :param action_id: the action id :type action_id: int
- Returns:
Current state of the environmment reward (float): reward value. done (bool): A boolean value signaling the if the episode has ended. info (dict): A dictionary that containing additional information about the environment state
- Return type:
obs (list)
envs.battery_model module¶
- class envs.battery_model.Battery2(capacity, current_load=0, eff_c=1, eff_d=1, c_lim=0.1, d_lim=1, upper_u=-0.04, upper_v=1, lower_u=0.01, lower_v=0)[source]¶
Bases:
object
- c_lim = 3¶
- capacity = 0¶
- current_load = 0¶
- d_lim = 3¶
- eff_c = 1¶
- eff_d = 1¶
- lower_lim_u = 0¶
- lower_lim_v = 0¶
- upper_lim_u = 0¶
- upper_lim_v = 1¶
envs.carbon_ls module¶
- class envs.carbon_ls.CarbonLoadEnv(env_config={}, future=True, n_vars_ci=4, flexible_workload_ratio=0.2, n_vars_energy=0, n_vars_battery=1, test_mode=False, queue_max_len=500)[source]¶
Bases:
Env
- reset(*, seed=None, options=None)[source]¶
Reset CarbonLoadEnv to initial state.
- Returns:
Current state of the environmment info (dict): A dictionary that containing additional information about the environment state
- Return type:
observations (List[float])
- step(action)[source]¶
Makes an environment step in`CarbonLoadEnv.
- Parameters:
action (int) – Action to take.
- Returns:
Current state of the environmment reward (float): reward value. done (bool): A boolean value signaling the if the episode has ended. info (dict): A dictionary that containing additional information about the environment state
- Return type:
observations (List[float])
envs.datacenter module¶
- class envs.datacenter.CPU(full_load_pwr=None, idle_pwr=None, cpu_config=None)[source]¶
Bases:
object
- class envs.datacenter.DataCenter_ITModel(num_racks, rack_supply_approach_temp_list, rack_CPU_config, max_W_per_rack=10000, DC_ITModel_config=None, chiller_sizing=False)[source]¶
Bases:
object
- calculate_cooling_tower_water_usage()[source]¶
Calculate the estimated water usage of the cooling tower.
This function uses the attributes set in the class to estimate the water usage based [Sharma, R.K., Shah, A., Bash, C.E., Christian, T., & Patel, C.D. (2009). Water efficiency management in datacenters: Metrics and methodology. 2009 IEEE International Symposium on Sustainable Systems and Technology, 1-6.] [Mohammed Shublaq, Ahmad K. Sleiti., (2020). Experimental analysis of water evaporation losses in cooling towers using filters] https://spxcooling.com/water-calculator/
- compute_datacenter_IT_load_outlet_temp(ITE_load_pct_list, CRAC_setpoint)[source]¶
Calculate the average outlet temperature of all the racks
- Parameters:
ITE_load_pct_list (List[float]) – CPU load for each rack
CRAC_setpoint (float) – CRAC setpoint
- Returns:
Rackwise CPU power usage rackwise_itfan_pwr (List[float]): Rackwise IT fan power usage rackwise_outlet_temp (List[float]): Rackwise outlet temperature
- Return type:
rackwise_cpu_pwr (List[float])
- class envs.datacenter.Rack(CPU_config_list, max_W_per_rack=10000, rack_config=None)[source]¶
Bases:
object
- clamp_supply_approach_temp(supply_approach_temperature)[source]¶
Returns the clamped delta/ supply approach temperature between the range [3.8, 5.3]
- Returns:
Supply approach temperature
- Return type:
float
- compute_instantaneous_pwr(inlet_temp, ITE_load_pct)[source]¶
Calculate the power consumption of the whole rack at the current step
- Parameters:
inlet_temp (float) – Room temperature
ITE_load_pct (float) – Current CPU usage
- Returns:
Current CPU power usage
- Return type:
cpu_power (float)
- get_average_rack_fan_v()[source]¶
Calculate the average fan velocity for each rack :returns: Average fan flow rate for the rack :rtype: (float)
- envs.datacenter.calculate_HVAC_power(CRAC_setpoint, avg_CRAC_return_temp, ambient_temp, data_center_full_load, DC_Config, ctafr=None)[source]¶
Calculate the HVAV power attributes
- Parameters:
CRAC_Setpoint (float) – The control action
avg_CRAC_return_temp (float) – The average of the temperatures from all the Racks + their corresponding return approach temperature (Delta)
ambient_temp (float) – outside air temperature
data_center_full_load (float) – total data center capacity
- Returns:
CRAC fan power CT_Fan_pwr (float): Cooling tower fan power CRAC_cooling_load (float): CRAC cooling load Compressor_load (float): Chiller compressor load
- Return type:
CRAC_Fan_load (float)
- envs.datacenter.calculate_avg_CRAC_return_temp(rack_return_approach_temp_list, rackwise_outlet_temp)[source]¶
Calculate the CRAC return air temperature
- Parameters:
rack_return_approach_temp_list (List[float]) – The delta change in temperature from each rack to the CRAC unit
rackwise_outlet_temp (float) – The outlet temperature of each rack
- Returns:
CRAC return air temperature
- Return type:
(float)
- envs.datacenter.calculate_chiller_power(max_cooling_cap, load, ambient_temp)[source]¶
Calculate the chiller power consumption based on load and operating conditions. Obtained from:
- Parameters:
load (float) – The heat load to be removed by the chiller (Watts).
ambient_temp (float) – Current ambient temperature (Celsius).
- Returns:
Estimated power consumption of the chiller (Watts).
- Return type:
float
- envs.datacenter.chiller_sizing(DC_Config, min_CRAC_setpoint=16, max_CRAC_setpoint=22, max_ambient_temp=40.0)[source]¶
Calculates the chiller sizing for a data center based on the given configuration and parameters.
- Parameters:
DC_Config (object) – The data center configuration object.
min_CRAC_setpoint (float) – The minimum CRAC setpoint temperature in degrees Celsius. Default is 16.
max_CRAC_setpoint (float) – The maximum CRAC setpoint temperature in degrees Celsius. Default is 22.
max_ambient_temp (float) – The maximum ambient temperature in degrees Celsius. Default is 40.0.
- Returns:
A tuple containing the cooling tower reference air flow rate (ctafr) and the rated load of the cooling tower (CT_rated_load).
- Return type:
tuple
envs.dc_gym module¶
- class envs.dc_gym.dc_gymenv(observation_variables: list, observation_space: Box, action_variables: list, action_space: Discrete, action_mapping: dict, ranges: dict, add_cpu_usage: bool, min_temp: float, max_temp: float, action_definition: dict, DC_Config: dict, seed: int = 123, episode_length_in_time: Timedelta | None = None)[source]¶
Bases:
Env
- get_obs()[source]¶
Returns the observation at the current time step.
- Returns:
Current state of the environmment.
- Return type:
observation (List[float])
- reset(*, seed=None, options=None)[source]¶
Reset dc_gymenv to initial state.
- Parameters:
seed (int, optional) – Random seed.
options (dict, optional) – Environment options.
- Returns:
Current state of the environmment {} (dict): A dictionary that containing additional information about the environment state
- Return type:
raw_curr_state (List[float])
- step(action)[source]¶
Makes an environment step in`dc_gymenv.
- Parameters:
action_id (int) – Action to take.
- Returns:
Current state of the environmment reward (float): reward value. done (bool): A boolean value signaling the if the episode has ended. info (dict): A dictionary that containing additional information about the environment state
- Return type:
observations (List[float])
envs.dcrl_env module¶
envs.dcrl_env_harl module¶
- class envs.dcrl_env_harl.DCRL(env_config)[source]¶
Bases:
Env
- calculate_reward(params)[source]¶
Calculate the individual reward for each agent.
- Parameters:
params (dict) – Dictionary of parameters to calculate the reward.
- Returns:
Individual reward for the load shifting agent. dc_reward (float): Individual reward for the data center agent. bat_reward (float): Individual reward for the battery agent.
- Return type:
ls_reward (float)
- close()[source]¶
After the user has finished using the environment, close contains the code necessary to “clean up” the environment.
This is critical for closing rendering windows, database or HTTP connections.
- render()[source]¶
Compute the render frames as specified by
render_mode
during the initialization of the environment.The environment’s
metadata
render modes (env.metadata[“render_modes”]) should contain the possible ways to implement the render modes. In addition, list versions for most render modes is achieved through gymnasium.make which automatically applies a wrapper to collect rendered frames.Note
As the
render_mode
is known during__init__
, the objects used to render the environment state should be initialised in__init__
.By convention, if the
render_mode
is:None (default): no render is computed.
“human”: The environment is continuously rendered in the current display or terminal, usually for human consumption. This rendering should occur during
step()
andrender()
doesn’t need to be called. ReturnsNone
.“rgb_array”: Return a single frame representing the current state of the environment. A frame is a
np.ndarray
with shape(x, y, 3)
representing RGB values for an x-by-y pixel image.“ansi”: Return a strings (
str
) orStringIO.StringIO
containing a terminal-style text representation for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).“rgb_array_list” and “ansi_list”: List based version of render modes are possible (except Human) through the wrapper,
gymnasium.wrappers.RenderCollection
that is automatically applied duringgymnasium.make(..., render_mode="rgb_array_list")
. The frames collected are popped afterrender()
is called orreset()
.
Note
Make sure that your class’s
metadata
"render_modes"
key includes the list of supported modes.Changed in version 0.25.0: The render function was changed to no longer accept parameters, rather these parameters should be specified in the environment initialised, i.e.,
gymnasium.make("CartPole-v1", render_mode="human")
- reset()[source]¶
Reset the environment.
- Parameters:
seed (int, optional) – Random seed.
options (dict, optional) – Environment options.
- Returns:
Dictionary of states. infos (dict): Dictionary of infos.
- Return type:
states (dict)
- step(action_dict)[source]¶
Step the environment.
- Parameters:
action_dict – Dictionary of actions of each agent defined in self.agents.
- Returns:
Dictionary of observations/states. rews (dict): Dictionary of rewards. terminated (dict): Dictionary of terminated flags. truncated (dict): Dictionary of truncated flags. infos (dict): Dictionary of infos.
- Return type:
obs (dict)
- class envs.dcrl_env_harl.EnvConfig(raw_config)[source]¶
Bases:
dict
- DEFAULT_CONFIG = {'actions_are_logits': False, 'agents': ['agent_ls', 'agent_dc', 'agent_bat'], 'bat_reward': 'default_bat_reward', 'cintensity_file': 'NYIS_NG_&_avgCI.csv', 'datacenter_capacity_mw': 1, 'days_per_episode': 30, 'dc_config_file': 'dc_config.json', 'dc_reward': 'default_dc_reward', 'evaluation': False, 'flexible_load': 0.1, 'individual_reward_weight': 0.8, 'location': 'ny', 'ls_reward': 'default_ls_reward', 'max_bat_cap_Mw': 2, 'timezone_shift': 0, 'weather_file': 'USA_NY_New.York-Kennedy.epw', 'workload_file': 'Alibaba_CPU_Data_Hourly_1.csv'}¶
envs.dcrl_env_harl_partialobs module¶
- class envs.dcrl_env_harl_partialobs.DCRL(env_config)[source]¶
Bases:
Env
- calculate_reward(params)[source]¶
Calculate the individual reward for each agent.
- Parameters:
params (dict) – Dictionary of parameters to calculate the reward.
- Returns:
Individual reward for the load shifting agent. dc_reward (float): Individual reward for the data center agent. bat_reward (float): Individual reward for the battery agent.
- Return type:
ls_reward (float)
- close()[source]¶
After the user has finished using the environment, close contains the code necessary to “clean up” the environment.
This is critical for closing rendering windows, database or HTTP connections.
- get_available_capacity(time_steps: int) float [source]¶
Calculate the available capacity of the datacenter over the next time_steps.
- Parameters:
time_steps (int) – Number of 15-minute time steps to consider.
- Returns:
The available capacity in MW.
- Return type:
float
- render()[source]¶
Compute the render frames as specified by
render_mode
during the initialization of the environment.The environment’s
metadata
render modes (env.metadata[“render_modes”]) should contain the possible ways to implement the render modes. In addition, list versions for most render modes is achieved through gymnasium.make which automatically applies a wrapper to collect rendered frames.Note
As the
render_mode
is known during__init__
, the objects used to render the environment state should be initialised in__init__
.By convention, if the
render_mode
is:None (default): no render is computed.
“human”: The environment is continuously rendered in the current display or terminal, usually for human consumption. This rendering should occur during
step()
andrender()
doesn’t need to be called. ReturnsNone
.“rgb_array”: Return a single frame representing the current state of the environment. A frame is a
np.ndarray
with shape(x, y, 3)
representing RGB values for an x-by-y pixel image.“ansi”: Return a strings (
str
) orStringIO.StringIO
containing a terminal-style text representation for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).“rgb_array_list” and “ansi_list”: List based version of render modes are possible (except Human) through the wrapper,
gymnasium.wrappers.RenderCollection
that is automatically applied duringgymnasium.make(..., render_mode="rgb_array_list")
. The frames collected are popped afterrender()
is called orreset()
.
Note
Make sure that your class’s
metadata
"render_modes"
key includes the list of supported modes.Changed in version 0.25.0: The render function was changed to no longer accept parameters, rather these parameters should be specified in the environment initialised, i.e.,
gymnasium.make("CartPole-v1", render_mode="human")
- reset()[source]¶
Reset the environment.
- Parameters:
seed (int, optional) – Random seed.
options (dict, optional) – Environment options.
- Returns:
Dictionary of states. infos (dict): Dictionary of infos.
- Return type:
states (dict)
- step(action_dict)[source]¶
Step the environment.
- Parameters:
action_dict – Dictionary of actions of each agent defined in self.agents.
- Returns:
Dictionary of observations/states. rews (dict): Dictionary of rewards. terminated (dict): Dictionary of terminated flags. truncated (dict): Dictionary of truncated flags. infos (dict): Dictionary of infos.
- Return type:
obs (dict)
- class envs.dcrl_env_harl_partialobs.EnvConfig(raw_config)[source]¶
Bases:
dict
- DEFAULT_CONFIG = {'actions_are_logits': False, 'agents': ['agent_ls', 'agent_dc', 'agent_bat'], 'bat_reward': 'default_bat_reward', 'cintensity_file': 'NYIS_NG_&_avgCI.csv', 'datacenter_capacity_mw': 1, 'days_per_episode': 30, 'dc_config_file': 'dc_config.json', 'dc_reward': 'default_dc_reward', 'evaluation': False, 'flexible_load': 0.1, 'individual_reward_weight': 0.8, 'location': 'ny', 'ls_reward': 'default_ls_reward', 'max_bat_cap_Mw': 2, 'timezone_shift': 0, 'weather_file': 'USA_NY_New.York-Kennedy.epw', 'workload_file': 'Alibaba_CPU_Data_Hourly_1.csv'}¶
envs.geo_dcrl module¶
envs.heirarchical_env module¶
envs.hierarchical_env_harl module¶
envs.hierarchical_env_rllib module¶
envs.truly_heirarchical_env module¶
envs.truly_heirarchical_ms_env module¶
Module contents¶
Includes the environments.