Skip to content

[BUG]: Cannot load model that has been fitted with TemplateExpressionSpec #941

@ibengtsson

Description

@ibengtsson

What happened?

When trying to load a model (from_file(...)) that has been fitted with a template function, I get a pickle error.

Version

1.5.8

Operating System

macOS

Package Manager

pip

Interface

Script (i.e., python my_script.py)

Relevant log output

Traceback (most recent call last):
  File "/Users/isakbe/Dev/modelling/il-sr/il_sr/scripts/minimal_example.py", line 32, in <module>
    main()
  File "/Users/isakbe/Dev/modelling/il-sr/il_sr/scripts/minimal_example.py", line 28, in main
    loaded_model = PySRRegressor().from_file(run_directory="./outputs/test")
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/isakbe/Library/Caches/pypoetry/virtualenvs/il-sr-9TFUWRsR-py3.11/lib/python3.11/site-packages/pysr/sr.py", line 1140, in from_file
    model = cast("PySRRegressor", pkl.load(f))
                                  ^^^^^^^^^^^
Exception: error deserializing this value

Extra Info

The model used to produce the error was defined as:

    x = np.random.uniform(low=[-1, 3, 10], high=[6, 10, 100], size=(3000, 3))
    y = np.sin(x[:, 0] - x[:, 2] ** 3) * np.exp(x[:, 1] / 5 + x[:, 0]) 
    

    template = TemplateExpressionSpec(
        expressions=["f", "g"],
        variable_names=["x1", "x2", "x3"],
        combine="sin(f(x1, x3)) * exp(g(x1, x2))",
    )

    model = PySRRegressor(
        binary_operators=["+", "-", "*", "/", "^"],
        expression_spec=template,
        constraints={"^": (1, 9)},
        run_id="test",
    )

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions