Skip to main content

UNsim: Differentiable network traffic simulation in Python

Project description

UNsim: Differentiable network traffic simulation in Python

PyPi arXiv

Main Features

  • Simple, lightweight, and easy-to-use Python implementation of modern standard models of dynamic network traffic flow for Python

  • Based on Link Transmission Model and Dynamic User Optimum route choice model

  • The features and syntax are almost identical to UXsim traffic flow simulator

  • An end-to-end differentiable simulation using JAX

  • Lightning-fast JAX mode on a good GPU server: 0.3 sec forward simulation for Chicago-Sketch dataset (2500 links, 1 million vehicles, 3 hours), and 0.5 sec for backward differentiation

  • Still an early development stage. There may be still bugs and inconsistency. The performance need to be optimized (especially the memory consumption). Documents will be added. The code and API will be significantly changed in the future.

  • Academic publication. This is the official implementation of arXiv preprint ``End-to-end differentiable network traffic simulation with dynamic route choice'' by Toru Seo.

Simulation Examples

Simple demonstration will be added. See examples/ for now.

Usage

from unsim import World

W = World(name="", deltat=5, tmax=1200, print_mode=1, save_mode=1)

W.addNode("orig1", 0, 0)
W.addNode("orig2", 0, 2)
W.addNode("merge", 1, 1)
W.addNode("dest", 2, 1)
link1 = W.addLink("link1", "orig1", "merge", length=1000, free_flow_speed=20, jam_density=0.2, merge_priority=1)
link2 = W.addLink("link2", "orig2", "merge", length=1000, free_flow_speed=20, jam_density=0.2, merge_priority=1)
link3 = W.addLink("link3", "merge", "dest", length=1000, free_flow_speed=20, jam_density=0.2)
W.adddemand("orig1", "dest", 0, 1000, 0.45)
W.adddemand("orig2", "dest", 400, 1000, 0.6)

W.exec_simulation()

W.analyzer.print_simple_stats()

W.analyzer.time_space_diagram(mode="k_norm", links="link1", vmax=1)
W.analyzer.time_space_diagram(mode="k_norm", links="link2", vmax=1)
W.analyzer.time_space_diagram(mode="k_norm", links="link3", vmax=1)

To be extended.

Install

pip install unsim

If you want to use acceleration using JAX, install your preferred JAX by doing something like

pip install jax[cpu]
pip install jax[cuda13]

The optimal installation depends on your hardware and software configuration, so please check the details by yourself.

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:

@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


Download files

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

Source Distribution

unsim-0.9.0.tar.gz (62.1 kB view details)

Uploaded Source

Built Distribution

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

unsim-0.9.0-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file unsim-0.9.0.tar.gz.

File metadata

  • Download URL: unsim-0.9.0.tar.gz
  • Upload date:
  • Size: 62.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for unsim-0.9.0.tar.gz
Algorithm Hash digest
SHA256 8a8c0e121d0f43e191e28117cfd4f5cd36ce4060853caa16f290dd7c521a4bb6
MD5 2b76fb7aedcd92b8d1541bac0d6d3560
BLAKE2b-256 976ef0250a291cc01dd3c8553ad834e9bb748285fc1979341207e1d528cf1a62

See more details on using hashes here.

File details

Details for the file unsim-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: unsim-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for unsim-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d83d3a0646755133bb985de28619e2ce54066ac9f64f7785c6889b4cf70be110
MD5 775cfa38bf65075011d833ac5023a8d9
BLAKE2b-256 413ef93ca0f5c5fe2c3189f44e230a32ef3a5cd7d35584941da3fcc75c05440e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page