TL;DR
This paper introduces Pushdown Reward Machines (pdRMs), an extension to Reward Machines that incorporates a stack memory based on deterministic pushdown automata. This allows reinforcement learning agents to understand and exploit rewards structured as deterministic context-free languages (such as recursive or palindromic tasks). By limiting policy access to just the top $k$ symbols of the stack, pdRMs avoid the state-space explosion typical of counter-based methods, significantly improving sample efficiency.
What Problem Does This Paper Address?
Reinforcement learning (RL) agents often struggle with tasks that feature non-Markovian rewards—where the reward depends on the history of actions rather than just the current state. Reward Machines (RMs) solve this by using finite-state automata to represent regular languages (Type-3 in the Chomsky hierarchy), like "do A, then B, then C."
However, many real-world tasks require more expressive power—specifically, deterministic context-free languages (DCFLs). Examples include:
- Symmetric tasks: Navigating a maze to a goal and retracing the exact path backward (a palindrome).
- Symmetric counting: Collecting an arbitrary number of items and delivering them to a specific location matching that exact count.
Prior attempts to scale up RMs introduced Counting Reward Automata (CRAs), which use integer counters. Unfortunately, counters can cause an exponential explosion in the environment's state space, making exploration and learning painfully slow or computationally intractable.
Methods
The authors propose Pushdown Reward Machines (pdRMs), which augment standard RMs with a single memory stack.
Key methodological innovations include:
- $k$-Policies: Instead of giving the RL agent's policy access to the entire (potentially infinite) stack, the authors define a bounded policy that only looks at the top $k$ symbols. For many tasks, $k=1$ is sufficient.
- Optimality Verification: They provide a theoretical value-iteration-based procedure to check whether a compact $k$-policy can achieve the same optimal state values as a full-stack policy.
- CpRM (Counterfactual pushdown Reward Machine): An off-policy learning algorithm that generates synthetic "counterfactual" experiences. To prevent a combinatorial explosion of updates, CpRM uniquely restricts these updates to stack strings actually observed during training.
Datasets
The authors evaluated pdRMs across five distinct simulated environments implemented in the Gymnasium framework:
- LetterEnv: A gridworld benchmark from prior CRA literature requiring the agent to visit a sequence of cells matching a specific count pattern ($A^n B C^n$).
- 1-TreasureMaze: A gridworld where the agent must find a treasure and retrace its exact path back to the start. Tested on $5\times5$, $10\times10$, and $20\times20$ maps.
- MultipleTreasureMaze: An extended version requiring multiple sequential path-retracing trips to a safe zone.
- DeliverWorld: A gridworld requiring a sequence of deliveries based on randomly generated target lists.
- WaterWorld: A continuous-state domain where the agent must ingest balls, store their parities on a stack, and then clear the stack by touching target items matching the top-of-stack parity.
Key Insights and Ideas
- The Power of Local Stack Visibility: For many context-free tasks, you don't need to know the whole history to make the next optimal move; you only need the immediate next step. For example, in path retracing, looking at just the top symbol ($k=1$) tells the agent which direction to head next.
- Linear vs. Exponential Blowup: While full-stack policies and counter-based methods (CRAs) suffer from an exponential state-space blowup relative to episode length, a $1$-policy scales linearly with the size of the stack alphabet. This makes the underlying product MDP significantly smaller and easier to explore.
Key Results
Gridworld Efficiency
In LetterEnv, pdRM variants converged faster or matched state-of-the-art CRA methods.
In the scaling tests of 1-TreasureMaze, the advantage became stark: the $1$-policy pdRM successfully solved all maze sizes up to $20\times20$. In contrast, CRA and full-stack pdRM approaches failed on larger maps because their state spaces blew up, causing the training to time out.
Continuous Domains
In WaterWorld, a deep RL agent trained using Proximal Policy Optimization (PPO) combined with a $1$-policy pdRM solved the task rapidly. It completely outperformed standard PPO and Recurrent PPO (LSTM), which failed to consistently learn the underlying context-free logic of the task.
Limitations and Future Work
- Counterfactual Bottlenecks: While the CpRM algorithm tracks only observed stack strings, it can still experience slowdowns in environments with highly diverse stack languages (like large mazes), leading to training timeouts.
- Manual Design: Currently, the pdRM structure must be manually specified by a human expert.
- Future Directions: The authors point toward automatically synthesizing pdRMs from data or grammatical specifications (like $LR(k)$ grammars) and extending pdRMs to handle partially observable environments.
Summary updated