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.4.tar.gz (59.0 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.4-py3-none-any.whl (72.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tubeulator_models-0.1.4.tar.gz
  • Upload date:
  • Size: 59.0 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.4.tar.gz
Algorithm Hash digest
SHA256 88ebf469fa45519c33fe55f5f8bd5e81b6d65709b60acf79aa0776073b10e6dd
MD5 111a042244fdcadb7daac100dfa7d9bd
BLAKE2b-256 6d69d3e949248cfd6736c7f22eeb57076ab3f5497503e7c39a6d18c4d581ee3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tubeulator_models-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 72.1 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 00f6d0054d025a23c616ac6c11f1cfea2804ea26c1066493e2effa5e13c49b54
MD5 a7d0b952021a3139b76b8d54df1563d4
BLAKE2b-256 2f70c8b22abb8980ea0d21e18b3b5850e1494bdebbee0878a5416aea441c91fe

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