Training Traffic Forecasters Through a Black-Box Traffic Simulator

Most traffic forecasters today are graph neural networks: models that pass information along the road network's sensor graph and read off future speeds or flows. They fit recurring rush-hour patterns well. They are weakest where forecasts matter most, after a crash, a lane closure, or a demand shift. There they smooth over the sudden queue, produce states no road can physically carry, and cannot answer "what if this lane closes?" Microscopic traffic simulators such as SUMO already encode the missing physics, including vehicle conservation, capacity, lane changes, merges and queue spillback. They are compiled programs full of discrete events, though, so no gradient flows through them, and nobody trains a forecaster through them.

We propose to make the simulator the output layer of the forecaster. A graph network reads recent sensor data and incident logs and predicts the simulator's inputs for the next hour: how many vehicles enter at each on-ramp, how much capacity each link loses to an incident, and how drivers on each segment behave. The unmodified simulator then produces the forecast. The network is trained end to end against observed sensor data. The gradient through the simulator is estimated without opening it, using random-direction finite differences whose noise is cancelled by a learned surrogate acting as a control variate (a correlated quantity with known mean, subtracted to reduce variance). The claim to test is narrow. Forecasts produced this way should be physically valid by construction, more accurate in incident windows, and transferable to corridors the model never saw, because the network predicts physical quantities rather than memorizing sensor identities.

Core Claim and What Is New

The closest work makes the physics differentiable by rewriting it. Differentiable Hybrid Traffic Simulation derives exact gradients for a continuum flow model coupled to car-following agents. Traffic-Aware Autonomous Driving with Differentiable Traffic Simulation does the same for the car-following model alone. Both explicitly leave out lane changes and merges, and neither is evaluated on real sensor networks. A second line borrows physics only as a structural prior inside the network: RA-BiGN uses the first-order Lighthill–Whitham–Richards wave equation to decide whether messages flow upstream or downstream, but no solver runs inside the model. A third line replaces the simulator with a neural copy: Lassen et al. train a graph network to imitate PTV Visum's static assignment, and its accuracy degrades as capacity perturbations approach 25%.

Our proposal differs from all three. The real simulator stays in the forward pass, with its discrete lateral dynamics intact. The surrogate never produces the forecast; it only reduces the variance of an estimated gradient. Real highway sensor benchmarks with incident logs supply the training signal. The gradient machinery comes from NI-GBMS, which wraps legacy C++/Fortran solvers this way but has only been applied to elliptic and parabolic equations such as Poisson and elasticity. It has never been tried on traffic, hyperbolic shock dynamics, or a forecasting objective.

Research Program

The model has three parts. The first is a graph network that predicts physical quantities for each road segment at each 5-minute interval of the horizon. Its inputs are recent detector speed, flow and occupancy, static road attributes (lanes, speed limit, ramp positions) and the incident log. Its outputs are boundary inflows, an incident capacity multiplier, and a small set of driver parameters (desired speed and time headway). It deliberately has no learnable per-sensor identity embeddings. G-SWaN shows that such embeddings effectively memorize location, with a linear probe recovering GPS coordinates at $R^2=0.996$. That memorization is what makes current models transductive, that is, unable to run on a new set of sensors without retraining.

The second part is SUMO, run on corridor networks built for selected freeway stretches. It is initialized from current detector densities and rolled forward 60 minutes under the predicted inputs. Its simulated detector readings are compared with observed future readings.

The third part is the gradient estimator. Let $\theta$ be the vector of simulator inputs the network emits, $L(\theta)$ the expected forecast loss of the simulator under those inputs, $\hat L(\theta)$ the same loss computed by a differentiable graph surrogate of the simulator, and $v$ a random direction with identity covariance. The update direction is

$$ \hat g = \nabla \hat L(\theta) + \big[D_v L(\theta) - D_v \hat L(\theta)\big]\, v , $$

where $D_v$ denotes the directional derivative along $v$. For the simulator, $D_v L$ is estimated by a paired finite difference that uses common random seeds, so SUMO's stochasticity cancels between the two runs. Because the expected value of $v v^\top$ is the identity, $\hat g$ is unbiased for the true gradient apart from finite-difference error. Its variance shrinks as the surrogate's directional derivatives track the simulator's, which is the mechanism NI-GBMS uses to stay stable up to 128 dimensions where plain forward gradients diverge. The surrogate is trained online on the simulator runs the estimator already pays for, so it is refreshed exactly in the regions the optimization visits. That addresses the drift failure documented for offline surrogates.

The analysis has three goals. First, measure the estimator's bias and variance against a high-sample finite-difference reference on a small corridor. Second, characterize where the simulator's discrete events (merge conflicts, lane-change cascades at a lane drop) change the gradient direction relative to a smooth continuum model. Third, test whether the benefit concentrates in incident windows, as the mechanism predicts. We expect, and will report honestly, that on recurring traffic a well-tuned pure network may match or beat this model on average error.

Baselines

The naive reference is the persistence/historical-average forecast: same time slot, same weekday average blended with the last observation. It calibrates how much of any gain is trivial. It is scored on exactly the same test windows, including the incident windows.

The strongest existing incident-aware forecaster is IGSTGNN from Incident-Guided Spatiotemporal Traffic Forecasting. It fuses incident context spatially and models recovery with a Gaussian temporal decay. It is the most direct competitor because it targets the same regime with the same incident logs. The file reports only relative figures: 5.65% lower average MAE than the second-best model on XTraffic Alameda, and a 4.1% advantage on 60-minute MAE on Orange. No absolute MAE for IGSTGNN was found on Lacuna, so we will rerun it ourselves on our corridor splits. For recurring-traffic accuracy, the strongest general forecasters are TESTAM, a mixture of temporal, static-graph and attention experts, and G-SWaN, which reports MAE 18.48 on PeMS-D4 against AGCRN's 19.83. TESTAM has no reported number on Lacuna for METR-LA or PEMS-BAY. For physics-informed prediction we use RA-BiGN, whose reported number is a 4% relative MAPE improvement over STAEformer on PeMS-D4. All learned baselines get the same training data, the same incident features where their architecture admits them, and the same hyperparameter-search budget in trials. Our model's simulator CPU hours are counted against its compute budget, and the baselines are given the same total wall-clock to spend on larger searches or ensembles.

Beating IGSTGNN means a statistically significant reduction in MAE restricted to incident windows (from incident onset to two hours after clearance) on held-out months of XTraffic, together with a lower error in queue-onset time. On non-incident windows we require only parity within a stated margin, and we treat a large loss there as a real cost.

Three ablations isolate the key ingredient. Removing the control variate leaves plain forward gradients, which tests whether variance reduction is necessary. Using surrogate gradients alone tests whether the real simulator's gradient information matters or the surrogate suffices. Replacing SUMO with a differentiable continuum model in the style of Son et al., trained with exact gradients, tests whether the non-differentiable discrete dynamics earn their cost. A fourth ablation adds back sensor-identity embeddings to measure what inductiveness costs in-distribution.

Why not just…?

Why not just train a neural surrogate of SUMO offline and backpropagate through it? This approach is cheaper, and it is the design of Lassen et al., who reach $R^2=0.952$ on Sioux Falls but degrade under capacity perturbations of the size an incident causes. In our setting the optimizer pushes the surrogate exactly toward unusual capacity drops, so its gradients become biased where they are needed. The surrogate-only ablation tests this directly. If it matches the full estimator in incident-window error and in gradient cosine to the reference, the real-simulator term is unnecessary and we would say so.

Why not just write the physics in a differentiable form, as in Differentiable Hybrid Traffic Simulation? This is the most serious threat. Exact gradients are cheaper and less noisy, and Son et al. report 15–19x backpropagation speedups from analytical gradients over autograd. What that model lacks is lateral dynamics: lane drops, weaving and merge friction, which plausibly govern how incident queues form on freeways. Whether that matters empirically is unknown, so the differentiable-continuum ablation is a co-equal arm, not a strawman. If it matches SUMO-in-the-loop within noise on incident windows, the conclusion is that a smooth continuum model suffices, and the black-box machinery is unnecessary for forecasting.

Why not just run a calibrated simulator and feed its outputs as features to a strong graph network, or correct a network's residuals statistically? Simulation-as-features keeps everything simple and differentiable on the network side. SAEA shows that modeling the remaining error as a linear vector autoregression cuts 45-minute RMSE by 5% to over 10%, while acknowledging it cannot capture nonlinear propagation. Neither approach makes the final forecast obey conservation or capacity, and the feature approach still uses a simulator calibrated offline and blind to the live incident. We run both: IGSTGNN with simulator-output features, and IGSTGNN with SAEA correction. If either matches our accuracy, the remaining case for our method rests only on physical validity and transfer, and we report it that way.

Why not just calibrate per incident with a derivative-free optimizer such as CMA-ES? Son et al. found gradient-based identification converged an order of magnitude faster than CMA-ES, but on synthetic geometry. A per-forecast search over hundreds of inputs is also unlikely to fit a 5-minute forecasting cadence. We include CMA-ES under a matched simulator-call budget on the small corridor to check this on real data.

Proposed Experiments

The primary benchmark is XTraffic, which has time-aligned incident logs. We train on corridors within Alameda (521 nodes, about 14,600 incidents), hold out later months for testing, and evaluate zero-shot on Contra Costa (496 nodes) without retraining. The zero-shot test targets the transductive limitation identified in Generalising Traffic Forecasting to Regions without Traffic Observations. Baselines with identity embeddings must instead be retrained there, and we report both their retrained and nearest-neighbor-transferred scores. PEMS-BAY and PeMS-D4 corridors serve as the recurring-traffic check.

Metrics are MAE, RMSE and MAPE at 15, 30 and 60 minutes, reported separately for incident and non-incident windows. We add three physical measures: the fraction of forecasts violating link capacity or vehicle conservation between consecutive detectors, the error in queue-onset time, and the error in the speed of the backward-propagating congestion front.

Three results would decide the question. The first is gradient quality on a small corridor. The control-variate estimator should show markedly lower variance than plain forward gradients at equal simulator calls, with cosine similarity to a high-sample reference that stays high in congested states. If not, the method fails at its foundation. The second is the incident-window comparison against IGSTGNN and the differentiable-continuum ablation. If neither beats ours there, the core claim is supported; if the continuum ablation ties, the black-box simulator is unnecessary. The third is the Contra Costa transfer gap relative to in-region performance. A small gap where embedding-based models collapse would confirm that predicting physical quantities, rather than memorizing sensors, is what carries over.