You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/ui.rst
+8-16Lines changed: 8 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,12 +18,13 @@ You can check a tutorial at the official CityLearn `website <https://intelligent
18
18
Exporting Data From CityLearn into CityLearn UI
19
19
===============================================
20
20
21
-
CityLearn automatically exports the folder structure expected by the UI. There are a few workflows to consider:
21
+
CityLearn automatically exports the folder structure expected by the UI. The behaviour depends on :class:`citylearn.citylearn.CityLearnEnv` ``render_mode``:
22
22
23
-
* ``render_mode='none'`` (default): no CSVs are produced, so the UI cannot ingest data.
24
-
* ``render_mode='during'``: data is exported every simulation step into timestamped folders. You may keep the default location (``<project>/SimulationData/<timestamp>``) or set ``render_directory``/``render_directory_name``/:code:`render_session_name` on :class:`citylearn.citylearn.CityLearnEnv` to choose the destination and a custom subfolder.
25
-
* ``render_mode='end'`` (buffered): the environment records each step in memory and automatically flushes the complete episode to disk when the episode finishes (or when you call :meth:`citylearn.citylearn.CityLearnEnv.render`). This produces the same per-timestep CSVs as the ``'during'`` mode but defers file I/O until the end.
26
-
* ``render_mode='none'`` with explicit export: keep rendering off for faster runs and call :meth:`citylearn.citylearn.CityLearnEnv.export_final_kpis` (or a custom exporter) at the end. This lazily creates the render folder and only writes KPI summaries—suitable for the UI **KPIs page** but not for the time-series dashboards.
23
+
* ``render_mode='none'`` (default): no CSVs are produced. Use this for fast headless runs where you do not need UI data, or call :meth:`citylearn.citylearn.CityLearnEnv.export_final_kpis` manually afterwards to obtain the KPI table only.
24
+
* ``render_mode='during'``: the environment writes a row for every simulation step directly to disk (``<project>/SimulationData/<timestamp>`` by default). Final KPIs are appended automatically once the episode ends—no extra script code is required.
25
+
* ``render_mode='end'``: per-step rows are buffered in memory and flushed to disk when the episode finishes (or whenever :meth:`~citylearn.citylearn.CityLearnEnv.render` is invoked). As with ``'during'``, the KPI export is triggered automatically at the end of the episode.
26
+
27
+
You can customise the export location with ``render_directory``, ``render_directory_name`` and/or ``render_session_name`` when constructing the environment. When a session name is provided the folder is reused across runs; otherwise a timestamped folder is created.
27
28
28
29
Per-Step Export Example
29
30
-----------------------
@@ -50,7 +51,7 @@ Per-Step Export Example
50
51
observations, reward, terminated, truncated, info = env.step(actions)
51
52
# CSV rows are appended at each step when render_mode='during'.
52
53
53
-
The code above writes per-step CSV files into ``outputs/ui_exports/<timestamp>/``. Omitting ``render_directory`` stores the results in ``SimulationData/<timestamp>/`` by default.
54
+
The code above writes per-step CSV files into ``outputs/ui_exports/<timestamp>/``. Omitting ``render_directory`` stores the results in ``SimulationData/<timestamp>/`` by default, and the episode summary KPIs are written automatically to ``exported_kpis.csv``.
54
55
55
56
Export-at-the-End Example
56
57
-------------------------
@@ -100,16 +101,7 @@ Buffered End-of-Run Export Example
100
101
actions = [env.action_space[0].sample()]
101
102
observations, reward, terminated, truncated, info = env.step(actions)
102
103
103
-
# Episode completion automatically flushes the buffered CSVs.
104
-
# Call env.render() mid-run if you need an interim snapshot.
105
-
class_Model:
106
-
pass
107
-
108
-
model = _Model()
109
-
model.env = env
110
-
env.export_final_kpis(model)
111
-
112
-
With ``render_mode='end'`` the per-step histories accumulate in memory while the episode runs. At episode completion the environment writes the full SimulationData folder (all timesteps plus components); you may still call :meth:`~citylearn.citylearn.CityLearnEnv.render` manually if you want to force a flush earlier than that.
104
+
With ``render_mode='end'`` the per-step histories accumulate in memory while the episode runs. At episode completion the environment writes the full SimulationData folder (all timesteps plus components) and the KPI summary; you may still call :meth:`~citylearn.citylearn.CityLearnEnv.render` manually if you want to force a flush earlier than that.
113
105
114
106
The UI consumes the directory produced by the ``'during'`` and ``'end'`` approaches. The system uses the :meth:`~citylearn.citylearn.CityLearnEnv.render` method to iterate over buildings, electric vehicles, batteries, chargers, pricing, etc., using their ``as_dict`` outputs to build CSV histories where each row corresponds to a time instant and columns include units. Timestamps are converted to calendar dates for display. You can disable step-wise exporting by keeping ``render_mode='none'`` and relying on the end-of-run exporter, but the resulting folder will only serve the KPI comparison page.
0 commit comments