Skip to main content

Models of the TfL transit network

Project description

Tubeulator Models

Graph neural network models of the London Underground trained on TfL timetable data.

Two models share a GATv2 encoder over the station topology graph and differ in their decoder head:

  • nexthop policy — given a current station and destination, predicts the optimal next station to visit. Greedy rollout achieves 1.09× Dijkstra ratio with 100% success across all 239,610 origin–destination pairs.
  • nexthop value — predicts shortest travel time in minutes between any pair of stations. MAE of ~0.5 min vs. Floyd–Warshall ground truth.

Installation

pip install tubeulator-models[inference]

For the CLI:

pip install tubeulator-models[cli]

Usage

Python API

from tubeulator_models import TubeRouter

router = TubeRouter.from_pretrained("permutans/tube-nexthop-policy")
route = router.route("West Ham", "Shoreditch")
print(route)
# West Ham
#   → [district] Bromley-by-Bow (2.0m)
#   ...
# ✓ 8 hops · 2 lines · 1 transfer · 16.0 min

Route through waypoints:

route = router.route("Camden Town", "Canary Wharf", via=["King's Cross"])

The Route object has .steps, .total_minutes, .lines_used, .n_transfers, .success, and a .to_dict() method.

CLI

tm-infer policy --model permutans/tube-nexthop-policy -o "West Ham" -d Shoreditch
tm-infer policy --model permutans/tube-nexthop-policy -o "Camden Town" -d "Canary Wharf" -v "King's Cross"
tm-infer value  --model permutans/tube-nexthop-value  -o "West Ham" -d Shoreditch

Training from source

Clone the repo and use the justfile recipes:

just all        # fetch data + build graph + train

Or step by step:

just fetch      # pull timetables from TfL API → GTFS zip
just graph      # GTFS → GeoParquet → PyG graph objects
just train nexthop full
just train nexthop full --value-primary --batch-size 1024 --epochs 200

All hyperparameters live in defaults.toml. CLI flags override the TOML but never replace it:

tm-train --model nexthop --profile full --lr 5e-5

Profiles control the training regime:

Profile Epochs Batch size LR Notes
dev 20 512 5e-4 Fast iteration
full 200 256 1e-4 Production, d_model=512, 16-layer encoder

Data pipeline

Step CLI Recipe Output
Fetch timetables tm-build-gtfs just fetch data/tfl_station_data_gtfs.zip
Build graph tm-gtfs2pyg just graph data/graph/, data/pyg/
Plot network tm-plot just plot data/graph/network.png
Train tm-train just train checkpoints/
Export tm-export just upload models/ → HuggingFace

Staged graph conversion is also available:

uv run --group prep    tm-gtfs2graph   # GTFS → GeoParquet
uv run --group pyg     tm-graph2pyg    # GeoParquet → PyG .pt

Configuration

defaults.toml is the single source of truth for all tuneable values. The merge order is:

[base] → [model.<type>] → [profiles.<name>] → [profiles.<name>.model.<type>] → CLI overrides

Development

just lint       # ruff check
just clean      # remove data/ and checkpoints/

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

tubeulator_models-0.1.1.tar.gz (58.3 kB view details)

Uploaded Source

Built Distribution

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

tubeulator_models-0.1.1-py3-none-any.whl (71.2 kB view details)

Uploaded Python 3

File details

Details for the file tubeulator_models-0.1.1.tar.gz.

File metadata

  • Download URL: tubeulator_models-0.1.1.tar.gz
  • Upload date:
  • Size: 58.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22","id":"wilma","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tubeulator_models-0.1.1.tar.gz
Algorithm Hash digest
SHA256 61d5abd0db22ff0794b8af0b676453eabdf517583472a5ab38771301c7b10a94
MD5 dc7e36ce6512ed7d94ea26bac69fbadd
BLAKE2b-256 5145721f7a6bf67e24c29cd8cf9a7b41cb2cef8982dfb10eb707dcea6973f130

See more details on using hashes here.

File details

Details for the file tubeulator_models-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tubeulator_models-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 71.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22","id":"wilma","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tubeulator_models-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 127018909b4582382e286e04a5d40e82ec42a3e3fb91f900b8782db6017c43da
MD5 3285d93dcfb4e148c9cf73a9f1dafa09
BLAKE2b-256 6a47777ef05dd2d6e34b469b7000b9882b1a63b5ea3216f99e051aa11f4a81d8

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