openmobisim tutorials · 00 · overview · ← 04 · Bikes, walking, transit and the choice of mode · 06 · Parameters and experiments → · documentation

05 · Results and figures#

Everything a run leaves behind: the answers on the Run object, the files in its folder (Parquet and JSON, readable by any tool), and the figures openmobisim.viz draws from them. One run on a grid serves the whole notebook.

Download this notebook or all ten (a zip), without their outputs. The Installation section below installs openmobisim; its last command, openmobisim notebooks, copies the same ten into a folder and opens the first in JupyterLab.


Installation#

Skip this if import openmobisim already works in this notebook. One install is all there is: pip install "openmobisim[all]" brings the simulator and everything the ten tutorials use (JupyterLab, matplotlib for the figures, pandas, polars and pyarrow for the tables); nothing is installed later. Find the case that matches yours and copy its commands, in order. Each needs Python 3.11 or newer.

A new conda environment (any system; openmobisim is on PyPI, so pip installs it into the environment):

conda create -y -n openmobisim python=3.12
conda activate openmobisim
pip install "openmobisim[all]"
openmobisim notebooks

A new venv on macOS or Linux (in a terminal):

python3 -m venv openmobisim
source openmobisim/bin/activate
pip install "openmobisim[all]"
openmobisim notebooks

A new venv on Windows (in the Command Prompt):

py -m venv openmobisim
openmobisim\Scripts\activate
pip install "openmobisim[all]"
openmobisim notebooks

The last line copies these ten notebooks into ./openmobisim-notebooks and opens them in JupyterLab. In VS Code or PyCharm, open a notebook and choose the openmobisim environment’s Python as its kernel instead.

Into the environment this notebook already runs in: paste this into a new code cell, run it, then restart the kernel.

%pip install "openmobisim[all]"

import json
import os

import pandas as pd
import polars as pl

import openmobisim as ms
from openmobisim import viz

net = ms.examples.manhattan_grid(n=6, block_metres=250.0, signals=True)
trips = ms.examples.trips_random(net, 20000, seed=2, spread_s=3600, min_m=500, max_m=2000)
run = ms.Scenario.from_parts(
    net, trips, classes={"commuter": (True, False, False)}, link_bin_s=900
).run("results", output_dir="runs/results")
Run 'results': 0.5 s, window 00:00–03:00, 20,000 of 20,000 trips completed, mean trip 2.6 min, verdict good (run.timings() has every stage)

1 · The files#

File

What is in it

kpis.parquet

the indicators, one row per (iteration, mode, metric)

trip_results.parquet

every trip: who, from where to where, when, by which mode, what became of it

events.parquet

a sample of what happened to the trips (completed, truncated) and when, one in a hundred

link_bins.parquet

each link’s traffic and mean time in each time bin (with link_bin_s)

diagnostics.parquet

counters of anything unusual, one row per kind and place

manifest.json

every input, setting and default, the versions and the fingerprint

timings.csv

where the run’s time went, by stage, on this machine’s clock

Each is a plain file: read it with pandas, polars, pyarrow, R or a spreadsheet, without openmobisim.

folder = "runs/results"
for name in sorted(os.listdir(folder)):
    print(f"{name:22s} {os.path.getsize(os.path.join(folder, name)):>9,d} bytes")
diagnostics.parquet          894 bytes
events.parquet             3,591 bytes
kpis.parquet               3,193 bytes
link_bins.parquet         13,692 bytes
manifest.json              1,765 bytes
timings.csv                  954 bytes
trip_results.parquet     387,955 bytes

2 · Indicators#

kpis.parquet is in long format. The last iteration’s run-wide indicators:

kpis = pl.read_parquet(f"{folder}/kpis.parquet")
last = kpis.filter((pl.col("iteration") == kpis["iteration"].max()) & (pl.col("mode") == "all"))
last.select("metric", "value")
shape: (22, 2)
metricvalue
strf64
"total_travel_time_s"3.081894e6
"completed_trips"20000.0
"truncated_trips"0.0
"completed_people"20000.0
"reselected_share"0.1635
……
"people"20000.0
"no_vehicle_available_trips"0.0
"no_feasible_path_trips"0.0
"mode_not_available_trips"0.0
"completion_rate"1.0

The same table through the Run (run.kpis().to_pandas() or .to_polars()), pivoted to one row per iteration:

k = run.kpis().to_pandas()
k[k["mode"] == "all"].pivot(index="iteration", columns="metric", values="value")[
    ["completed_trips", "total_travel_time_s", "gap", "gap_excess", "changed_share"]
].round(4)
metric completed_trips total_travel_time_s gap gap_excess changed_share
iteration
0 20000.0 8069276.0 1.4837 1.4628 NaN
1 20000.0 9738350.0 2.6961 2.6705 0.3539
2 20000.0 3442422.0 0.2455 0.1794 0.1826
3 20000.0 3182288.0 0.1126 0.0300 0.1136
4 20000.0 3094576.0 0.1044 0.0215 0.0974
5 20000.0 3081894.0 0.1013 0.0166 0.0789

3 · Every trip#

run.trip_results() has one row per trip, also in the folder as trip_results.parquet: who travelled, from where to where, when, by which mode, what became of the trip, and, if it completed, when it arrived and how long it took. For a car still on the roads when the window ended, link_at_end is the link it was on. Filtering on outcome finds the trips that did not finish.

t = run.trip_results().to_pandas()
print(t["outcome"].value_counts().to_string())
t[t["outcome"] != "completed"].head()
outcome
completed    20000
trip traveller_id trip_seq user_class weight origin_lon origin_lat destination_lon destination_lat departure_s mode mode_choice outcome arrival_s travel_time_s link_at_end

5 · The manifest and reproducibility#

The manifest records what went in. Together with the package version, the fingerprint identifies the run: the same fingerprint on the same version gives the same results.

manifest = run.manifest()
keys = ["openmobisim_version", "defaults_version", "platform", "run_fingerprint", "network_fingerprint", "flow_level",
        "route_method", "choice_descriptor", "equilibration_descriptor", "iterations_run", "converged"]
print(json.dumps({k: manifest[k] for k in keys}, indent=1))
{
 "openmobisim_version": "0.1.0",
 "defaults_version": 31,
 "platform": "aarch64-apple-darwin",
 "run_fingerprint": "ca49acea94b59540",
 "network_fingerprint": "dfa893b06adf093b",
 "flow_level": 2,
 "route_method": "shortest",
 "choice_descriptor": "logit;beta_bike_mixed_km=-0.16;beta_cost_eur=-1.2;beta_ln_path_size=1;beta_time_min=-0.2;beta_transfers=-1;beta_wait_min=-0.09;beta_walk_min=-0.13",
 "equilibration_descriptor": "msa;cost_bin_s=300;gap_sample=300;gap_tolerance=0.05;increments=5;itinerary_gap_sample=100000000;iterations=10;route_growth_tolerance=1;warmup=1",
 "iterations_run": 6,
 "converged": true
}

6 · Where the time went#

Every run says in one line how long it took (unless quiet=True; the logger openmobisim at DEBUG adds the table) and keeps its wall-clock time by stage in Run.timings() and timings.csv.

t = run.timings().to_pandas()
t[t["iteration"].isna()][["stage", "seconds"]].round(3)
stage seconds
0 demand_read 0.012
1 setup 0.002
2 static_routes 0.007
3 itineraries_setup 0.000
4 route_sets 0.001
37 results_assembled 0.000
38 results_written 0.013
39 total 0.477

7 · Figures#

The figures share one look: a flow map (map_link), the demand (map_demand, chart_demand_matrix), a pair’s route set (map_route), mode shares (chart_mode_share, notebook 04), transit and parkings (map_transit, map_parking), an interactive page (map_interactive) and a one-page summary of a run (summary). Each takes theme="paper" (the default) or "night", a size in centimetres (size_cm) and a path to save to (PNG, PDF or SVG by the extension).

viz.map_link(run, title="Flows on a 6 x 6 grid")
../_images/cd3f41aaa41c6eae266a4ed3a64d29ad2467cf1f74a0a44cee23a01929cea9de.png
viz.map_link(run, theme="night", bins=4, title="The same, in the hour's second quarter")
../_images/9f99a61f67a82193cde3333d71781f4bd852986600f69847bc179cf4355b6d45.png
viz.map_demand(trips, network=net, title="Where the trips start and end")
../_images/b7f2228e9e540807bbbc6cc8b5439df2511b5d8c74048b5a3f99de4d8064cb0d.png
viz.map_route(run.route_sets(), net, 0, title="The routes of one origin-destination pair")
../_images/cb868182a5d5e0c386fd5016feb30e347bec4d611f66cfa4f1e4c95d3f7b5b38.png

Interactive and summary pages. map_interactive writes one self-contained HTML file to open in a browser: pan and zoom, step through the time bins, click a link for its numbers, show a pair’s routes. summary writes a one-page report of a run: headline numbers, the flow map, the modes, the convergence and where the time went.

page = viz.map_interactive(run, "runs/results/interactive.html", title="A 6 x 6 grid")
report = viz.summary(run, note="A synthetic hour on a 6 x 6 grid")
print(page, report, sep="\n")

Interactive map: runs/results/interactive.html — file:///private/var/folders/q0/vjghqqvj4dvcq_z2rjmvd0jmw3f5y2/T/tmpryrzjgrs/runs/results/interactive.html

Summary page: runs/results/summary.html — file:///private/var/folders/q0/vjghqqvj4dvcq_z2rjmvd0jmw3f5y2/T/tmpryrzjgrs/runs/results/summary.html

runs/results/interactive.html
runs/results/summary.html

Saving. path= saves a figure as it is drawn, at its size and dpi:

viz.map_link(run, title="Flows on a 6 x 6 grid", size_cm=(17.0, 10.0), dpi=300, path="runs/results/flows.pdf")
print(os.path.getsize("runs/results/flows.pdf"), "bytes")
54502 bytes

Next: 06 · Parameters and experiments: every default by name, seeds and replications, samples, sweeps; a city’s mode shares moved. The whole series: 00 · overview. The documentation: openmobisim.github.io. Something wrong or unclear? Report it.