File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -616,16 +616,20 @@ def eval(
616
616
"""
617
617
from pytensor .compile .function import function
618
618
619
+ ignore_unused_input = kwargs .get ("on_unused_input" , None ) in ("ignore" , "warn" )
620
+
619
621
def convert_string_keys_to_variables (inputs_to_values ) -> dict ["Variable" , Any ]:
620
622
new_input_to_values = {}
621
623
for key , value in inputs_to_values .items ():
622
624
if isinstance (key , str ):
623
625
matching_vars = get_var_by_name ([self ], key )
624
626
if not matching_vars :
625
- raise ValueError (f"{ key } not found in graph" )
627
+ if not ignore_unused_input :
628
+ raise ValueError (f"{ key } not found in graph" )
626
629
elif len (matching_vars ) > 1 :
627
630
raise ValueError (f"Found multiple variables with name { key } " )
628
- new_input_to_values [matching_vars [0 ]] = value
631
+ else :
632
+ new_input_to_values [matching_vars [0 ]] = value
629
633
else :
630
634
new_input_to_values [key ] = value
631
635
return new_input_to_values
Original file line number Diff line number Diff line change @@ -367,6 +367,10 @@ def test_eval_kwargs(self):
367
367
self .w .eval ({self .z : 3 , self .x : 2.5 })
368
368
assert self .w .eval ({self .z : 3 , self .x : 2.5 }, on_unused_input = "ignore" ) == 6.0
369
369
370
+ # regression test for https://github.com/pymc-devs/pytensor/issues/1084
371
+ q = self .x + 1
372
+ assert q .eval ({"x" : 1 , "y" : 2 }, on_unused_input = "ignore" ) == 2.0
373
+
370
374
@pytest .mark .filterwarnings ("error" )
371
375
def test_eval_unashable_kwargs (self ):
372
376
y_repl = constant (2.0 , dtype = "floatX" )
You can’t perform that action at this time.
0 commit comments