ALLSHIFT/AICONTROL/tests/test_spaces.py
robert 702647d84e Updated the parameter names contained within the matlab controller david1606
TBD: parameters outside the controller, parameters contained on the old parameter doc
2026-09-11 13:05:38 +00:00

34 lines
1.3 KiB
Python

"""The observation and action spaces build from the config and mean what they say."""
import numpy as np
from aicontrol.env import spaces as S
def test_observation_layout_matches_config():
cfg = S.load_config()
space = S.build_observation_space(cfg)
fixed = 4 + 12 # calendar (2 + 2) plus the twelve single-value slots
fc = cfg["forecast"]
forecast = len(fc["quantities"]) * len(fc["horizons_min"]) * len(fc["quantiles"])
assert space.shape == (fixed + forecast,)
assert S.observation_size(cfg) == space.shape[0]
assert space.contains(space.sample())
def test_action_space_and_shedding_level():
cfg = S.load_config()
space = S.build_action_space(cfg)
assert space.shape == (len(S.ACTION_NAMES),)
assert space.contains(space.sample())
assert S.shedding_level(np.array([0, 0, 0, 0.2]), cfg) == S.SHEDDING_NONE
assert S.shedding_level(np.array([0, 0, 0, 1.4]), cfg) == S.SHEDDING_TIER3
assert S.shedding_level(np.array([0, 0, 0, 2.0]), cfg) == S.SHEDDING_TIERS_2_3
assert S.shedding_level(np.array([0, 0, 0, 9.0]), cfg) == S.SHEDDING_TIERS_2_3 # clipped
def test_describe_lists_every_named_slot():
cfg = S.load_config()
table = S.describe(cfg)
for name in ("P_PV", "SoC", "H2_level", "p_tank", "grid_on", "fcst_solar_60min", "fcst_tier3_1440min"):
assert f"`{name}`" in table