UNsim: Differentiable network traffic simulation in Python
Project description
UNsim: Differentiable network traffic simulation in Python
[!IMPORTANT] Early development stage. There may be bugs and inconsistencies. The performance needs to be optimized (especially the memory consumption). Documentation should be added. This is more like a research prototype than a library. The code and API will change significantly in the future.
Main Features
- Simple, lightweight, and easy-to-use Python implementation of modern standard models of dynamic network traffic flow
- An end-to-end differentiable simulation using JAX
- Lightning-fast JAX mode on a good GPU server: 0.3 sec for forward simulation on the Chicago-Sketch dataset (2500 links, 1 million vehicles, 3 hours), and 0.5 sec for backward differentiation
- The features and syntax are almost identical to those of the UXsim traffic flow simulator
Simulation Examples
60000 vehicles travel through a 10 km grid network over 3 hours. Dark colors indicate congestion (slow speeds). The simulation wall-clock time was 5 seconds on a 2.0 GHz CPU in pure Python mode.
Usage
Simple scenario in a Y-shaped merge network:
from unsim import World
import matplotlib.pyplot as plt
# Define the main simulation
# Units are standardized to seconds (s) and meters (m)
W = World(name="merge", deltat=5, tmax=1200,
print_mode=1, save_mode=1, show_mode=1)
# Define the network
W.addNode("orig1", x=0, y=0)
W.addNode("orig2", x=0, y=2)
W.addNode("merge", x=1, y=1)
W.addNode("dest", x=2, y=1)
W.addLink("link1", "orig1", "merge", length=1000, free_flow_speed=20, capacity=0.8, merge_priority=1)
W.addLink("link2", "orig2", "merge", length=1000, free_flow_speed=20, capacity=0.8, merge_priority=1)
W.addLink("link3", "merge", "dest", length=1000, free_flow_speed=20)
# Define the vehicle demand
W.adddemand("orig1", "dest", t_start=0, t_end=1000, flow=0.45)
W.adddemand("orig2", "dest", t_start=400, t_end=1000, flow=0.6)
# Run the simulation
W.exec_simulation()
# Analysis
W.analyzer.print_simple_stats()
W.analyzer.network(t=200)
W.analyzer.network(t=800)
plt.show()
Results:
Simulation completed. merge
Simulation Results:
Total trips: 810.0
Completed trips: 740.0
Total travel time: 136825.0 s
Avg travel time: 184.9 s
Avg delay: 84.9 s
Install
pip install unsim
If you want to use JAX acceleration, install your preferred JAX build such as jax[cpu] and jax[cuda13].
The optimal installation depends on your hardware and software configuration, so please check the JAX official document.
Technical Note
This simulator implements the following transportation scientific models:
- Link Transmission Model: very efficient and accurate macroscopic traffic flow model
- Incremental Node Model: general intersection or junction model
- Dynamic User Optimum: route choice model in which each traveler chooses the real-time minimum travel time path
For the details, please see arXiv preprint.
Terms of Use & License
UNsim is released under the MIT License. You are free to use it as long as the source is acknowledged.
If you use the code, please cite the arXiv article:
- Toru Seo. End-to-end differentiable network traffic simulation with dynamic route choice. arXiv preprint arXiv:2604.11380, 2026.
@Article{seo2026unsim_arxiv,
author = {Toru Seo},
journal = {arXiv preprint arXiv: 2604.11380},
title = {End-to-end differentiable network traffic simulation with dynamic route choice},
year = {2026},
doi = {10.48550/arXiv.2604.11380},
}
Related Links
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 unsim-0.11.0.tar.gz.
File metadata
- Download URL: unsim-0.11.0.tar.gz
- Upload date:
- Size: 69.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e762a3bf60fadf9d68053efa31e92f08112739893fdc2ceeecc9951ed174bfed
|
|
| MD5 |
150959c267193fe677e110e2b1086b4a
|
|
| BLAKE2b-256 |
9f31ef886963d029cf4f517c6d8879f4ef15fdd90b6734c15268820a8bfdfe3d
|
File details
Details for the file unsim-0.11.0-py3-none-any.whl.
File metadata
- Download URL: unsim-0.11.0-py3-none-any.whl
- Upload date:
- Size: 48.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfdc63244d85f8930de59fe563340d6d224c18463335374496e16088f4d7d874
|
|
| MD5 |
8eeb25757884d85588b573866d58fd7a
|
|
| BLAKE2b-256 |
22a88c22278188dd45b17fdd52b2c1808de43622223753c310aabf85f250e36a
|