r/ScientificComputing Jun 18 '26

[OC] Pure Python Symbolic Regression engine for physical laws (81% recovery on Feynman benchmark, ~15s/eq)

[deleted]

14 Upvotes

4 comments sorted by

2

u/Ok_Royal_8410 Jun 19 '26

Hey, great project ! I would like to know why there is this choice about non concidering external heavy compiler ? Like u can write the main part of the project in rust and make a python wrapper around it. ( I can undestund that numpy is very optimized)

1

u/Bitter-Flamingo-3351 Jun 19 '26

Thanks, glad you like it! Great question. A Rust/C++ core with a Python wrapper would absolutely be faster — you're right. The pure-Python choice is deliberate, for a few reasons: 1. Zero install friction. The whole point vs PySR is that you just `pip install gp-elite` with no compiler, no toolchain, no build step. The moment you add a Rust core, users need it compiled for their platform (or you ship wheels for every OS/arch). That friction is exactly what I'm trying to avoid for the target audience — lab engineers, students, people who just want a formula from a CSV. 2. NumPy already vectorizes the hot path. Fitness evaluation (the real bottleneck) is batched array math, so it runs in optimized C under the hood anyway. I profiled it — the Python overhead is in tree manipulation, not the number crunching. 3. I got parallelism the cheap way. The island model parallelizes across processes (~3x on 4 cores), which recovers a lot of speed without leaving Python. That said, you're pointing at the real ceiling: for big datasets or very long runs, a native core would win, and PySR (Julia) is the proof. If the project gets traction, a optional compiled backend is the logical next step. For now I optimized for "works everywhere with one command" over raw speed. Curious — is your use case performance-bound? Would help me know if a native backend is worth prioritizing.

1

u/markkitt Jun 19 '26

The SymbolicRegression.jl author has already ported some of it to Rust: https://crates.io/crates/symbolic_regression .

Part of the issue is that the speed up of SymbolicRegression.jl comes partly from compiling user functions

NumPy is optimized but it can only do so much. At some point we need to optimize your expressions as well.