Training Wave-Damping Autonomous Vehicles Inside a Hard-Constrained Differentiable Traffic Simulator

A few automated vehicles placed in human traffic can dissolve "phantom" stop-and-go jams. On a 22-car ring road, one controlled car out of 22 raises average speed by up to 57% (Flow). The fastest way to learn such controllers is to differentiate through the traffic simulator itself, so that the controller sees exactly how its acceleration ripples through every human car behind it. Differentiable traffic simulators already do this, but they keep their physics smooth with soft relaxations. Spacing and speed limits become softplus terms, and safety becomes a reward penalty. That combination is dangerous. A gradient-based learner does not merely tolerate small constraint violations. It follows the gradient into them. If simulated humans can brake slightly harder than real people can, or cars can slightly overlap, the policy will learn to rely on it.

We propose to build a differentiable mixed-autonomy traffic simulator in which every physical and safety constraint holds exactly at every time step, and to train automated-vehicle controllers by backpropagating through it. Human drivers get hard limits on acceleration and braking. The automated vehicles' actions pass through a differentiable safety filter at each step: a small optimization that minimally corrects each commanded acceleration so that no car, including the human cars behind it, can be forced into a collision. Gradients flow through both the filter and the multi-car dynamics. The claim is that this gives controllers whose throughput gains survive transfer to a non-differentiable, hard-limited simulator. We expect soft-constraint training and post-hoc safety filtering to each lose a measurable part of their apparent gains, and we define a diagnostic, the exploitation gap, to measure that loss.

Core Claim

When a controller is optimized with first-order gradients through a simulator, soft constraints in that simulator act as loopholes the optimizer will find and use. The results are inflated in-simulator gains and unsafe behavior at deployment. A hard projection placed inside the rollout removes the loophole. Because the projection is differentiable, it also changes the gradient: the policy learns how filter-corrected braking propagates upstream as a wave, so it learns to avoid triggering the filter in the first place. The effect is not the same as attaching the filter after training.

The automated vehicles' safety filter solves, at each step, a quadratic program (an optimization with a quadratic cost and linear constraints):

$$u^\star = \arg\min_u \|u - \pi_\theta(s)\|^2 \quad \text{s.t.} \quad \dot h_j(s,u) + \alpha\, h_j(s) \ge 0 \;\; \forall j, \qquad u_{\min} \le u \le u_{\max}.$$

Here $\pi_\theta(s)$ is the controller's nominal acceleration command given traffic state $s$, and $u$ is the executed command. The constraints come from a control barrier function, a function whose sign certifies safety: $h_j(s) \ge 0$ for a leader–follower pair $j$ means the follower can still stop in time. Each $h_j$ is defined as the gap minus a stopping distance, with the stopping distance computed from the follower's speed, a human reaction delay, and the human's maximum braking rate. The constant $\alpha > 0$ sets how quickly the filter allows $h_j$ to approach zero.

Constraints are written for pairs in which the follower is human as well as pairs in which it is automated, in the cooperative style of Enforcing Cooperative Safety for RL-Based Mixed-Autonomy Platoon Control. On a single lane each constraint couples only neighboring cars, so the program is banded and cheap to solve in batches. We differentiate through its solution by implicit differentiation of the optimality conditions, the technique PDE-CL uses to avoid unrolling solver iterations.

Relation to Prior Work

Three papers motivate the gap. TrAAD backpropagates analytic car-following gradients into policy updates and reports a +64.27% median traffic-flow gain in CARLA, but it handles safety only through cost terms. The parallel differentiable IDM simulator keeps speed and spacing nonnegative with softplus, which is adequate for fitting recorded trajectories but has never been stress-tested while an optimizer actively pushes against those bounds. The soft-constraint literature predicts trouble in exactly this setting. hPINN shows optimizers trading feasibility for objective value. Lee et al. show small per-step violations compounding over autoregressive rollouts. Saad et al. show penalty-enforced boundaries leaking.

The method comes from two sources. The cooperative platoon paper (detailed version; Enforcing Cooperative Safety for Reinforcement Learning-based Mixed-Autonomy Platoon Control) supplies the cooperative barrier constraints and a differentiable safety layer. There, however, gradients stop at the filter, the simulator is a black box, and training is model-free multi-agent reinforcement learning. Differentiable Predictive Control with CBF safety shows that a policy trained through differentiable rollouts and then guarded by a barrier filter rarely triggers that filter. It is single-agent and one-dimensional, and its filter is attached after training rather than placed inside the rollout. That paper is also our strongest piece of contrary evidence, which we address directly below.

Two papers constrain the design. The LTL differentiable-simulation work shows that smoothing discrete logic makes behavior sensitive to temperature settings, so we refuse to smooth safety. It also shows that short-horizon actor-critic (SHAC) tames long-rollout gradients, and we reuse that. The projection methods HCP and PDE-CL enforce linear PDE equalities. Our constraints are inequalities over many cars, which is why we use a quadratic program with implicit differentiation rather than a closed-form projection.

Research Program

The simulator is a single-lane ring and an on-ramp merge implemented in JAX, following the functional design of JAX MD. Human cars follow the Intelligent Driver Model (IDM), a standard equation for how a driver accelerates given gap and speed. To capture heterogeneity, each human car's five IDM parameters are calibrated to individual NGSIM drivers using the gradient-fitting procedure of the parallel simulator paper. Human accelerations are clipped exactly to physically realistic limits rather than softened, and they include a reaction delay. Any overlap between cars is logged as a crash and never repaired. The simulator is not allowed to quietly rescue a crash.

Controllers are shared-parameter networks for each automated vehicle. They are trained with SHAC through the simulator and the filter. Training adds an efficiency term, the squared size of the filter's correction, so the policy is rewarded for staying away from the filter's active region. That term affects only efficiency. Safety holds regardless of its weight.

The first analysis characterizes gradient behavior near active constraints. When a constraint is active, the executed action stops depending on the nominal command, and the controller's gradient there can vanish. We will measure how often this happens and whether the correction penalty supplies enough signal to escape it.

The second analysis defines the exploitation gap. It is a policy's average speed or throughput gain in its training simulator minus its gain when replayed in SUMO with hard braking limits and NGSIM-calibrated humans, both measured against the all-human baseline. Crashes in the replay are counted separately.

Baselines

The do-nothing reference is all-human traffic, with every car following calibrated IDM. Every gain is reported relative to it.

The classic learning reference is model-free reinforcement learning in Flow on the same ring and merge, with no safety layer. Flow reports up to 57% average-velocity improvement on the 22-car ring with one automated car. We rerun it under our calibrated humans and do not compare against the published figure directly, because the human models differ.

The soft-differentiable competitor is TrAAD-style training. It uses the same JAX simulator and SHAC, but replaces hard limits with softplus spacing and speed bounds and replaces the filter with a collision penalty, tuned over the same sweep budget as our method. TrAAD reports a +64.27% median traffic-flow gain in CARLA. No reported result was found on Lacuna for TrAAD on the Flow ring or merge.

The strongest existing method is MAPPO with the cooperative differentiable safety filter ( Enforcing Cooperative Safety for Reinforcement Learning-based Mixed-Autonomy Platoon Control). It uses exactly our barrier constraints but trains model-free, without simulator gradients. It reports a nearly 100% and a 70% expansion of the safely tolerated disturbance range over unfiltered multi-agent RL, in its own platoon environment. We run it on our ring and merge with identical constraints, humans, environment steps, and wall-clock budget. Our method beats it if it reaches at least equal throughput in the hard SUMO replay with equal or fewer steps, and matches its zero-crash record and its disturbance-tolerance range.

Two ablations isolate the key ingredient. The post-hoc ablation trains through the soft simulator without a filter and attaches the identical filter only at test time. The stop-gradient ablation keeps the filter in the loop during training but blocks gradients through the multi-car dynamics. Together they separate the value of having hard constraints inside training from the value of differentiating through physics.

Why not just…?

Why not just train with soft penalties and attach the safety filter at deployment? This is the most serious threat. DPC with CBF safety found that a well-trained policy rarely triggers its filter. Our counter-hypothesis applies specifically to traffic. A policy trained without the filter will sit close to the spacing boundary, because tight following is where throughput lives. At test time, filter corrections then arrive as unanticipated sharp braking, which propagates upstream through the human cars and recreates the waves the controller was meant to suppress. The post-hoc ablation settles this. If it matches our throughput in the hard replay with a comparably low intervention rate, the core claim is wrong for this setting, and we will report it as such.

Why not just use model-free MAPPO with the cooperative differentiable filter, which already exists? It provides the same safety guarantee, so the question reduces to efficiency and solution quality. Simulator gradients sped learning severalfold in the LTL work (20M versus more than 100M steps on CartPole) and accelerated convergence in TrAAD. Neither result covers multi-agent traffic with an active filter, where gradients can vanish at active constraints. Equal-budget learning curves against this baseline, together with the stop-gradient ablation, answer the question directly.

Why not just tune the penalty properly, for example with augmented Lagrangian multipliers? hPINN shows that augmented Lagrangian methods drive residuals small at convergence. That is a property of the trained solution, not a per-step guarantee. Violations remain possible during training, and they remain possible on the out-of-distribution human braking events that matter most. We include an augmented-Lagrangian variant of the soft competitor. If its exploitation gap and adversarial crash count both reach zero, hard enforcement is unnecessary, and we would say so.

Proposed Experiments

The first decisive check is the exploitation gap. For every method trained on the ring and the merge, we replay the policy in SUMO with hard braking limits and held-out NGSIM-calibrated humans. Our prediction is that both soft-trained variants lose a substantial share of their training-simulator gain or produce crashes, while the hard-constrained method loses little and produces no crashes.

The second check is adversarial disturbance. Following the protocol of the platoon paper, we inject sudden braking and acceleration by individual human cars and sweep the magnitude until the first crash. This gives a tolerated disturbance range per method.

The third check measures wave damping and filter intervention frequency as functions of automated-vehicle penetration (5%, 10%, 20%) and ring density. It also tests whether a policy trained at one density transfers to the others without retraining.

Compute is matched across all methods, and every result is reported over ten seeds. The claim stands if the hard-constrained method has the smallest exploitation gap, has zero crashes, and achieves at least the throughput of the strongest baseline in the hard replay.