Abstract
This paper presents a technique, named STLCG, to compute the quantitative semantics of Signal Temporal Logic (STL) formulas using computation graphs. STLCG provides a platform which enables the incorporation of logical specifications into robotics problems that benefit from gradient-based solutions. Specifically, STL is a powerful and expressive formal language that can specify spatial and temporal properties of signals generated by both continuous and hybrid systems. The quantitative semantics of STL provide a robustness metric, i.e., how much a signal satisfies or violates an STL specification. In this work, we devise a systematic methodology for translating STL robustness formulas into computation graphs. With this representation, and by leveraging off-the-shelf automatic differentiation tools, we are able to efficiently backpropagate through STL robustness formulas and hence enable a natural and easy-to-use integration of STL specifications with many gradient-based approaches used in robotics. Through a number of examples stemming from various robotics applications, we demonstrate that STLCG is versatile, computationally efficient, and capable of incorporating human-domain knowledge into the problem formulation.
Introduction
In robotics and autonomous systems, safety and operational rules are often clear—such as maintaining distance from obstacles or following specific sequences of checkpoints. Traditionally, these rules are expressed using Linear Temporal Logic (LTL). However, LTL is discrete and inherently incompatible with the gradient-based optimization methods that drive modern artificial intelligence and control.
Signal Temporal Logic (STL) offers an improvement by providing "robustness" values—a continuous metric indicating the degree to which a signal satisfies or violates a rule. Despite this, calculating these values and their gradients for complex formulas has historically been computationally expensive and difficult to integrate into deep learning libraries like PyTorch. This paper introduces stlcg, a Python toolbox that bridges this gap by representing STL as a differentiable computation graph.
Methodology: STL as a Computation Graph
The core innovation of the stlcg (Signal Temporal Logic Computation Graph) framework is the treatment of STL formulas as recursive structures. Every logical operator—including AND ($\wedge$), OR ($\vee$), Always ($\Box$), Eventually ($\diamondsuit$), and Until ($\mathcal{U}$)—is mapped to a node in a directed acyclic graph.
To ensure the framework is compatible with gradient descent, the authors implement several key technical strategies:
- Recursive Robustness: Dynamic programming is used to compute robustness traces efficiently. Temporal operators are unrolled similarly to Recurrent Neural Networks (RNNs), passing "hidden states" of robustness across time steps.
- Smooth Approximations: Standard STL uses non-differentiable
maxandminfunctions. The authors replace these with smooth versions like Softmax and LogSumExp to ensure continuous gradient flow. - Integral Robustness: They propose an integral-based robustness formula that "spreads" gradients across the entire signal, preventing the optimizer from focusing solely on a single point of failure.
Key Insights and Results
By making logic differentiable, it can be used as a loss function or a "logical prior" in neural network training. This allows researchers to explicitly "bake" domain knowledge into a model rather than relying on the network to learn rules from potentially noisy or limited data. Furthermore, because the logic is represented as a computation graph, it can be batched and accelerated on GPUs, providing significant speedups over traditional CPU-based checkers.
The framework was evaluated across several scenarios:
- Motion Planning: Successfully solved complex "Until" constraints (e.g., "Visit A, then stay in B while avoiding C") using simple gradient descent.
- Neural Network Regularization: A sequence-to-sequence model trained with an STL loss predicted long-term behaviors accurately, even when those behaviors were absent from short-horizon training data.
- VAE Mode Separation: By adding an STL loss to a Variational Autoencoder (VAE), the authors forced the latent space to correspond to specific logical behaviors, effectively mitigating "mode collapse."
Conclusion
While stlcg represents a major step forward, limitations remain. Currently, the framework cannot backpropagate through the time bounds of operators (e.g., optimizing the duration of a constraint). Additionally, the robustness landscape can be non-convex, meaning gradient descent may still encounter local minima for highly complex formulas. Future work includes extending the language's expressivity and applying the tool to the verification of safety-critical systems like autonomous vehicles.
Summary updated