Abstract
We consider the task of program synthesis in the presence of a reward function over the output of programs, where the goal is to find programs with maximal rewards. We employ an iterative optimization scheme, where we train an RNN on a dataset of K best programs from a priority queue of the generated programs so far. Then, we synthesize new programs and add them to the priority queue by sampling from the RNN. We benchmark our algorithm, called priority queue training (or PQT), against genetic algorithm and reinforcement learning baselines on a simple but expressive Turing complete programming language called BF. Our experimental results show that our simple PQT algorithm significantly outperforms the baselines. By adding a program length penalty to the reward function, we are able to synthesize short, human readable programs.
Introduction
Program synthesis—the automatic generation of code to satisfy specific requirements—remains a significant challenge in artificial intelligence. The search space for valid programs is massive and combinatorial, while the reward signal is often sparse or binary. Traditional methods frequently rely on hand-crafted heuristics or extensive "ground-truth" datasets. This research introduces Priority Queue Training (PQT), an iterative optimization method designed to synthesize source code in expressive, Turing-complete languages using only a reward signal.
Methodology: Priority Queue Training
The core of the proposed system is a 2-layer LSTM Recurrent Neural Network (RNN) acting as a generative model. This model emits characters of the target programming language in an autoregressive manner.
The PQT algorithm operates through a three-step iterative loop:
- Queue Management: A priority queue maintains the $K$ highest-reward programs discovered throughout the training process.
- Training: The RNN is trained via maximum likelihood to imitate the programs currently stored in the priority queue. This "hall of fame" approach provides stable, high-quality targets for the model.
- Sampling and Update: The RNN samples new programs, which are then executed and scored. Any programs that outperform existing entries in the queue are added, and the cycle repeats.
To encourage efficiency, the authors incorporate a program length penalty into the reward function, promoting the synthesis of concise, "human-readable" code.
Experimental Setup
The method was evaluated using BF, a minimalist, Turing-complete language consisting of only eight commands. BF's simplicity makes it an ideal research sandbox; its syntax ensures that almost any character sequence is a valid program, preventing the search from being stalled by frequent syntax errors. The benchmark suite consists of 25 algorithmic tasks, ranging from string manipulation (e.g., reverse, remove-char) to arithmetic operations (e.g., add, divide-2).
Results and Discussion
Experimental results indicate that PQT is a robust search algorithm that significantly outperforms standard Reinforcement Learning (RL) and Genetic Algorithm (GA) baselines.
Across the 25 tasks, PQT achieved an average success rate of 13.0, compared to 8.6 for the Genetic Algorithm and 3.3 for vanilla Policy Gradient. PQT also demonstrated superior efficiency, requiring fewer program executions to reach successful solutions.
A key insight from the study is that PQT provides stability. While standard Policy Gradient methods often suffer from high variance or "catastrophic forgetting," the priority queue acts as a persistent memory, anchoring the model to successful strategies. Furthermore, the length penalty successfully induced "code golf" behavior, where the model learned to produce efficient, non-redundant code.
Limitations and Future Work
Despite its success, the model occasionally exhibited overfitting, finding "hacks" that satisfied specific test cases without implementing a truly general algorithm. Additionally, scaling PQT to higher-level languages like Python remains a challenge due to more complex syntax and the resulting increase in syntax errors. Future research will focus on improving generalization and adapting PQT for more complex programming environments.
Summary updated