Twin4Build

Dynamic simulation of buildings with differentiable data-driven models and integration with semantic models for developing Digital Twins for buildings.
https://github.com/jbjoernskov/twin4build

Category: Energy Systems
Sub Category: Building Energy Monitoring

Keywords

building-energy-model building-simulation data-driven digital-twin ontology

Last synced: about 20 hours ago
JSON representation

Repository metadata

Dynamic simulation of buildings with differentiable data-driven models and integration with semantic models.

README.md

docs

twin4build: A python package for Data-driven and Ontology-based modeling and simulation of buildings

Dynamic modeling and simulation of buildings, featuring fully differentiable models for parameter estimation and optimal control. Supports integration of semantic models for automatic model generation and fast implementation.

Core Classes and Functionality

Twin4Build provides several top-level classes for building, simulating, translating, calibrating, and optimizing building energy models:

  • Model:
    The main container for your building system, components, and their connections. Use this class to assemble your digital twin from reusable components.

  • Simulator:
    Runs time-based simulations of your Model, producing time series outputs for all components. Handles the simulation loop and time stepping.

  • Translator:
    Automatically generates a Model from a semantic model (ontology-based building description) and maintains a link between these. Enables ontology-driven, automated model creation.

  • Estimator:
    Performs parameter estimation (calibration) for your Model using measured data. Supports both least-squares and PyTorch-based optimization.

  • Optimizer:
    Optimizes building operation by adjusting setpoints or control variables to minimize objectives or satisfy constraints, using gradient-based methods.

All classes are accessible via the main package import:

import twin4build as tb

A typical workflow would look like this:

Examples and Tutorials

Below are some examples of how to use the package.
More examples are coming soon.

Basics of Twin4Build

Translator

Estimator

Optimizer

Documentation

The documentation can be found online.
Below is a code snippet showing the basic functionality of the package.

import twin4build as tb

# Create a model
model = tb.Model(id="example_model")

# Define components
damper = tb.DamperTorchSystem(id="damper")
space = tb.BuildingSpaceTorchSystem(id="space")

# Add connections to the model
model.add_connection(damper, space, 
                    "airFlowRate", "supplyAirFlowRate")

# Load the model
model.load()

# Create a simulator instance
simulator = tb.Simulator(model)

# Simulate the model
step_size = 600 #Seconds
start_time = datetime.datetime(year=2025, month=1, day=10, hour=0, minute=0, second=0) # Optionally set the timezone
end_time = datetime.datetime(year=2025, month=1, day=12, hour=0, minute=0, second=0) # Optionally set the timezone
simulator.simulate(step_size=step_size,
                   start_time=start_time,
                   end_time=end_time)

# Plot the results
plot.plot_component(simulator, 
                    components_1axis=[("Damper", "airFlowRate")],
                    components_2axis=[("Damper", "damperPosition")],
                    ylabel_1axis="Air flow rate", #Optional
                    ylabel_2axis="Damper position", #Optional
                    show=True,
                    nticks=11)

Installation

The package is installed with pip:

pip install twin4build

The following python versions are supported:

Python version Windows Ubuntu
3.9 windows-python3.9 ubuntu-python3.9
3.10 windows-python3.10 ubuntu-python3.10
3.11 windows-python3.11 ubuntu-python3.11
3.12 windows-python3.12 ubuntu-python3.12

Graphviz (recomended)

To utilize the graph-drawing capabilities of twin4build, the drawing engine Graphviz must be installed.
It can be installed by downloading the install-file from the official website or by using your favorite package manager:

Ubuntu

sudo add-apt-repository universe
sudo apt update
sudo apt install graphviz

Windows

On windows, the winget or choco package managers can be used:

winget install graphviz
choco install graphviz

MacOS

brew install graphviz

Publications

[1]
Bjørnskov, J. & Thomsen, A. & Jradi, M. (2025). Large-scale field demonstration of an interoperable and ontology-based energy modeling framework for building digital twins. Applied Energy, 387, [125597]

[2]
Bjørnskov, J. & Jradi, M. & Wetter, M. (2025). Automated Model Generation and Parameter Estimation of Building Energy Models Using an Ontology-Based Framework. Energy and Buildings 329, [115228]

[3]
Bjørnskov, J. & Jradi, M. (2023). An Ontology-Based Innovative Energy Modeling Framework for Scalable and Adaptable Building Digital Twins. Energy and Buildings, 292, [113146].

[4]
Bjørnskov, J., Badhwar, A., Singh, D., Sehgal, M., Åkesson, R., & Jradi, M. (2025). Development and demonstration of a digital twin platform leveraging ontologies and data-driven simulation models. Journal of Building Performance Simulation, 1–13.

[5]
Bjørnskov, J. & Jradi, M. (2023). Implementation and demonstration of an automated energy modeling framework for scalable and adaptable building digital twins based on the SAREF ontology. Building Simulation.

[6]
Andersen, A. H. & Bjørnskov, J. & Jradi, M. (2023). Adaptable and Scalable Energy Modeling of Ventilation Systems as Part of Building Digital Twins. In Proceedings of the 18th International IBPSA Building Simulation Conference: BS2023 International Building Performance Simulation Association.

Cite as

@article{OntologyBasedBuildingModelingFramework,
    title = {An ontology-based innovative energy modeling framework for scalable and adaptable building digital twins},
    journal = {Energy and Buildings},
    volume = {292},
    pages = {113146},
    year = {2023},
    issn = {0378-7788},
    doi = {https://doi.org/10.1016/j.enbuild.2023.113146},
    url = {https://www.sciencedirect.com/science/article/pii/S0378778823003766},
    author = {Jakob Bjørnskov and Muhyiddine Jradi},
    keywords = {Digital twin, Data-driven, Building energy model, Building simulation, Ontology, SAREF},
}

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 4 days ago

Total Commits: 1,162
Total Committers: 7
Avg Commits per committer: 166.0
Development Distribution Score (DDS): 0.158

Commits in past year: 104
Committers in past year: 2
Avg Commits per committer in past year: 52.0
Development Distribution Score (DDS) in past year: 0.01

Name Email Commits
Jakob Bjørnskov j****v@m****m 978
SebsCubs a****c@u****o 83
Avneet a****t@i****m 77
AugustMST a****0@s****k 9
Wiszniewski.Grzegorz GPI G****I@k****k 6
anshumannec a****i@i****m 5
Avneet 3****d 4

Committer domains:


Issue and Pull Request metadata

Last synced: 12 days ago

Total issues: 13
Total pull requests: 92
Average time to close issues: 5 months
Average time to close pull requests: 3 days
Total issue authors: 2
Total pull request authors: 5
Average comments per issue: 0.92
Average comments per pull request: 0.2
Merged pull request: 73
Bot issues: 0
Bot pull requests: 0

Past year issues: 4
Past year pull requests: 1
Past year average time to close issues: 2 months
Past year average time to close pull requests: 24 days
Past year issue authors: 2
Past year pull request authors: 1
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.0
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/jbjoernskov/twin4build

Top Issue Authors

  • JBjoernskov (10)
  • SebsCubs (3)

Top Pull Request Authors

  • avneet006 (45)
  • SebsCubs (33)
  • AugustMST (11)
  • gpikmddk (2)
  • JBjoernskov (1)

Top Issue Labels

  • enhancement (10)
  • documentation (1)
  • bug (1)

Top Pull Request Labels

  • enhancement (22)
  • bug (11)
  • documentation (3)
  • duplicate (1)

Package metadata

pypi.org: twin4build

Dynamic simulation of buildings and integration with semantic modeling.

  • Homepage:
  • Documentation: https://twin4build.readthedocs.io/
  • Licenses: MIT
  • Latest release: 1.1.2 (published 5 months ago)
  • Last Synced: 2026-04-03T20:01:26.214Z (4 days ago)
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 22 Last month
  • Rankings:
    • Dependent packages count: 8.725%
    • Average: 28.947%
    • Dependent repos count: 49.168%
  • Maintainers (1)

Dependencies

requirements_dev.txt pypi
  • FMPy ==0.3.16 development
  • OMPython ==3.4.0 development
  • Requests ==2.31.0 development
  • SQLAlchemy ==2.0.21 development
  • arviz ==0.12.1 development
  • bayesian_optimization ==1.4.3 development
  • corner ==2.2.2 development
  • emcee ==3.1.4 development
  • fastapi ==0.103.1 development
  • ipython ==8.15.0 development
  • keycloak ==3.1.3 development
  • matplotlib ==3.7.2 development
  • memory_profiler ==0.61.0 development
  • networkx ==3.1 development
  • numpy ==1.22.4 development
  • onnxruntime ==1.15.1 development
  • pandas ==2.0.3 development
  • ptemcee ==1.0.0 development
  • pwlf ==2.2.1 development
  • pydot ==1.4.2 development
  • pymc ==5.7.2 development
  • pymcmcstat ==1.9.1 development
  • pytensor ==2.14.2 development
  • pytz ==2023.3 development
  • scipy ==1.7.3 development
  • seaborn ==0.12.2 development
  • setuptools ==68.0.0 development
  • tqdm ==4.66.1 development
  • uvicorn ==0.23.2 development
setup.py pypi
  • fastapi *
  • fmpy *
  • matplotlib *
  • networkx *
  • onnx *
  • onnxruntime *
  • openpyxl *
  • pandas *
  • pwlf *
  • pydot *
  • pymc *
  • pytensor *
  • requests *
  • scipy *
  • seaborn *
  • torch *
  • tqdm *

Score: 8.448700194970938