Skip to content

Python Synthesis

Open In Colab

Program Synthesis with PythonSynthesis + OMEGA

This example evolves a Python program to solve an ARC-AGI task.

Unlike a Generator, where the trainable state is a prompt and the LM runs on every prediction, a PythonSynthesis module's trainable state is a Python script. At inference time there is no LM at all: the script runs in the Monty sandbox and transforms the input JSON into the output JSON. The language model only appears during fit, where the OMEGA optimizer uses it to author and refine the script across generations (mutation + crossover), keeping a diverse population alive with Dominated Novelty Search.

Pipeline:

  1. Load an ARC-AGI task (input_grid -> output_grid).
  2. Build a PythonSynthesis program seeded with an identity script.
  3. Run the seed offline to see the starting point (it just echoes the input, so it scores 0 unless the rule is the identity).
  4. (Optional) Evolve the script with OMEGA, then read the learned algorithm straight off the trainable variable.

OMEGA needs both a language_model (writes the code) and an embedding_model (measures candidate novelty for DNS). ARC-AGI is hard: the goal here is to show the wiring, not to guarantee a solve. Use a strong code model for serious attempts.

API References

grid_str(grid)

Render a small integer grid as text for printing.

Cells may be plain ints (from the sandbox, via JSON) or Color enum members (from the typed ground-truth DataModel); coerce to int so both sides print identically.

Source code in examples/22_python_synthesis.py
def grid_str(grid):
    """Render a small integer grid as text for printing.

    Cells may be plain ints (from the sandbox, via JSON) or `Color` enum
    members (from the typed ground-truth DataModel); coerce to int so
    both sides print identically.
    """
    return "\n".join(" ".join(str(int(c)) for c in row) for row in grid)

Source

--8 < --"examples/22_python_synthesis.py:source"