Skip to content

feat: add runtime TypeSpec support - #1280

Open
MilesCranmerBot wants to merge 12 commits into
astroautomata:masterfrom
MilesCranmerBot:codex/type-spec
Open

feat: add runtime TypeSpec support#1280
MilesCranmerBot wants to merge 12 commits into
astroautomata:masterfrom
MilesCranmerBot:codex/type-spec

Conversation

@MilesCranmerBot

@MilesCranmerBot MilesCranmerBot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a runtime TypeSpec for existing Julia types or simple generated structs
  • install the SymbolicRegression value hooks from compact Julia callbacks
  • support PySRRegressor(type_spec=...) with typed Julia arrays and GenericOperatorEnum, with the custom loss scalar type configured by TypeSpec.loss_type
  • keep custom-type equations and prediction Julia-backed

Example

spec = TypeSpec(
    "RASPVal",
    fields={"data": "Union{Float64, Vector{Float64}}"},
    init_value="() -> RASPVal(0.0)",
    sample_value="rng -> RASPVal(randn(rng))",
    mutate_value="(rng, value, temperature) -> value",
    count_scalar_constants=1,
    can_optimize=False,
    loss_type="Float64",
)

Verification

  • actual String fit/search/predict
  • actual one-field and two-field struct fit/search/predict
  • compact hook installation and arity validation
  • parameter-group completeness
  • ordinary numeric fit/predict smoke test
  • full pre-commit suite

Current scope

The custom-type path supports serial and multithreaded searches, existing Julia types, and automatic conversion for generated structs with one or more fields. It remains unweighted and single-output. Denoising, feature selection, resampling, and custom expression specs are rejected explicitly.

No SymbolicRegression.jl backend change is required.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.51852% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pysr/sr.py 81.33% 14 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread pysr/sr.py Outdated
Comment thread pysr/type_specs.py Outdated
Comment thread pysr/type_specs.py Outdated
Comment thread pysr/sr.py Outdated
@MilesCranmer

Copy link
Copy Markdown
Member

@MilesCranmerBot please address the above

@MilesCranmer

Copy link
Copy Markdown
Member

@MilesCranmerBot also we need 100% diff coverage

MilesCranmerBot and others added 3 commits August 8, 2026 01:00
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@MilesCranmerBot

Copy link
Copy Markdown
Contributor Author

Addressed in 9601b5a:

  • renamed the TypeSpec setup method to instantiate
  • replaced the @eval wrappers with direct jl.seval definitions
  • removed the serial-only restriction and added a multithreaded TypeSpec regression test
  • added coverage for TypeSpec conversions and callback variants

Checks: normal numeric regression test passes; TypeSpec direct-instantiation coverage is 100%.

@MilesCranmer
MilesCranmer self-requested a review August 9, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants