LCRL: Certified Policy Synthesis via Logically-Constrained Reinforcement Learning

Hosein Hasanbeig, Daniel Kroening, Alessandro Abate

TL;DR

LCRL is an open-source Python tool that enables reinforcement learning (RL) agents to automatically synthesize optimal policies under complex, time-dependent Linear Temporal Logic (LTL) constraints in unknown environments. By translating logical specifications into automata and shaping rewards on-the-fly, LCRL bridges the gap between formal verification and model-free RL, scaling effectively to continuous and high-dimensional state spaces where traditional model checkers fail.

What Problem Does This Paper Address?

Standard reinforcement learning relies heavily on hand-crafted, scalar reward functions. While this works well for simple, static goals, it struggles significantly with complex, history-dependent tasks (e.g., "visit region A, then region B, but never enter unsafe region C").

Linear Temporal Logic (LTL) provides a mathematically rigorous language to specify these complex behaviors. However, traditional formal verification methods (like model checking) require a complete, explicit mathematical model of the environment's transition probabilities—an assumption that is unrealistic for complex, black-box systems. Existing model-free RL approaches that incorporate LTL either restrict themselves to small subsets of the logic or fail to scale to continuous or high-dimensional spaces.

The authors introduce LCRL to solve this bottleneck, providing a scalable, model-free tool capable of synthesizing certified policies for unknown Markov Decision Processes (MDPs) under full LTL specifications.

Methods

LCRL introduces a framework that automatically coordinates an unknown environment with a formal logical specification:

  1. LTL to Automaton Translation: The user-defined LTL specification is translated into a Limit-Deterministic Büchi Automaton (LDBA), a type of finite-state machine that can express complex temporal properties.
  2. On-the-Fly Synchronization: Rather than computing a massive, explicit product state space beforehand (which causes a combinatorial explosion), LCRL synchronizes the unknown MDP environment and the LDBA dynamically during runtime. The LDBA acts as an automated memory register tracking task progression.
  3. Automaton-Guided Reward Shaping: LCRL automatically shapes the reward function based on the transitions of the LDBA. The agent receives positive reinforcement as it advances toward fulfilling the logical specification.
  4. State-Dependent Discounting: To preserve theoretical convergence and optimality guarantees, LCRL applies a discount factor ($\eta$) only when the reward is positive, leaving it un-discounted otherwise.
  5. Flexible RL Backends: LCRL supports multiple underlying RL algorithms depending on the state space: tabular Q-learning (ql) for discrete environments, and Neural Fitted Q-iteration (nfq) or Deep Deterministic Policy Gradient (ddpg) for continuous state and action spaces.
Figure 1: The LCRL architecture: the inputs to the tool are the environment (MDP) - in particular its states s and corresponding labels L(s) - as well as the LDBA generated from the user-defined LTL specification. The MDP (with state s) and the LDBA (with state q) are synchronised on-the-fly, thus generating the pair (s, q). A reward r is then automatically generated by LCRL, based on the environment label L(s) and the automaton state q; actions a are selected accordingly and passed back to the environment (MDP).

Datasets

The paper evaluates LCRL across a diverse suite of simulated environments and robotic benchmarks rather than static datasets:

  • Minecraft-inspired Grid-worlds (minecraft-t1 to t7): Discrete environments requiring the sequential collection of items (e.g., wood, grass, iron) before reaching a final checkpoint.
  • OpenAI Gym Benchmarks: Standard environments including Frozen-Lake (adapted for sequential region visits and avoidance) and Cart-Pole (adapted for continuous control under safety constraints).
  • Mars-Rover: A realistic robotic benchmark featuring fully continuous state and action spaces.
  • Pacman (pacman-sml and pacman-lrg): High-dimensional discrete state spaces simulating the classic arcade game, configured to force the agent to choose between different food sources while avoiding ghosts.
Figure 3: (a) Synthesised policy by LCRL in minecraft-t3; (b) cart-pole experiment [44]; (c) pacman-lrg - the white square on the left is labelled as food 1 (f1) and the one on the right as food 2 (f2), the state of being caught by a ghost is labelled as (g) and the rest of the state space is labelled as neutral (n).

Key Insights and Ideas

  • Deconstructing Non-Markovian Tasks: LTL tasks are naturally non-Markovian because the next best action depends on history. By using the LDBA state as an extra dimension, LCRL breaks down history-dependent specifications into standard Markovian "reach-avoid" sub-problems.
  • First for Continuous LTL Synthesis: LCRL is the first tool to successfully implement model-free RL synthesis for full LTL specifications in continuous state/action spaces without requiring manual space discretization.
  • Scalability via Guided Exploration: Traditional dynamic programming solutions evaluate the entire state space exhaustively. LCRL’s automaton-driven rewards focus the agent's exploration only on task-relevant regions, drastically mitigating the curse of dimensionality.
  • Hyperparameter Robustness: The framework demonstrates remarkable insensitivity to hyperparameter tuning (such as variations in the learning rate $\mu$ and discount factor $\eta$), maintaining high task satisfaction rates across various configurations.

Key Results

  • Ground-Truth Alignment: In smaller environments where the true maximum satisfaction probability could be mathematically computed using the PRISM model checker, LCRL's empirical satisfaction probability closely matched the theoretical maximum (often reaching $\sim0.99$).
  • Outperforming Traditional Model Checkers: For large state spaces like pacman-lrg (boasting over 4.2 million states), traditional model checkers timed out (t/o) due to memory limits. LCRL successfully synthesized a satisfying policy in reasonable time.
  • Continuous Control Success: LCRL successfully solved continuous control tasks (Mars-Rover and Cart-Pole) under strict LTL constraints where standard Q-learning completely fails.

Limitations and Future Work

  • Automata Tool Integration: Currently, the LDBA step function must be manually specified or pre-configured within the tool. The authors plan to directly interface LCRL with automated LTL-to-automata synthesis tools like OWL.
  • Model Checker Interoperability: Future iterations aim to build direct pipelines to link LCRL with established probabilistic model checkers like PRISM and Storm for verification.
  • Algorithmic Expansion: The authors intend to embed a wider variety of modern deep RL backends to handle even more complex environments.
  • Alternative Logics: The framework is slated for extension to support other formalisms, such as Signal Temporal Logic (STL), which natively handles continuous-time constraints.

Summary updated

Abstract

LCRL is a software tool that implements model-free Reinforcement Learning (RL) algorithms over unknown Markov Decision Processes (MDPs), synthesising policies that satisfy a given linear temporal specification with maximal probability. LCRL leverages partially deterministic finite-state machines known as Limit Deterministic Buchi Automata (LDBA) to express a given linear temporal specification. A reward function for the RL algorithm is shaped on-the-fly, based on the structure of the LDBA. Theoretical guarantees under proper assumptions ensure the convergence of the RL algorithm to an optimal policy that maximises the satisfaction probability. We present case studies to demonstrate the applicability, ease of use, scalability, and performance of LCRL. Owing to the LDBA-guided exploration and LCRL model-free architecture, we observe robust performance, which also scales well when compared to standard RL approaches (whenever applicable to LTL specifications). Full instructions on how to execute all the case studies in this paper are provided on a GitHub page that accompanies the LCRL distribution www.github.com/grockious/lcrl.
BibTeX
@inproceedings{hasanbeig2022lcrl,
  author = {Hosein Hasanbeig and Daniel Kroening and Alessandro Abate},
  title = {{LCRL: Certified Policy Synthesis via Logically-Constrained Reinforcement Learning}},
  booktitle = {QEST},
  year = {2022},
}
Figure