Skip to content

Not possible to load a model fitted with TemplateExpressionSpec #846

Description

@MilesCranmer

Unfortunately template expressions aren't yet compatible with loading from file—should update the error message to mention this.

Discussed in #844

Originally posted by ibengtsson February 28, 2025
Hi!

First of all, thank you for a great library.

I'm having some issues when working with TemplateExpresssionSpec, and it could very well be a fault on my end... If I create a model with a TemplateExpression, fit and save it, and then try and load it (with from_file) in a different script, I cannot do any model predictions. I just get the error:

ValueError: Failed to evaluate the expression. If you are using a custom operator, make sure to define it in `extra_sympy_mappings`, e.g., `model.set_params(extra_sympy_mappings={'inv': lambda x: 1/x})`, where `lambda x: 1/x` is a valid SymPy function defining the operator. You can then run `model.refresh()` to re-load the expressions.

I don't use any custom operators in my TemplateEpxressionSpec, but maybe I still need to add some mappings to make the loading work?

Grateful for any help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions