Graph Neural Networks For Mapping Variables Between Programs - Extended Version

Pedro Orvalho, Jelle Piepenbrock, Mikolás Janota, Vasco ManquinhoarXiv 2023 · DOI

Introduction

Automated program repair (APR) holds significant promise for scaling personalized feedback in introductory computer science courses. However, existing tools often struggle with the structural diversity of student code. This paper presents a novel approach using Relational Graph Convolutional Networks (RGCNs) to map variables between a student's buggy submission and a correct reference implementation. By prioritizing variable usage patterns over rigid code structure, this method achieves an 88.5% repair rate, significantly outperforming current state-of-the-art tools.

The Challenge of Structural Mismatch

Traditional APR tools like CLARA and VERIFIX typically rely on matching Control Flow Graphs (CFGs). This requirement creates a "structural bottleneck": if a student implements a solution using a while loop and helper functions while the reference uses a simple for loop, the tools often fail to find a correspondence. Furthermore, these tools are sensitive to variable naming and the exact number of variables used. To overcome this, a robust system must perform variable mapping—identifying semantic equivalents between programs regardless of their names or surrounding syntax.

Methodology: A Name-Agnostic Graph Representation

The core innovation is a program representation that captures data flow and hierarchical relationships through a specialized graph. Unlike a standard Abstract Syntax Tree (AST), this representation introduces a central "Variable Node" for each unique variable in the program.

Comparison between a standard AST and the proposed graph representation for the code snippet `a = a - b`.

To capture the nuances of program logic, the authors utilize five distinct edge types:

  • AST/Child: Standard hierarchical relationships.
  • Sibling: Maintains the order of arguments in function calls or expressions.
  • Read/Write: Connects variable occurrences to their central Variable Node based on access type.
  • Chronological: Links variable occurrences in the order they appear in the source code.

Using these graphs, an RGCN generates numerical embeddings for every variable node. The model then predicts the most likely mapping between variables in the buggy and correct programs by calculating the dot product between these embeddings. This name-agnostic approach allows the model to learn what a variable does rather than what it is called.

Experimental Results

The model was evaluated using the C-PACK-IPAS dataset, comprising real-world student submissions from an introductory C course. The evaluation involved 4,166 pairs of incorrect and correct programs, with bugs systematically injected to simulate common novice errors such as wrong comparison operators, variable misuse, and missing expressions.

Mapping and Repair Performance

The GNN correctly mapped all variables in 83% of the evaluation pairs, with an overall overlap coefficient (measuring partial correctness) exceeding 94%. This high mapping accuracy translated directly into superior repair performance.

Repair performance comparison: The GNN-based approach repairs significantly more programs in less time compared to state-of-the-art tools like Clara and Verifix.

As shown in the performance analysis, the GNN approach repaired 88.5% of the buggy programs, substantially outperforming VERIFIX (~62%) and CLARA (~72%). Notably, the mapping process is highly efficient, taking an average of only 0.025 seconds per program pair.

Discussion and Future Work

Ablation studies revealed that AST and Sibling edges are the most critical features; removing AST edges caused mapping accuracy to drop from 96% to 53%. While the model is highly effective, its performance scales inversely with the number of variables, showing increased difficulty with programs containing more than six variables.

Future work aims to expand the repair logic beyond the three targeted bug types to handle more complex algorithmic flaws. Additionally, integrating this variable mapping technique into existing CFG-based APR tools could help them overcome structural mismatch limitations, leading to more robust automated tutoring systems.

Summary updated

BibTeX
@misc{orvalho2023graph,
  author = {Pedro Orvalho and Jelle Piepenbrock and Mikolás Janota and Vasco Manquinho},
  title = {{Graph Neural Networks For Mapping Variables Between Programs - Extended Version}},
  year = {2023},
  eprint = {2307.13014},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.13014},
}
Figure