Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unitful.jl integration #179

Closed
MilesCranmer opened this issue Mar 9, 2023 · 2 comments
Closed

Unitful.jl integration #179

MilesCranmer opened this issue Mar 9, 2023 · 2 comments
Assignees
Labels
feature (importance: mid) Mid-importance feature

Comments

@MilesCranmer
Copy link
Owner

For the past few years by far the most requested feature in SymbolicRegression.jl & PySR has been a way of checking whether expressions are dimensionally correct. I have not looked at adding this yet because I argue that unknown constants could have units that simply cancel out units in your expressions - thus obviating the need. However I definitely see some use-cases where this could be very useful, especially if you wish to not allow learning new constants (e.g., you simply want to pass a set of constants and set complexity_of_constants=100, say).

I think the easiest way of doing this is to integrate Unitful.jl (h/t @tfiers for recommendation). An example API could be:

options = Options()
hall_of_fame = equation_search(X, y; options, var_names=["v", "a"], units=["m/s", "m/s^2"])

These units could be stored in the Dataset object. Then, adding another step to check_constraints, you could basically see whether an expression is dimensionally correct. You would require that + and - maintain the same units as their input, * and / propagate units, and all other operators require dimensionless inputs. When there is a constant in an expression, you could have some sort of "wildcard" units, and do a solve to see whether such units exist. This might be the most expensive part though...

@tfiers @ChrisRackauckas do you know if there is a way to have some sort of "wildcard" units, and solve for them, using Unitful.jl?

@MilesCranmer MilesCranmer added the feature (importance: mid) Mid-importance feature label Mar 9, 2023
@MilesCranmer
Copy link
Owner Author

Actually this might be easier than I thought.

You could create a new unit, say "wildcard". Then recursively evaluate an expression and aggregate units. When you hit a * or /, you would combine units, and, if there is any wildcard, you simply combine it with the units. When you get to an operator that requires dimensionless input, you would first check whether there is a wildcard in the units. If there is, you are safe. Otherwise, you would see whether the units simplify or not.

Likewise for + and -: if any wildcard at all, you are safe. Otherwise, you check whether the units are compatible!

@MilesCranmer MilesCranmer self-assigned this Mar 9, 2023
@MilesCranmer
Copy link
Owner Author

Added with #228 (not Unitful.jl, but DynamicQuantities.jl)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature (importance: mid) Mid-importance feature
Projects
None yet
Development

No branches or pull requests

1 participant