ALLSHIFT/AICONTROL/tests/test_spaces.py
pepe ef7857da31 Add shared Python environment, AICONTROL cluster folder, and CLAUDE.md
- Root pyproject.toml + uv.lock: one pinned Python 3.12 environment for every
  cluster (the Project Manual's rule), as a uv workspace; cluster code folders
  are workspace members.
- AICONTROL/: the AI & Control cluster package. spaces.py builds the 64-value
  observation and 4-value action spaces from configs/env.yaml; interface draft
  for the November session with Simulations; tests; clone-and-run README.
- .gitignore: Python environment, caches, W&B runs, raw data downloads.
- CLAUDE.md: repository guidance for Claude Code.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-11 14:15:02 +02: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