Learning compositional programs with arguments and sampling

Giovanni De Toni, Luca Erculiani, Andrea Passerini

TL;DR

This paper extends AlphaNPI—a neural program synthesis framework that uses Monte Carlo Tree Search (MCTS) to learn programs without execution traces—by enabling subroutines to accept arguments. By introducing an argument policy network and an approximate MCTS variant, the authors train an agent to synthesize a classic non-trivial algorithm, Quicksort, which previous architectures failed to learn.

What Problem Does This Paper Address?

Synthesizing programs purely from input-output examples remains a holy grail in machine learning. While neural program interpreters (such as NPI and AlphaNPI) can learn algorithmic tasks hierarchically, they historically operate over rigid domain-specific languages lacking core programming abstractions like variables or function arguments.

Without arguments, an agent must treat every variation of an operation (e.g., move_pointer_1 vs. move_pointer_2) as a completely separate atomic action. As algorithms scale in complexity, this creates a combinatorial explosion of the action space, rendering search intractable and preventing models from learning complex, parameter-dependent algorithms like Quicksort.

Methods

The authors build directly on AlphaNPI, which combines a neural controller (LSTM) with recursive MCTS to autonomously generate execution traces during training. They introduce several key modifications:

  • Argument Network ($f_{\text{arguments}}$): Alongside the standard program policy ($\pi_p$) and value network ($f_{\text{value}}$), an additional module predicts a probability distribution $\pi_a$ over function arguments (e.g., up to three pointer variables or an "empty" placeholder).
  • Joint Training Loss: The loss function optimizes cross-entropy over both program selection ($l_{\text{policy}}$) and argument selection ($l_{\text{arguments}}$) against MCTS visit frequencies, alongside value MSE ($l_{\text{value}}$).
  • Approximate MCTS (A-MCTS): Because combining discrete actions with discrete argument combinations drastically widens the branching factor, A-MCTS samples only a small subset $n$ of program-argument pairs (perturbed with Dirichlet noise) during node expansion rather than evaluating all combinations.
  • Curriculum & Failure Buffer: The model trains bottom-up over a hierarchy of subroutines (e.g., partition_update $\to$ partition $\to$ quicksort_update $\to$ quicksort). Failed environment states are stored in a buffer ($e_{\text{failed}}$) and re-sampled with probability $\epsilon$ to prevent the agent from ignoring hard corner cases.
  • Handcrafted Pre-conditions: Deterministic boolean constraints enforce validity before executing actions (e.g., ensuring pointers stay within list bounds).

Datasets

  • Quicksort Environment: Synthetic lists of integers constrained between values 0 and 10.
  • Training Data: Short lists varying from 2 to 7 elements.
  • Evaluation & Out-of-Distribution Generalization: Evaluated on lists of lengths 5, 10, 20, 40, and 60 (50 randomly generated lists per length).

Key Insights and Ideas

  • Decoupling Operations from Operands: Splitting program selection from argument selection avoids the exponential bloat of creating distinct actions for every possible parameter permutation (e.g., defining generic swap(p1, p2) instead of multiple dedicated swapping primitives).
  • Quicksort as an Argument-Driven Benchmark: Simpler sorting algorithms like Bubblesort can get by with hardcoded pointer updates, but recursive divide-and-conquer routines inherently rely on passing dynamic pointers, making Quicksort an ideal stress test.
  • Exploration vs. Stability Trade-off in Search: While A-MCTS successfully pruned large search trees to speed up node expansion for low-level tasks, it suffered from instability on higher-level subroutines, showing that aggressive tree pruning can risk dropping critical sparse execution paths.

Key Results

The authors evaluated four variants: baseline AlphaNPI ($M_{\text{alphanpi}}$), baseline with A-MCTS ($M^s_{\text{alphanpi}}$), the proposed argument-aware model ($M_{\text{alphaargs}}$), and the proposed model with A-MCTS ($M^s_{\text{alphaargs}}$).

  • Full Quicksort Learning: Only the proposed model with exact MCTS ($M_{\text{alphaargs}}$) successfully learned the complete Quicksort hierarchy. It reached 100% accuracy on list length 5.
  • Length Generalization: Despite only training on lists of up to 7 elements, $M_{\text{alphaargs}}$ generalized to longer unseen lists:
  • Length 10: 66%
  • Length 20: 42%
  • Length 40: 22%
  • Length 60: 2%
  • Baselines Failed Completely: Both $M_{\text{alphanpi}}$ and $M^s_{\text{alphanpi}}$ achieved 0% accuracy on lists of length 10 or greater for the full Quicksort routine (and only 10% and 2% respectively on length 5).

Limitations and Future Work

  • Arguments Limited to Atomic Actions: Currently, arguments are only passed down to level-0 atomic actions; higher-level recursive programs still default to "empty" arguments due to the absence of local variable scoping and independent execution contexts.
  • Handcrafted Preconditions: The environment still relies on human-specified preconditions to prune illegal transitions, rather than discovering safety rules autonomously.
  • Generalization Drop-off: Accuracy degrades substantially as list lengths grow toward 60, largely due to compound pointer errors accumulating over longer execution traces.
  • A-MCTS Instability: The approximate search mechanism struggled to reliably synthesize higher-level routines, requiring better sampling strategies before it can replace standard MCTS.

Summary updated

BibTeX
@inproceedings{toni2021learning,
  author = {Giovanni De Toni and Luca Erculiani and Andrea Passerini},
  title = {{Learning compositional programs with arguments and sampling}},
  booktitle = {AIPLANS @ NeurIPS},
  year = {2021},
  url = {https://openreview.net/forum?id=KUWjNgo2Gm9},
}

Loading related content...

Figure