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

Made from_file pickle loading more robust #702

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pysr/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,29 @@ def from_file(
base_equation_file = os.path.basename(model.equation_file_)
model.equation_file_ = os.path.join(base_dir, base_equation_file)

# Get constructor parameters and default values
params = inspect.signature(model.__init__).parameters

# Filter for missing parameters excluding kwargs
missing_params = {
k: v
for k, v in params.items()
if k not in model.__dict__.keys()
and v.name != "self"
and v.kind != v.VAR_KEYWORD
}

if len(missing_params) > 0:
warnings.warn(
"The following missing parameters will be assigned with default values:"
f"{', '.join(missing_params.keys())}"
"This may be due to the model being saved under an old package version."
)

# Assign missing attributes
for k, v in missing_params.items():
setattr(model, k, v)
MilesCranmer marked this conversation as resolved.
Show resolved Hide resolved

# Update any parameters if necessary, such as
# extra_sympy_mappings:
model.set_params(**pysr_kwargs)
Expand Down
Loading