# astroautomata/pysr architecture

> Architecture diagram of the GitHub repository astroautomata/pysr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/astroautomata/pysr
- Repository: https://github.com/astroautomata/pysr

## Overview

PySR is a Python-facing symbolic-regression product backed by the Julia SymbolicRegression search engine. The main workflow configures a regressor, fits it to feature/target data, runs the search, retains and selects candidate equations, and exposes predictions and export formats. The graph includes documented auxiliary capabilities for denoising and feature selection. Source excerpts are partial, so links to those auxiliary subsystems and some persistence details are not asserted where their wiring was not shown.

Main entry points: [`pysr/sr.py`](https://github.com/astroautomata/pysr/blob/master/pysr/sr.py) (Regressor), [`pysr/__init__.py`](https://github.com/astroautomata/pysr/blob/master/pysr/__init__.py) (Public API), [`pysr/julia_import.py`](https://github.com/astroautomata/pysr/blob/master/pysr/julia_import.py) (Julia Bootstrap), [`pysr/julia_helpers.py`](https://github.com/astroautomata/pysr/blob/master/pysr/julia_helpers.py) (Julia Helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Python Interface"]
  node_regressor["Regressor<br/>[sr.py]"]
  node_python_api["Public API<br/>[__init__.py]"]
end

subgraph group_search["Search Configuration"]
  node_expressions["Expression Specs"]
  node_type_specs["Type Specs<br/>[type_specs.py]"]
  node_mutations["Mutation Config<br/>[mutations.py]"]
end

subgraph group_engine["Julia Search"]
  node_julia_bootstrap["Julia Bootstrap<br/>[julia_import.py]"]
  node_julia_helpers["Julia Helpers<br/>[julia_helpers.py]"]
end

subgraph group_results["Results and Exports"]
  node_equation_results["Equation Results<br/>[sr.py]"]
  node_checkpoint[("Search Checkpoint<br/>[sr.py]")]
  node_numpy_export["NumPy Export<br/>[export_numpy.py]"]
  node_sympy_export["SymPy Export<br/>[export_sympy.py]"]
  node_jax_export["JAX Export<br/>[export_jax.py]"]
  node_torch_export["PyTorch Export<br/>[export_torch.py]"]
  node_latex_export["LaTeX Export<br/>[export_latex.py]"]
end

subgraph group_extensions["Model Extensions"]
  node_denoising["Denoising<br/>[denoising.py]"]
  node_feature_selection["Feature Selection"]
  node_plugins["Plugins<br/>[plugins.py]"]
end

node_user(("Python User"))
node_data["Training Data"]
node_search_engine{{"SymbolicRegression.jl"}}

node_user -->|"uses"| node_python_api
node_python_api -->|"exposes"| node_regressor
node_data -->|"fits"| node_regressor
node_regressor -->|"configures"| node_expressions
node_regressor -->|"validates"| node_type_specs
node_regressor -->|"converts"| node_mutations
node_regressor -->|"initializes"| node_julia_bootstrap
node_regressor -->|"converts data"| node_julia_helpers
node_julia_helpers -->|"bridges values"| node_search_engine
node_julia_bootstrap -->|"loads"| node_search_engine
node_regressor -->|"runs search"| node_search_engine
node_search_engine -->|"returns search state"| node_regressor
node_regressor -->|"selects equations"| node_equation_results
node_regressor -->|"saves state"| node_checkpoint
node_regressor -->|"builds exports"| node_numpy_export
node_regressor -->|"builds exports"| node_sympy_export
node_regressor -->|"builds exports"| node_jax_export
node_regressor -->|"builds exports"| node_torch_export
node_regressor -->|"formats equations"| node_latex_export

click node_regressor "https://github.com/astroautomata/pysr/blob/master/pysr/sr.py"
click node_python_api "https://github.com/astroautomata/pysr/blob/master/pysr/__init__.py"
click node_julia_bootstrap "https://github.com/astroautomata/pysr/blob/master/pysr/julia_import.py"
click node_julia_helpers "https://github.com/astroautomata/pysr/blob/master/pysr/julia_helpers.py"
click node_expressions "https://github.com/astroautomata/pysr/blob/master/pysr/expression_specs.py"
click node_type_specs "https://github.com/astroautomata/pysr/blob/master/pysr/type_specs.py"
click node_mutations "https://github.com/astroautomata/pysr/blob/master/pysr/mutations.py"
click node_equation_results "https://github.com/astroautomata/pysr/blob/master/pysr/sr.py"
click node_checkpoint "https://github.com/astroautomata/pysr/blob/master/pysr/sr.py"
click node_numpy_export "https://github.com/astroautomata/pysr/blob/master/pysr/export_numpy.py"
click node_sympy_export "https://github.com/astroautomata/pysr/blob/master/pysr/export_sympy.py"
click node_jax_export "https://github.com/astroautomata/pysr/blob/master/pysr/export_jax.py"
click node_torch_export "https://github.com/astroautomata/pysr/blob/master/pysr/export_torch.py"
click node_latex_export "https://github.com/astroautomata/pysr/blob/master/pysr/export_latex.py"
click node_denoising "https://github.com/astroautomata/pysr/blob/master/pysr/denoising.py"
click node_feature_selection "https://github.com/astroautomata/pysr/blob/master/pysr/feature_selection.py"
click node_plugins "https://github.com/astroautomata/pysr/blob/master/pysr/plugins.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_regressor,node_python_api,node_user toneBlue
class node_expressions,node_type_specs,node_mutations toneAmber
class node_julia_bootstrap,node_julia_helpers toneMint
class node_equation_results,node_checkpoint,node_numpy_export,node_sympy_export,node_jax_export,node_torch_export,node_latex_export toneRose
class node_denoising,node_feature_selection,node_plugins,node_data,node_search_engine toneIndigo
```

## Components

### Python Interface

- [Regressor](https://github.com/astroautomata/pysr/blob/master/pysr/sr.py): `pysr/sr.py`
- [Public API](https://github.com/astroautomata/pysr/blob/master/pysr/__init__.py): `pysr/__init__.py`

### Search Configuration

- [Expression Specs](https://github.com/astroautomata/pysr/blob/master/pysr/expression_specs.py): `pysr/expression_specs.py`
- [Type Specs](https://github.com/astroautomata/pysr/blob/master/pysr/type_specs.py): `pysr/type_specs.py`
- [Mutation Config](https://github.com/astroautomata/pysr/blob/master/pysr/mutations.py): `pysr/mutations.py`

### Julia Search

- [Julia Bootstrap](https://github.com/astroautomata/pysr/blob/master/pysr/julia_import.py): `pysr/julia_import.py`
- [Julia Helpers](https://github.com/astroautomata/pysr/blob/master/pysr/julia_helpers.py): `pysr/julia_helpers.py`

### Results and Exports

- [Equation Results](https://github.com/astroautomata/pysr/blob/master/pysr/sr.py): `pysr/sr.py`
- [Search Checkpoint](https://github.com/astroautomata/pysr/blob/master/pysr/sr.py): `pysr/sr.py`
- [NumPy Export](https://github.com/astroautomata/pysr/blob/master/pysr/export_numpy.py): `pysr/export_numpy.py`
- [SymPy Export](https://github.com/astroautomata/pysr/blob/master/pysr/export_sympy.py): `pysr/export_sympy.py`
- [JAX Export](https://github.com/astroautomata/pysr/blob/master/pysr/export_jax.py): `pysr/export_jax.py`
- [PyTorch Export](https://github.com/astroautomata/pysr/blob/master/pysr/export_torch.py): `pysr/export_torch.py`
- [LaTeX Export](https://github.com/astroautomata/pysr/blob/master/pysr/export_latex.py): `pysr/export_latex.py`

### Model Extensions

- [Denoising](https://github.com/astroautomata/pysr/blob/master/pysr/denoising.py): `pysr/denoising.py`
- [Feature Selection](https://github.com/astroautomata/pysr/blob/master/pysr/feature_selection.py): `pysr/feature_selection.py`
- [Plugins](https://github.com/astroautomata/pysr/blob/master/pysr/plugins.py): `pysr/plugins.py`

### Other components

- **Python User**
- **Training Data**
- **SymbolicRegression.jl**

## Connections

- Python User → Public API: uses
- Public API → Regressor: exposes
- Training Data → Regressor: fits
- Regressor → Expression Specs: configures
- Regressor → Type Specs: validates
- Regressor → Mutation Config: converts
- Regressor → Julia Bootstrap: initializes
- Regressor → Julia Helpers: converts data
- Julia Helpers → SymbolicRegression.jl: bridges values
- Julia Bootstrap → SymbolicRegression.jl: loads
- Regressor → SymbolicRegression.jl: runs search
- SymbolicRegression.jl → Regressor: returns search state
- Regressor → Equation Results: selects equations
- Regressor → Search Checkpoint: saves state
- Regressor → NumPy Export: builds exports
- Regressor → SymPy Export: builds exports
- Regressor → JAX Export: builds exports
- Regressor → PyTorch Export: builds exports
- Regressor → LaTeX Export: formats equations
