feat: add runtime TypeSpec support - #1280
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@MilesCranmerBot please address the above |
|
@MilesCranmerBot also we need 100% diff coverage |
|
Addressed in 9601b5a:
Checks: normal numeric regression test passes; TypeSpec direct-instantiation coverage is 100%. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69d5b4ded4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
0069e72 to
0bfdb21
Compare
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
for more information, see https://pre-commit.ci
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
`names(...; all=true)` reports gensym symbols such as `#1#2` for the anonymous functions in a TypeSpec module. Copying those into the configuration module reserved the same names that Julia 1.11 assigns to that module's own closures, so loading any configuration failed with an invalid constant redefinition. Also correct the runtime boundary annotations for numeric early stopping and the search output tuple. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
b94051c to
6667c13
Compare
A configuration source that raised left the module holding the constants for the sources that had already run, so retrying the same definition redefined them and failed on Julia 1.10 and 1.11. Replace the module on every install and stop binding the per-source values, which nothing read. Also state what a preamble shares with configuration sources. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
SymbolicRegression wraps the equation in quotes without escaping its contents, so an equation holding a string constant is not valid CSV: pandas either raises or shifts a later field into the complexity column, which then fails arithmetic. The file has three columns in a fixed order, so read the equation as the rest of the line. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
for more information, see https://pre-commit.ci
The fixtures wrote a leading index column, so the file had four fields where the Julia writer emits three, and the equation was read as the last two. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
SymbolicRegression 2.0.0-beta.8 escapes quotes in the equation column, so the file is valid CSV and the hand-rolled reader added for beta.7 is unnecessary. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
A type module that failed partway stayed defined in Main, so every later load skipped reinstall and failed with a missing binding. Mark the module as installed with its last statement and reinstall whenever that marker is absent. Evaluating an expression through its callable let DynamicExpressions fill the output with NaN, which cannot convert to a generated type. Evaluate with eval_tree_array and report the rejected value instead. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
The parameter test only checked fingerprint stability, so nothing proved that a parameter holding a TypeSpec value actually changes during a search. Fit a model whose only route to zero loss is the mutate hook rewriting the parameter, and document how parameters are created, mutated, and optimized. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01e998d528
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
TypeSpec and TemplateExpressionSpec models hold live Julia objects in `julia_expression` and `lambda_format`, which cannot be revived in a fresh Julia session. Drop both columns for either spec when pickling and rebuild them from the search output whenever equations are accessed, so `get_best`, `from_file`, and the export helpers all work after a restore instead of only `predict`. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Every error branch reported uncovered by codecov on this PR now runs under the test suite: spec and configuration validation, fit and prediction data validation, array conversion failures, the runtime value-ordering guard, warm-start toggling, and the fitted-model score/predict guards. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Summary
TypeSpec(name, fields, sample, ...)for symbolic regression over custom Julia value typesmutateand continuous constant optimization throughscalar_constantsandwith_scalar_constantsOperatorEnumevaluation, full objectives,ExpressionSpec, explicit-keywordTemplateExpressionSpec, and custom expression specs that declare TypeSpec supportTemplateExpressionSpecconstructor and its obsolete compatibility machineryv2.0.0-beta.5for custom-value mutation supportExample
The documentation includes custom full objectives plus vector-valued, string-valued, heterogeneous tensor, variable-length constant, template, multiprocessing, and checkpoint examples.
Verification
44 passed, 36 subtests passedinpysr/test/test_type_specs.py157 passed, 38 subtests passedinpysr/test/test_main.pygit diff --checkpassed