Skip to main content

UXsim Logo

UNsim: Python/JAX traffic simulator with AutoDiff

PyPi arXiv Jupyter docs

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 mode with a GPU: 0.3 sec for forward simulation on the Chicago-Sketch dataset (2500 links, 1 million vehicles, 3 hours), and 1.5 sec for backward differentiation, with 2GB VRAM (on RTX 5060 Ti).
  • The basic features and syntax are almost identical to those of the UXsim traffic flow simulator

Simulation Examples

Simple Simulation

grid11x11_anim_linkbased_3hours_11km_60000vehs_5sec_by_2GHz_cpu

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.

Autodiff-based large-scale optimization

toll_network_avg_tolled toll_ad_vs_spsa_convergence

One million vehicles travel through the Chicago network (approximately 2500 links) over a 3-hour period. The simulation time for a single run was 0.2 seconds using a GPU.

Additionally, we solve a dynamic congestion pricing optimization problem on this network. The number of decision variables is 15000, corresponding to the number of links and tolling periods. This problem is very difficult to solve using conventional approaches (e.g., SPSA in the figure above), but our simulator quickly produced a high-quality solution (AD in the figure).

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

network_t200 network_t800

For further usage including Autodiff, please see the Jupyter notebook tutorial and example scripts.

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:

For the details, please see the arXiv preprint.

Terms of Use & License

UNsim is released under the Apache License 2.0. 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},
}

Metadata

Release files for unsim 0.16.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unsim 0.16.0
File Size Uploaded Provenance Actions
unsim-0.16.0.tar.gz 116.3 kB Without provenance Details for unsim-0.16.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for unsim 0.16.0
File Interpreter ABI Platform Actions
unsim-0.16.0-py3-none-any.whl Python 3 none any Details for unsim-0.16.0-py3-none-any.whl

Total release size: 191.0 kB

Release files / unsim-0.16.0.tar.gz

Download URL unsim-0.16.0.tar.gz
Size 116.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e7716e96fa145290c3fa404fe661d966baaf5b7c3deaec2fb252860066b4f153
BLAKE2b-256 checksum
How to use checksums
fee999370a710ef6cd98135f7559b1067c715daed2bac7a90b1e30506a9073d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / unsim-0.16.0-py3-none-any.whl

Download URL unsim-0.16.0-py3-none-any.whl
Size 74.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b871d02d827c78fab67fafdbd2dfd579cd299315d86bf8192b77419216d37f00
BLAKE2b-256 checksum
How to use checksums
6986bf9bc4542520e790e1362d11942f18eea7b2e33718839f115c1a9a7820c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for unsim 0.16.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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