-
Notifications
You must be signed in to change notification settings - Fork 121
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
ENH: Allow on_unused_input="ignore"
for string keys in eval
#1084
Comments
I don't think that's possible because pytensor.function requires actual variables to be initialized, even when unused. In your example it would need to know what type to use as x or y (such as There is a utility to know what root variables are needed to evaluate a graph: Eval is only meant for debug, we have utilities to do everything eval can do and more without needing it. |
Thanks for the lightning fast response, @ricardoV94! I submitted a PR with this feature. My specific use-case is related to evaluating variables in a import pymc as pm
with pm.Model() as model:
x = pm.Normal("x")
y = pm.Normal("y")
obs1 = pm.Normal("obs1", mu=x, observed=1.0)
obs2 = pm.Normal("obs2", mu=x+y, observed=2.0) If the user is only given access to params = {
"x": 3.0,
"y": 2.0,
}
sim_obs1 = model["obs1"].eval(params, on_unused_input="ignore")
sim_obs2 = model["obs2"].eval(params, on_unused_input="ignore") This fails with the Please let me know if there is a smarter way to do this! Thanks for your help! |
The statement eval is only meant for debugging still stands. In your case you probably want to make a function with inputs x and y and outputs obs1 and obs2. This will save on repeated computations between the two outputs. Then pymc specifically has the |
Thanks for the suggestion about |
Before
Passing
on_unused_input="ignore"
toeval
when theinputs_to_values
dictionary is indexed by thepytensor
variables properly ignores any unused inputs sinceon_unused_input
is passed along topytensor.function
. When the dictionary is indexed by strings, however, the helper functionconvert_string_keys_to_variables
will raise aValueError
when a given input name is not found in the graph, regardless of the value ofon_unused_input
.After
Both of these
eval
statements should work, but the latter raises aValueError
.Context for the issue:
Users may wish to evaluate a
pytensor
function after having lost references to the underlyingpytensor
variables, in which case the easiest (or only) solution is to index theinputs_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.The text was updated successfully, but these errors were encountered: