Learning Safe Neural Network Controllers with Barrier Certificates

Hengjun Zhao, Xia Zeng, Taolue Chen, Zhiming Liu, Jim Woodcock

Abstract

Ensuring safety in nonlinear control systems remains a significant challenge, particularly when employing "black-box" neural network controllers. This paper introduces a "verification-in-the-loop" framework that co-synthesizes a neural network controller and a neural barrier certificate. By encoding formal safety requirements directly into the loss function and validating the results with a Satisfiability Modulo Theories (SMT) solver, the authors produce controllers for nonlinear systems that are both effective and formally guaranteed to remain within safe operating regions. The approach is demonstrated across five classic nonlinear control benchmarks, showing high efficiency and robust safety margins.

Introduction

In control theory, designing a controller for a nonlinear system is inherently difficult; ensuring that the controller is "safe"—meaning the system never enters a predefined "unsafe" region—is even more complex. While Deep Learning has revolutionized the control of complex systems like self-driving cars and drones, neural networks are often viewed as black boxes that lack formal safety guarantees. Traditional formal methods, such as Barrier Certificates (functions that mathematically prove a system stays within a safe set), usually require manual design or are restricted to simple polynomial systems.

This paper bridges the gap by using neural networks to represent both the controller and the safety proof, automating the synthesis of safe, nonlinear control laws. The proposed framework allows for high-performance control without sacrificing the rigorous guarantees required for safety-critical applications.

The Verification-in-the-Loop Framework

The authors propose a co-synthesis approach using two distinct neural networks: a Controller-NN ($N_c$), which learns the feedback control law $u = g(x)$, and a Barrier-NN ($N_b$), which learns a barrier function $B(x)$ that satisfies the conditions for a strict barrier certificate.

The verification-in-the-loop framework for co-synthesizing controllers and barrier certificates.

Key Innovations in Synthesis

  • Loss Function Encoding: Safety conditions (e.g., $B(x) \le 0$ for initial states, $B(x) > 0$ for unsafe states, and a negative Lie derivative on the boundary) are converted into sub-loss terms. Training succeeds only when the total loss reaches zero, indicating all safety conditions are met on the training data.
  • Bent-ReLU Activation: Standard ReLUs are not continuously differentiable, which complicates calculating the Lie derivative (the rate of change of the barrier function along the system's trajectory). The authors utilize Bent-ReLU for the Barrier-NN to ensure the necessary smoothness for formal verification.
  • Formal Verification: After training, the candidates are passed to iSAT3, a nonlinear SMT solver. If the solver finds a counterexample (a point where safety is violated), the networks are fine-tuned with adjusted tolerances and the counterexample is added to the training set.

Experimental Results and Benchmarks

The approach is data-driven but model-based, generating training data by sampling the state space of the target system. The method was evaluated on five classic nonlinear control problems: Dubins’ Car, Inverted Pendulum, Duffing Oscillator, Bicycle Steering, and a generic 3D Academic Model.

Trajectories of the Dubins' car model staying within safe boundaries (red lines) while tracking the target path.

As shown in the Dubins' Car benchmark (Figure 4), the synthesized controller successfully steers the vehicle to track a path ($y=0$) while strictly avoiding lateral boundaries ($y = \pm 5$). The tool, nncontroller, successfully generated and formally verified safe controllers for all five examples. For the Dubins' Car, training took roughly 26 seconds, and formal verification took about 8 seconds. Even for the more complex 3D Academic model, the system found a provably safe controller where traditional methods might struggle.

Discussion and Future Work

A key insight of this work is that simultaneous learning allows the controller and the certificate to "negotiate." The controller learns to stay within the region that the barrier function can successfully certify. Furthermore, the authors found that very simple neural architectures (e.g., one hidden layer with 5-10 neurons) are sufficient to control and certify these nonlinear systems.

Despite these successes, limitations remain. The current framework requires a precise mathematical model (ODEs) of the system and faces the "curse of dimensionality" during state-space sampling. Future work aims to incorporate a third neural network to learn system dynamics from data and explore alternative verification methods to scale to higher-dimensional systems. Additionally, integrating cost-based rewards to optimize for fuel or time alongside safety remains a priority.

Summary updated

BibTeX
@article{zhao2021learning,
  author = {Hengjun Zhao and Xia Zeng and Taolue Chen and Zhiming Liu and Jim Woodcock},
  title = {{Learning Safe Neural Network Controllers with Barrier Certificates}},
  journal = {Formal Aspects Comput.},
  year = {2021},
  doi = {10.1007/s00165-021-00544-5},
}
Figure