feat(types): add an optional invalid value hook - #1360
Closed
MilesCranmer wants to merge 1 commit into
Closed
MilesCranmer wants to merge 1 commit into
MilesCranmer wants to merge 1 commit into
Conversation
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Custom TypeSpec values need a way to construct an invalid result without adding a scalar constructor to the Julia type.
Scope
TypeSpec(invalid="() -> value"), following the existinginitcallable convention.DynamicExpressions.invalid_value(T)and validate that its result has typeTand failsis_valid.pysr/juliapkg.jsonwith its registry UUID. The docs Julia project does not load this backend and needs no extra dependency.Tradeoffs
Dependent draft. Do not merge or release this PR yet.
This requires astroautomata/DynamicExpressions.jl#209 and a registered DynamicExpressions release containing that change. The latest real release is 2.10.1, which lacks
invalid_value. The current^2.10.1constraint records the tested compatible series, but it does not enforce the new API. Before merge, replace that lower bound with the first actual registered release containing #209, then rerun ordinary resolver and CI tests. No future release number is invented here.The Force example and its documentation mirror live in dependent docs PR #1350, not current master. Their scoped migration is to remove
Force(u::Real) = Force(u,u,u)fromsample, usesample="rng -> Force(randn(rng, 3)...)", and addinvalid="() -> Force(NaN, NaN, NaN)". The matching prose must describe the invalid hook. Both revised definitions were compiled and compared locally; the complete example passed a small fit/predict smoke run. The existing dirty docs branch and definitions PR #1359 are untouched.Blast Radius
Types without invalid states can omit this hook. Existing positional TypeSpec parameters retain their positions. Runtime hook loading does not invoke the constructor; validation does.
Verification
Pkg.developintegration resolved this backend checkout, SymbolicRegression 2.4.0, and PythonCall 0.9.35. No local source overrides are committed.