MilesCranmer / PySR

High-Performance Symbolic Regression in Python and Julia
https://astroautomata.com/PySR
Apache License 2.0
2.09k stars 197 forks source link

[Feature]: Make sympy2torch export functions, not objects #435

Open MilesCranmer opened 9 months ago

MilesCranmer commented 9 months ago

Feature Request

Right now sympy2jax is functional. It returns a dictionary containing a function and some parameters. However, sympy2torch is object-oriented. It returns a module.

I think the functional approach is a bit simpler so would reduce maintenance burden. From my experience trying to add sympy.Piecewise in #433, it's quite a bit of work. Therefore, for torch export, you would basically have a tensor of parameters and a function that takes that tensor and an array input. So you could do what you like with that, including putting it inside a class. But it's harder to go the other way, from an exported object back to a function.

The functional approach is also better for MCMC'ing parameters, which you can't really do with the PyTorch export right now.