How it works¶
The co-simulation loop¶
EnergyPlus drives its own time loop and calls back into Python at fixed points; a Gymnasium agent
instead expects to call step() itself. frads-gym gives each side its own thread:
reset()builds the EnergyPlus model with frads, registers the glazing systems, generates (or loads) the Radiance matrices and starts EnergyPlus in a background thread.- EnergyPlus calls frads-gym at the end of every HVAC system timestep. Energy variables that EnergyPlus
reports per HVAC sub-step (for example
Zone Air System Sensible Cooling Energyor coil energies) are summed over the sub-steps of the zone timestep. - At the end of each zone timestep the callback collects the observation: EnergyPlus variables, the current glazing states, and the Radiance results (illuminance, glare) for those states. It puts the observation into a queue and blocks.
step(action)maps each action dimension to a glazing state, hands the states to the callback and waits for the next observation. The callback actuates the windows (and the daylight-dimmed lights) and returns; EnergyPlus computes the next timestep with the new states.
Two queues and one event carry the exchange; nothing is serialised across processes.
Timing of actions and observations¶
One step() corresponds to one EnergyPlus zone timestep (number_of_timesteps_per_hour). By default
reset() lets EnergyPlus run one timestep ahead to obtain the first observation, so the observation
returned by step(a) was produced before a took effect: actions act with a delay of one step, and an
episode over N timesteps has N - 1 steps. With sync_first_action=True, reset() returns the first
observation without releasing EnergyPlus, so the first action acts on the transition that observation
starts.
Episodes¶
| Situation | step() returns |
Next reset() |
|---|---|---|
| End of the run period | truncated=True, info["simulation_finished"]=True |
restarts EnergyPlus, with the next weather file if several are given |
truncate_on="day" or "month" and the date passes into a new day or month |
truncated=True |
continues the running simulation |
| A step that timed out (600 s without an observation) | truncated=True, info["sim_step_error"] |
restarts EnergyPlus |
staggered_start=True shifts the start month of run_periods per environment (env_id of n_envs)
and per reset, so parallel environments see different seasons.
Observations, info and reward¶
The observation is a Dict with one entry per active config entry that has an observation_space,
plus datetime: six features, the sine and cosine of the hour of day, the day of the year and the day
of the week. Values are normalised as configured (Configuration).
info carries the raw values: raw_current_<key> before the step, raw_next_<key> after it, for every
active entry, including those without an observation_space (these are read and logged, but not
observed). The reward function is called as reward_function(obs, action, next_obs, info).
Outputs¶
Everything goes to output_dir, which also becomes the working directory of the process:
| Path | Content |
|---|---|
eplusout/ |
EnergyPlus output of the current run |
Matrices/, Octrees/ |
Radiance matrices and octrees generated by frads |
environment_log.csv |
one row per step with raw and normalised observations, action and reward (logging=True) |
Parallel environments¶
EnergyPlus keeps a process-wide state and frads-gym reaches the running simulation through a
process-wide context, so only one environment can run per process. Run several in separate processes,
for example with stable-baselines3's SubprocVecEnv, each with its own output_dir.
Reproducibility¶
frads samples the matrices between sensors and windows randomly, so two runs differ slightly (about ±3 % in vertical illuminance at a glare sensor). A fixed matrix set removes that:
- Create it once: set
FRADS_MATRIX_WRITE=1, pointmodel_setup.fixed_matrices(or the environment variableFRADS_MATRIX_DIR) to an empty directory and callreset(). frads-gym stores one<zone>.npzper zone under<dir>/<IDF name>/together withmanifest.json. - Use it: run without
FRADS_MATRIX_WRITE. Every zone loads its matrices and checks them against the manifest (the building model, the sensor positions and the files); a mismatch is an error.
Fixed matrices need model_setup.model_path, because the set is keyed by the model file.
Errors¶
The configuration and the constructor arguments are checked when the environment is created, and every
problem is listed at once (frads_gym.validation.ConfigError). Errors inside the EnergyPlus callback,
for example a variable the model does not provide or a failed Radiance calculation, stop EnergyPlus and
are raised by the next step() or reset() as RuntimeError with the original exception as cause.