March 11, 2025

Parv Kapoor

By Scaled Foundations

STLCG++: A Masking Approach for Fast and Differentiable Signal Temporal Logic

Scaling Signal Temporal Logic (STL) for real-time robotics and AI

Signal Temporal Logic (STL) provides a precise formal language for specifying desired robotic system behavior, grounded in a well-developed theoretical foundation of logic. Whether ensuring that autonomous vehicles comply with traffic rules, enforcing sequential constraints in task planning, or verifying the robustness of learned control policies, STL enables the specification of spatio-temporal rules for robotic systems. Its ability to quantify “how well” a system’s behavior satisfies a requirement (robustness) makes it an attractive tool for optimization, learning, and verification.

STLCG was introduced to encode any STL formula as a computation graph and leveraged GPU-accelerated automatic differentiation for evaluation and backpropagation. However, STLCG’s robustness computation is slow because it relies on recurrent operations to evaluate and differentiate STL robustness, making it impractical for real-time or large-scale applications. We propose STLCG++, which addresses this bottleneck by replacing recurrence with masking, achieving a 1000× speedup in key tasks.

Type image caption here (optiona

Key Idea: Scaling STL robustness evaluation with Masking

The traditional way of evaluating STL robustness is similar to how an RNN works - it processes signals sequentially, one timestep at a time. This sequential nature makes it slow and difficult to parallelize for long sequences, which limits its usefulness in modern robotics.

To address this, we introduce STLCG++, a new approach inspired by causal masking mechanisms used in modern transformers. STLCG++ uses a masking technique to parallelize STL robustness evaluation. Instead of processing each timestep sequentially, STLCG++ precomputes masks that select relevant parts of the trajectory and then applies highly optimized vectorized operations across all timesteps at once.

Major advantages of this approach:

- 1000× faster robustness evaluation across multiple time intervals compared to the recurrent method, making STL feasible for online use.
- Efficient differentiation of STL robustness, enabling gradient-based optimization over time intervals.
- GPU acceleration using modern deep learning libraries (JAX, PyTorch). Scalability to long sequences, making STL practical for complex robotic tasks.

Leveraging STLCG++ for Real-World Robotics

We applied STLCG++ to three real-world robotics problems:

Trajectory Optimization with Adaptive STL Constraints

Finding optimal robot trajectories while simultaneously optimizing the STL constraints themselves. This approach produces trajectories that are both optimal and flexible, satisfying constraints without excessive conservatism. The resulting long-horizon, complex task trajectory data can be used to train modern Vision-Language-Action models.

STL-Guided Diffusion Models for Policy Learning

By incorporating STL robustness into diffusion models, we can bias generated behaviors toward satisfying complex temporal logic constraints, achieving a 62.5% success rate compared to unguided models.

Mining STL Specifications from Data

Successfully recovering ground-truth STL constraints from noisy robot trajectory datasets. This method is valuable for runtime monitors that assess system behavior at test time and determine whether intervention is required.

Why This Matters for Robotics

Until now, STLCG based methods were largely restricted to small-scale, offline applications due to it’s computational costs. STLCG++ changes this by making computational graph based STL evaluation real-time, scalable, and differentiable, unlocking its full potential for:

  • Autonomous driving → Enforcing STL-based safety and performance constraints
  • Robot learning → Using STL as a structured loss function for training or for reward shaping in reinforcement learning
  • Data generation → Using trajectory optimization with STL, complex trajectory data can be generated which can be used for training modern Vision Language Action Models.

STLCG++ is open-source and available in both JAX and PyTorch, making it easy to integrate with modern deep learning and optimization frameworks.

Explore trajectory optimization with STLCG++ in jax via our GRID notebook!

Link to the grid notebook