Digital Twins: Data-Driven Dynamic Simulation - Companion package for building digital twins with data assimilation
Project description
Digital Twins: Data-Driven Dynamic Simulation
Overview
Digital Twins is a Python package providing state-of-the-art algorithms for building digital twins through data assimilation. It combines simulation models with real-world observations to create accurate, real-time representations of physical systems.
What is a Digital Twin?
A digital twin is a virtual representation of a physical system that updates in real-time using sensor data. This package provides the mathematical foundation and algorithms needed to:
- Simulate dynamic systems using continuous, discrete-time, and event-based models
- Assimilate real-world data to correct model predictions
- Estimate hidden states and parameters from noisy observations
- Visualize uncertainty and spatial distributions
Key Features
๐ฏ Data Assimilation Algorithms
- Kalman Filters: Standard, Extended (EKF), and Ensemble (EnKF) implementations
- Particle Filters: Bootstrap filter with systematic resampling for nonlinear/non-Gaussian systems
๐ฌ Simulation Models
- Continuous Models: ODE solvers (Euler, RK4) for systems like the Lorenz attractor
- Discrete-Time Models: Including cellular automata and difference equations
- DEVS Models: Discrete Event System Specification for event-driven simulations
๐ Visualization Tools
- Uncertainty visualization (confidence ellipses, particle clouds)
- Spatial distribution plots for grid-based simulations
- Real-time animation support via Jupyter widgets
Installation
From PyPI (Recommended)
pip install digital-twins
From Source
git clone https://github.com/bulentsoykan/digital-twins.git
cd digital-twins
pip install -e .
Development Installation
pip install -e .[dev] # Includes testing and development tools
Quick Start
Example 1: Kalman Filter for State Estimation
import numpy as np
from digital_twins import KalmanFilter
# Initialize with uncertain initial state
mu0 = np.array([0.0, 0.0]) # [position, velocity]
Sigma0 = np.eye(2) * 100 # High initial uncertainty
kf = KalmanFilter(mu0, Sigma0)
# System dynamics (constant velocity model)
dt = 1.0
A = np.array([[1.0, dt], [0.0, 1.0]]) # State transition
Q = np.eye(2) * 0.1 # Process noise
C = np.array([[1.0, 0.0]]) # Observe position only
R = np.array([[1.0]]) # Measurement noise
# Simulate one step
kf.predict(A, Q) # Predict next state
measurement = np.array([5.0]) # Receive sensor data
kf.update(measurement, C, R) # Correct with measurement
print(f"Estimated state: {kf.mu}")
print(f"Uncertainty: {kf.Sigma}")
Example 2: Particle Filter for Nonlinear Systems
from digital_twins import BootstrapParticleFilter
# Initialize 1000 particles
N_particles = 1000
initial_particles = np.random.randn(N_particles, 2) # Random initial distribution
pf = BootstrapParticleFilter(N_particles, initial_particles)
# Nonlinear dynamics
def f(x, u):
return np.array([x[0] + 0.1*np.sin(x[1]), x[1] + 0.1])
def g(x):
return x[0]**2 # Nonlinear measurement
# Run filter
pf.predict(f, process_noise_std=np.array([0.1, 0.1]))
pf.update(y_md=2.5, g_func=g, sensor_noise_std=0.5)
mean_state, std_state = pf.estimate_state()
print(f"Estimated state: {mean_state} ยฑ {std_state}")
Example 3: Continuous System Simulation
from digital_twins import ContinuousSimulator, LorenzSystem
# Create Lorenz attractor model
model = LorenzSystem(sigma=10.0, rho=28.0, beta=8.0/3.0)
simulator = ContinuousSimulator(model, method='rk4')
# Run simulation
initial_state = np.array([1.0, 1.0, 1.0])
t_history, x_history, y_history = simulator.simulate(
t_start=0.0,
t_end=50.0,
dt=0.01,
x0=initial_state
)
# x_history contains the chaotic trajectory
Interactive Notebooks
The package includes comprehensive Jupyter notebooks demonstrating:
- Continuous Systems: Lorenz attractor visualization
- Discrete-Time Models: Cellular automata patterns
- DEVS Models: Traffic light coordination
- Kalman Filters: Interactive gain visualization
- Particle Filters: Bootstrap filter basics
- Advanced Topics: Joint state-parameter estimation, spatial tracking
Running the Notebooks
# Install Jupyter if needed
pip install jupyter
# Navigate to notebooks directory
cd notebooks/
# Start Jupyter
jupyter notebook
Package Structure
digital-twins/
โโโ src/digital_twins/
โ โโโ assimilation/ # Data assimilation algorithms
โ โ โโโ kalman.py # Kalman filter variants
โ โ โโโ particle.py # Particle filters
โ โโโ models/ # Simulation models
โ โ โโโ continuous.py # ODE-based models
โ โ โโโ discrete_time.py # Difference equations
โ โ โโโ devs.py # Event-driven models
โ โโโ visualization/ # Plotting utilities
โโโ notebooks/ # Interactive tutorials
โโโ tests/ # Unit tests
โโโ data/ # Example datasets
Mathematical Background
This package implements algorithms from modern data assimilation theory:
- Kalman Filtering: Optimal state estimation for linear Gaussian systems
- Extended Kalman Filter: First-order linearization for nonlinear systems
- Ensemble Kalman Filter: Sample-based covariance estimation
- Particle Filtering: Sequential Monte Carlo for arbitrary distributions
The mathematical formulations follow standard texts in data assimilation and state estimation.
Use Cases
Digital twins built with this package can be applied to:
- ๐ Transportation: Traffic flow estimation and prediction
- ๐ฅ Wildfire Tracking: Real-time fire spread monitoring
- ๐ญ Manufacturing: Production line optimization
- ๐ Environmental Monitoring: Ocean/atmosphere modeling
- ๐ฆ Supply Chain: Inventory and logistics optimization
- ๐ค Robotics: Sensor fusion and SLAM
Contributing
We welcome contributions! Please see our GitHub repository for:
- Bug reports and feature requests
- Pull request guidelines
- Development setup instructions
Testing
Run the test suite:
pytest tests/
With coverage:
pytest tests/ --cov=digital_twins
Citation
If you use this package in your research, please cite:
@software{digital_twins,
author = {Soykan, Bulent},
title = {Digital Twins: Data-Driven Dynamic Simulation},
year = {2026},
url = {https://github.com/bulentsoykan/digital-twins}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Bulent Soykan
- Website: bulentsoykan.com
- GitHub: @bulentsoykan
- LinkedIn: Bulent Soykan
Acknowledgments
This package was developed as a companion to research in digital twin technology and data assimilation methods. Special thanks to the scientific computing and data assimilation communities for their foundational work.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file digital_twins_ddds-0.1.0.tar.gz.
File metadata
- Download URL: digital_twins_ddds-0.1.0.tar.gz
- Upload date:
- Size: 31.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4248627860f052a6d1e41a8d60b2306b2da8ee424188000fe01ce3ae6934f7f2
|
|
| MD5 |
0cee95338b92fc1ef733a00de6e820e0
|
|
| BLAKE2b-256 |
7b584314f6df904e4ea35704ec09a4302b13d8960bf3cf1ff67de8e1d1bd0d5e
|
File details
Details for the file digital_twins_ddds-0.1.0-py3-none-any.whl.
File metadata
- Download URL: digital_twins_ddds-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bacb240801257c5ebe4152597fdf1e9c68bf68a7893c65e178eac7cbff0e022a
|
|
| MD5 |
9f1df0c7010998d983adb3da77baa85f
|
|
| BLAKE2b-256 |
eeb4102d8e3911fe309af2d8196c54bf034b1a18675aeb2e1fedd6254452f793
|