Skip to main content

CityLearn

CityLearn is an open-source Farama Foundation Gymnasium environment for building energy coordination, demand response and multi-agent reinforcement learning. Version 3 integrates the extended simulator developed by the Soft-CPS Research Group, including EVs, normalized deferrable appliances, sub-hourly physics, entity observations, dataset-driven demand response, robustness events, dynamic topology, three-phase electrical service, community KPIs and performance work for large datasets.

Package name:

pip install citylearn

Python import path:

from citylearn.citylearn import CityLearnEnv

Default documentation is in English. Portuguese documentation is available under docs/pt.

Current source release: 3.0.0.

Start Here

Link Portuguese Use it for
Release history PT Version history, release owner, validation status and compatibility notes.
How to run simulations PT Installation, quickstarts, CLI, CityLearnEnv parameters, render/export and validation.
Schema reference PT Full schema contract: buildings, devices, PV modes, EVs, chargers, deferrables, topology and market.
Dataset reference PT Required files/columns, CSV/Parquet, 15s datasets and real-data conversion.
Observations reference PT Observation names, units, bundles, sentinels, entity tables and edges.
Actions reference PT Flat/entity actions, ranges and physical meaning.
Flat and entity interfaces PT Vector mode, entity-table mode and dynamic topology semantics.
KPIs reference PT evaluate(), evaluate_v2(), KPI units and KPI families.
Multi-community reference PT Orchestrating multiple synchronized communities and portfolio KPIs.
Robustness reference PT Dataset-driven observation, forecast, action and asset availability perturbations.
Data unit contract PT Formal contract for kWh/step, kW, prices, emissions and timesteps.
Simulator features PT Capability inventory, including less obvious features.
Developer guide PT Tests, audits, performance checks and internal architecture.
Publishing guide PT PyPI release workflow and local build checks.

Additional reference: KPI v2 naming tree.

Capability Snapshot

Area Supported
Time resolution Hourly and sub-hourly, including 15min, 5min, 1min and 15s fixtures.
Dataset formats CSV and Parquet with equivalent schema columns.
Real data Power data can be converted to kWh/step; PV supports absolute measured generation.
PV per_kw normalized profile mode and absolute measured-energy mode.
EVs Charger-centric schedules, connected/incoming EVs, SOC requirements and V2G-capable actions.
Deferrables Normalized cycle catalog plus sparse flexibility schedule.
Escalators Aggregate standby/slow/normal control with passenger-service signals and KPIs.
Interfaces Flat Gymnasium vectors and entity tables/edges for offline RL, GraphRL and Transformers.
Entity RL observations Forecast bundles, physical deadline pressure, feasible action capacity and requested/limited/applied action feedback.
Dynamic topology Add/remove buildings and assets during simulation in entity mode, with clean structural replay after each episode reset.
Demand response Dataset-driven DSO/TSO flexibility requests in entity observations, with settlement and KPIs.
Multi-community Synchronized orchestration of multiple independent communities with portfolio KPI rows.
Robustness Optional dataset-driven observation, forecast, action-channel and logical asset outages with KPIs.
Three phase Phase connections, headroom, phase power, violations and phase KPIs.
Community market Local settlement, import weights, savings and self-consumption KPIs.
Performance Windowed loading, shared weather/pricing/carbon cache, runtime profiling and Parquet for large 15s datasets.
Validation Unit tests, golden KPI tests, physics audit and strict entity contract audit.

Quickstart

import numpy as np
from citylearn.citylearn import CityLearnEnv

env = CityLearnEnv(
    "data/datasets/citylearn_challenge_2022_phase_all_plus_evs/schema.json",
    interface="flat",
    episode_time_steps=24,
    render_mode="none",
)

observations, info = env.reset()
terminated = truncated = False

while not (terminated or truncated):
    actions = [np.zeros(space.shape, dtype="float32") for space in env.action_space]
    observations, reward, terminated, truncated, info = env.step(actions)

kpis = env.evaluate_v2()

Entity interface:

from citylearn.citylearn import CityLearnEnv

env = CityLearnEnv(
    "data/datasets/citylearn_three_phase_dynamic_topology_demo/schema.json",
    interface="entity",
    topology_mode="dynamic",
)

observations, info = env.reset()
specs = env.entity_specs

Compact 15s parquet dataset with dynamic asset changes:

env = CityLearnEnv(
    "data/datasets/citylearn_three_phase_dynamic_asset_changes_demo_15s_parquet/schema.json",
    interface="entity",
    topology_mode="dynamic",
)

Demand response dataset:

env = CityLearnEnv(
    "data/datasets/citylearn_challenge_2022_phase_all_demand_response/schema.json",
    interface="entity",
)

Robustness dataset:

env = CityLearnEnv(
    "data/datasets/citylearn_challenge_2022_phase_all_robustness/schema.json",
    interface="entity",
)

Multi-community portfolio:

from citylearn.multi_community import MultiCommunityEnv

env = MultiCommunityEnv(
    communities=[
        {
            "community_id": "community_a",
            "schema": "data/datasets/community_a/schema.json",
            "env_kwargs": {"interface": "entity", "episode_time_steps": 48},
            "weight": 1.0,
        },
        {
            "community_id": "community_b",
            "schema": "data/datasets/community_b/schema.json",
            "env_kwargs": {"interface": "entity", "episode_time_steps": 48},
            "weight": 1.0,
        },
    ],
)

Unit Contract

Quantity Unit
Dataset energy columns kWh/step
PV generation_mode="absolute" kWh/step
PV generation_mode="per_kw" W/kW profile multiplied by installed power
Power limits and ratings kW
Prices currency/kWh
Carbon intensity kgCO2/kWh
Deferrable cycle load_profile kWh/step

Real power data conversion:

kWh_per_step = kW * seconds_per_time_step / 3600

Validation

Recommended pre-release checks:

.venv/bin/pytest -q
.venv/bin/python scripts/audit/audit_entity_contract.py --strict
.venv/bin/python scripts/audit/audit_physics.py

See Developer guide for lint, smoke simulations, benchmarks and architecture notes.

Documentation and UI

The CityLearn documentation covers the base concepts, examples and Version 3 extensions: official docs.

CityLearn UI is a visual dashboard for inspecting simulation data and KPIs:

Resource Link
Hosted web app https://citylearnui.netlify.app/
Open-source UI https://github.com/Soft-CPS-Research-Group/citylearn-ui

The KPI export consumed by the UI is generated from evaluate_v2() by default, while evaluate() remains available for legacy workflows.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

citylearn-3.0.0.tar.gz (593.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

citylearn-3.0.0-py3-none-any.whl (549.6 kB view details)

Uploaded Python 3

File details

Details for the file citylearn-3.0.0.tar.gz.

File metadata

  • Download URL: citylearn-3.0.0.tar.gz
  • Upload date:
  • Size: 593.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for citylearn-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c8532ba18ac107af8648e405aecf16814c478ee7f2a46f7147a38ca23b10af4e
MD5 2abeba5bcfdf3185ca38f4d149151210
BLAKE2b-256 3614e126449642b39f5834940dba26e0b436b4bf087100eb2ba81190aeec8948

See more details on using hashes here.

File details

Details for the file citylearn-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: citylearn-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 549.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for citylearn-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1da8716b51120e69043c32670ba8f05641a29357834408db2a4c926510a1373c
MD5 b0bb5b549a49136111cd1b7cb1ad4be1
BLAKE2b-256 fbd4e28c4ec4bf9cdf5883853b855639bbbce5e09872c15437ce0eae652f08c2

See more details on using hashes here.

Release history Release notifications | RSS feed

3.0.2

2 files

3.0.1

2 files

This release

3.0.0 This release

2 files

2.5.0

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.0

2 files

1.8.0

2 files

1.7.0

2 files

1.6.0

2 files

1.5.0

2 files

1.4.4

2 files

1.4.3

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.6

2 files

1.3.5

2 files

1.3.4

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page