Skip to content

perf(julia_helpers): check for Julia functions with isa - #1395

Merged
MilesCranmer merged 2 commits into
astroautomata:masterfrom
MilesCranmerBot:perf/isa-function-check
Sep 28, 2026
Merged

MilesCranmer merged 2 commits into
astroautomata:masterfrom
MilesCranmerBot:perf/isa-function-check

Conversation

@MilesCranmerBot

Copy link
Copy Markdown
Contributor

These PySR changes pair with the SymbolicRegression.jl PRs astroautomata/SymbolicRegression.jl#739 through #742, which compile PySR's search and PythonCall conversions at install time. Each PySR PR works on its own with the current SymbolicRegression.jl. The full speedup arrives once those PRs are released and PySR's version bound is raised.

Why

jl_is_function evaluated a new anonymous Julia function (op -> op isa Function) each time it was called, and Julia compiled each one. Calling isa directly avoids that.

Scope

  • pysr/julia_helpers.py: jl_is_function calls jl.isa(f, jl.Function).

Verification

Zero-iteration first fit 2.91 s to 2.83 s. The README example's first fit did not change beyond noise.

With all seven PRs applied, on a 12-core Slurm node (Julia 1.13.1, Python 3.13), the README example's first fit went from 17.4 s to 6.95 s, and a zero-iteration first fit from 12.6 s to 2.71 s. pysr/test/test_main.py and pysr/test/test_type_specs.py pass (254 passed, 1 skipped). The pre-commit hooks pass.

Call `isa(op, Function)` directly instead of compiling a new anonymous
Julia function for each validation.

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@MilesCranmer
MilesCranmer enabled auto-merge (squash) September 28, 2026 08:54
@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MilesCranmer
MilesCranmer enabled auto-merge (squash) September 28, 2026 18:09
@MilesCranmer
MilesCranmer merged commit bfba1b6 into astroautomata:master Sep 28, 2026
67 of 81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants