maxffarrell's picture
Release experimental Transition Foundation Model v0.1 with reproducible source and validation
1baf215 verified
Raw History Blame Contribute Delete
2.74 kB
"""Controlled, stable vocabulary; bounds describe sensors, never instance capacities."""
from dataclasses import dataclass
import numpy as np
DT_MINUTES = 15
HORIZONS = (1, 2, 4, 8)
GENERATOR_VERSION = "0.1.2"
@dataclass(frozen=True)
class FieldSpec:
name: str
unit: str
role: str
minimum: float
maximum: float
type: str = "continuous"
FIELD_SPECS = [
FieldSpec("indoor_temp", "degC", "state", -30, 70),
FieldSpec("mass_temp", "degC", "state", -30, 70),
FieldSpec("energy_kwh", "kWh", "state", 0, 1e6),
FieldSpec("water_level", "m3", "state", 0, 50),
FieldSpec("water_temp", "degC", "state", -5, 80),
FieldSpec("flow", "m3/h", "state", 0, 20),
FieldSpec("pressure", "kPa", "state", 0, 300),
FieldSpec("state_of_charge", "fraction", "state", 0, 1),
FieldSpec("battery_temp", "degC", "state", -30, 80),
FieldSpec("terminal_voltage", "V", "state", 10, 70),
FieldSpec("hvac_power", "kW", "action", -15, 15),
FieldSpec("valve_position", "fraction", "action", 0, 1),
FieldSpec("pump_output", "fraction", "action", 0, 1),
FieldSpec("battery_power", "kW", "action", -20, 20),
FieldSpec("outdoor_temp", "degC", "exogenous", -30, 60),
FieldSpec("solar_gain", "kW", "exogenous", 0, 5),
FieldSpec("occupancy_gain", "kW", "exogenous", 0, 3),
FieldSpec("demand", "m3/h", "exogenous", 0, 10),
FieldSpec("inlet_temp", "degC", "exogenous", -5, 60),
FieldSpec("ambient_temp", "degC", "exogenous", -30, 60),
]
FIELD_INDEX = {spec.name: i for i, spec in enumerate(FIELD_SPECS)}
NUM_FIELDS = len(FIELD_SPECS)
UNIT_NAMES = tuple(dict.fromkeys(spec.unit for spec in FIELD_SPECS))
ROLE_NAMES = ("state", "action", "exogenous")
UNIT_IDS = np.array([UNIT_NAMES.index(spec.unit) for spec in FIELD_SPECS], dtype=np.int64)
ROLE_IDS = np.array([ROLE_NAMES.index(spec.role) for spec in FIELD_SPECS], dtype=np.int64)
SCHEMAS = {
"thermal": [
"indoor_temp",
"mass_temp",
"energy_kwh",
"hvac_power",
"outdoor_temp",
"solar_gain",
"occupancy_gain",
],
"tank": [
"water_level",
"water_temp",
"flow",
"pressure",
"valve_position",
"pump_output",
"demand",
"inlet_temp",
],
"battery": ["state_of_charge", "battery_temp", "terminal_voltage", "battery_power", "ambient_temp"],
}
MAX_STATE_FIELDS = max(sum(FIELD_SPECS[FIELD_INDEX[n]].role == "state" for n in s) for s in SCHEMAS.values())
def role_fields(schema, role):
return [n for n in schema if FIELD_SPECS[FIELD_INDEX[n]].role == role]
def field_mask(schema):
mask = np.zeros(NUM_FIELDS, dtype=bool)
mask[[FIELD_INDEX[n] for n in schema]] = True
return mask