TL;DR
Program Machine Policies (POMPs) marry programmatic reinforcement learning with finite-state machines to solve complex, long-horizon tasks. By structuring high-level behaviors as human-readable programs (modes) and learning a transition policy to switch between them, POMP enables inductive generalization to horizons spanning thousands or even hundreds of thousands of steps without any fine-tuning.
What Problem Does This Paper Address?
Standard deep reinforcement learning (DRL) produces "black-box" policies that struggle to generalize to unseen scenarios and lack interpretability. While programmatic RL addresses this by synthesizing policies as formal, executable code (e.g., in domain-specific languages), existing synthesis techniques fail to scale beyond short horizons (under 400 steps) and concise programs (<120 tokens).
Conversely, state machine policies can capture repetitive, cyclic tasks and inductively generalize across long horizons, but they typically rely on rigid, hand-crafted primitive actions rather than expressive, high-level skills. This paper bridges this divide: how can we build policies that retain the readability and compositional expressiveness of domain-specific programs while scaling to long-horizon, repetitive tasks via state-machine transitions?
Methods
The authors propose Program Machine Policies (POMP) via a three-stage framework:
- Constructing the Program Embedding Space: Following prior latent program synthesis work (LEAPS), a continuous, behaviorally smooth latent space of programs is trained using a Variational Autoencoder (VAE) coupled with semantic execution consistency losses over a dataset of randomly generated DSL programs.
- Retrieving Mode Programs (CEM + Diversity + Compatibility): To discover reusable skills that serve as state machine "modes," the authors extend the Cross-Entropy Method (CEM):
- Effectiveness: Optimizes task returns via CEM.
- Diversity: Modulates the objective with a sigmoid-based cosine distance penalty relative to previously discovered programs, ensuring the agent learns distinct skills.
- Compatibility: Candidate program latents $z$ are evaluated by executing them sequentially between random sequences of already discovered mode programs ($\Psi_{\text{before}}, \rho_z, \Psi_{\text{after}}$). This ensures that mode programs can be chained together without breaking task execution.
- Learning the Transition Function: A neural network transition function $f(m_i, m_j, s)$ takes the current environment state $s$ and active mode $m_i$ to sample the next mode $m_{j}$ (or a dedicated termination state $m_{\text{term}}$). Trained via Proximal Policy Optimization (PPO), the transition model learns when to swap programs to maximize cumulative task return. To restore full interpretability, a post-hoc quantization method extracts the neural transition function into a discrete Moore machine.
┌────────────────────────┐
│ Current Mode Program │
│ (e.g., harvest row) │
└───────────┬────────────┘
│ emits actions to env
▼
State s ──► ┌────────────────────────┐
Mode m_i ──► │ Mode Transition Policy │ ──► Next Mode Program m_j
│ (PPO / State Machine) │ or Terminate
└────────────────────────┘
Datasets & Benchmarks
The paper evaluates on the Karel the Robot grid-world domain:
- KAREL Benchmark: 6 short-horizon tasks (e.g.,
StairClimber,FourCorner,Harvester) solvable in under 200 steps and 45 tokens. - KAREL-HARD Benchmark: 4 structurally complex tasks (
DoorKey,OneStroke,Seeder,Snake) requiring 45–120 tokens and up to 500 actions. - KAREL-LONG Benchmark (New): Introduced by the authors to test extended horizons requiring thousands of steps and repetitive looping:
Seesaw: Navigating back-and-forth through corridors between two distant chambers.Up-N-Down: Ascending and descending stairs repeatedly under movement penalties.Farmer: Alternating cycles of completely seeding a grid with markers and harvesting them.Inf-DoorKey&Inf-Harvester: Indefinite chamber traversal and probabilistic marker respawning.
Key Insights and Ideas
- Compatibility is critical for modular programs: Simply finding diverse, high-reward programs independently leads to sub-policies that conflict (e.g., ending in deadlocks or unrecoverable states). Evaluating candidate programs sandwiched within execution chains during search produces naturally composable skills.
- Temporal abstraction through programs: Treating entire looping programs (rather than primitive single-step actions) as state-machine modes dramatically compresses the effective decision horizon for the high-level policy.
- Zero-shot inductive generalization: Because looping logic is encapsulated in the programs and state machine transitions govern cycles, POMPs generalize to horizon lengths $2\times$ to $16\times$ larger than seen during training (running up to 500,000 steps) with minimal performance degradation.
Key Results
- KAREL-LONG Tasks: POMP substantially outperforms deep RL, programmatic RL (LEAPS, HPRL), and primitive state machines (PSMP):
Seesaw: POMP achieves 0.90 ± 0.02 return vs. 0.00 for DRL and 0.25 for PSMP.Up-N-Down: POMP achieves 0.97 ± 0.00 vs. 0.00 for DRL/HPRL and 0.38 for LEAPS.Farmer: POMP achieves 0.88 ± 0.01 vs. 0.55 for DRL and 0.40 for HPRL.- Ablations on Retrieval: CEM + diversity + compatibility consistently outperformed vanilla CEM ($\times |M|$) and CEM + diversity alone (e.g., on
Farmer, reaching 0.88 vs. 0.22–0.24). - Inductive Generalization: When test horizons were expanded up to $16\times$ on
FarmerandInf-DoorKey, competing methods plummeted by 60–100%, while POMP’s performance remained nearly flat.
Limitations and Future Work
- Domain Dependence: The approach is evaluated solely within the Karel DSL grid world. Extending to robotics, continuous control, or text-based environments requires defining expressive, domain-specific DSLs.
- Non-repetitive, Dense Planning Tasks: POMP struggles on tasks like
OneStroke(0.62) andSnake(0.36), where precise global path planning and collision avoidance dominate over repetitive subroutine switching. - Two-Stage Disconnection: Mode program synthesis and transition learning are decoupled. Developing an end-to-end framework where mode synthesis adapts dynamically to transition learning remains an open challenge.
Summary updated