Skip to content

ENH: Allow on_unused_input="ignore" for string keys in eval #1084

@tvwenger

Description

@tvwenger

Before

Passing on_unused_input="ignore" to eval when the inputs_to_values dictionary is indexed by the pytensor variables properly ignores any unused inputs since on_unused_input is passed along to pytensor.function. When the dictionary is indexed by strings, however, the helper function convert_string_keys_to_variables will raise a ValueError when a given input name is not found in the graph, regardless of the value of on_unused_input.

After

Both of these eval statements should work, but the latter raises a ValueError.

import pytensor.tensor as pt

x = pt.dscalar("x")
y = pt.dscalar("y")
z = x + 1.0

print(z.eval({x: 1.0, y: 0.0}, on_unused_input="warn"))

print(z.eval({"x": 1.0, "y": 0.0}, on_unused_input="warn"))

Context for the issue:

Users may wish to evaluate a pytensor function after having lost references to the underlying pytensor variables, in which case the easiest (or only) solution is to index the inputs_to_values dictionary by the variable names. The user then has to determine which variables are needed to evaluate a given function, which is cumbersome.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions