Review of PySR: high-performance symbolic regression in Python and Julia

Alberto TondaGenet. Program. Evolvable Mach 2025

Introduction

Symbolic Regression (SR) represents a unique paradigm in machine learning that prioritizes interpretability alongside predictive power. Unlike "black-box" models such as deep neural networks, SR searches the vast space of mathematical expressions to discover the simplest equation that accurately describes a given dataset. However, this search process is computationally intensive, as the space of possible equations is effectively infinite. Historically, researchers faced a trade-off: use slow, pure-Python implementations that were easy to integrate into data science workflows, or adopt high-performance C++ or Java tools that were difficult to customize and maintain.

PySR (version 0.19.4) addresses this dilemma by providing a high-performance symbolic regression library that bridges the gap between Python's accessibility and Julia's raw computational speed. By leveraging a Julia-based backend, PySR offers a "best of both worlds" solution for modern scientific discovery.

Architecture and Methodology

PySR utilizes a hybrid architecture designed for both performance and ease of use. The user interacts with a Python front-end that is fully compatible with the scikit-learn API. This allows PySR to be seamlessly integrated into existing machine learning pipelines using standard methods like .fit() and .predict().

Under the hood, the library offloads the heavy lifting to SymbolicRegression.jl, a highly optimized Julia engine. The core of this engine is an evolutionary algorithm that employs several sophisticated techniques:

  • Multi-population "Island" Scheme: PySR parallelizes function evaluations across multiple CPU cores. It evolves separate populations independently, with occasional "migrants" exchanged between islands to maintain genetic diversity and prevent premature convergence.
  • Pareto Optimization: Rather than returning a single model, PySR tracks a Pareto front—a set of equations representing the optimal trade-offs between mathematical complexity and accuracy. This allows researchers to choose the model that best fits their specific needs for simplicity or precision.
  • Extensibility: Users can define custom binary and unary operators, loss functions, and structural constraints (such as maximum nesting depth) directly within the Python interface.
Example of PySR usage in Python, demonstrating its scikit-learn compatible API and integration with Julia-based operators.

Performance and Practical Insights

In practical applications, PySR has demonstrated the ability to recover complex synthetic equations, such as $y = 2.5382 \cdot \cos(x_3) + x_0^2 - 0.5$, from relatively small datasets. Its integration with the broader Python ecosystem is a significant advantage; discovered equations can be exported directly to SymPy for symbolic manipulation (differentiation, simplification) or to LaTeX for publication.

When compared to pure C++ implementations like Operon, PySR exhibits a performance trade-off. In benchmarks involving 100,000 evaluations, Operon completed the task in 0.04 seconds, while PySR took approximately 7 seconds. However, the developers argue that the use of Julia makes the codebase significantly more accessible for researchers to modify and extend compared to low-level C++. For most scientific research applications, the gain in flexibility and ease of use outweighs the absolute speed advantage of C++.

Limitations and Future Outlook

Despite its strengths, PySR faces several challenges common to hybrid-language tools:

  1. Reproducibility: The complexities of multi-core parallel processing mean that fixing a random seed does not currently guarantee identical results across different runs when using multiple cores.
  2. The "Julia String" Problem: Custom functions must be defined as Julia code within Python strings. This prevents Python IDEs from providing syntax highlighting or error checking, making debugging more difficult for users unfamiliar with Julia syntax.
  3. Model Selection: The automated heuristics used to select the "best" model from the Pareto front can occasionally overlook superior candidates that a human researcher might prefer for their physical meaning or structural simplicity.

Future development is expected to focus on tightening the integration between Python and Julia to improve the debugging experience and further optimizing the evolutionary engine to narrow the performance gap with C++ implementations. As a core component of the SRBench benchmarking effort, PySR continues to be a pivotal tool for the symbolic regression community.

Summary updated

BibTeX
@article{tonda2025review,
  author = {Alberto Tonda},
  title = {{Review of PySR: high-performance symbolic regression in Python and Julia}},
  journal = {Genet. Program. Evolvable Mach},
  year = {2025},
  doi = {10.1007/s10710-024-09503-4},
}
Figure