Skip to content

Preserve CustomLibrary parameters for display, cloning and updates - #706

Open
antonsoo wants to merge 1 commit into
dynamicslab:mainfrom
antonsoo:fix/703-custom-library-parameters
Open

antonsoo wants to merge 1 commit into
dynamicslab:mainfrom
antonsoo:fix/703-custom-library-parameters

Conversation

@antonsoo

@antonsoo antonsoo commented Nov 1, 2026 •

Copy link
Copy Markdown

Fixes #703.

CustomLibrary stores its functions as functions, but scikit-learn looks up the constructor parameter library_functions. This breaks notebook display, clone() and set_params() on both 2.1.0 and current main:

import numpy as np
from sklearn.base import clone
from pysindy import CustomLibrary

library = CustomLibrary([lambda x: x])
print(library.fit(np.ones((10, 2))))
clone(library)
library.set_params(library_functions=[lambda x: x**2])

Expose library_functions as a read/write alias of the existing functions attribute. This also makes parameter replacement affect the functions used by fit and transform, while retaining the documented attribute and libraries saved by older versions.

Fitted libraries cache generated function_names. When changing the number of functions after a fit, also set function_names=None to regenerate names on the next fit.

Checked fitted/unfitted cloning, parameter replacement, an old-writer serialized library, and cloning a fitted Lorenz model. Existing feature arrays, coefficients and predictions remain identical. A scikit-learn Pipeline/GridSearchCV on a recorded waveform now runs; both candidate scores agree with independently assembled matrices and NumPy least squares within 2e-16. This is an API check, not a physiological model.

Validation: all three new regressions fail on base and pass here; feature-library tests: 93 passed, 1 skipped; configured pre-commit checks pass. The complete suite has the same 35 Gurobi max_iter failures on both revisions (base 709 passed, head 712 passed, both 13 skipped and 11 deselected).

Fixes dynamicslab#703. Retain the documented functions attribute and old serialized
libraries while making sklearn repr, clone and parameter updates agree.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T21:35:54.498592Z 39c1560 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
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.

[BUG] CustomLibrary method fit causing attribute error in python REPL and Jupyter Notebook

1 participant