Skip to content

Allow string keys in .eval #227

Closed
@ricardoV94

Description

@ricardoV94

Description

eval is very useful for debugging, including interactive debugging during development. One issue is that required inputs must be passed by reference which is not always easy to do inside a given stack.

I usually have to play with ancestors to get a hold of the input variable. Instead it would be neat if we can get it by name if a string is used as a key in eval

import pytensor.tensor as pt

def create_expr():
  x = pt.scalar("x")
  y = pt.exp(x)
  return y

y = create_expr()
# Feature request:
y.eval({"x": 0})  # 1.0

If there are multiple variables with the same key name we could use the closest + warning or raise.

There is already a handy utility to find variables by name: https://pytensor.readthedocs.io/en/latest/library/graph/graph.html#pytensor.graph.basic.get_var_by_name

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