Skip to content

Allow string keys in .eval #227

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

Closed
ricardoV94 opened this issue Feb 21, 2023 · 1 comment · Fixed by #242
Closed

Allow string keys in .eval #227

ricardoV94 opened this issue Feb 21, 2023 · 1 comment · Fixed by #242
Labels
beginner friendly enhancement New feature or request

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 21, 2023

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

@ricardoV94 ricardoV94 added enhancement New feature or request beginner friendly labels Feb 21, 2023
@ricardoV94 ricardoV94 changed the title Allow string inputs in .eval Allow string keys in .eval Feb 21, 2023
@Raj-Parekh24
Copy link
Contributor

Raj-Parekh24 commented Mar 11, 2023

Hello @ricardoV94 ,

I am new to this project and want to make a contribution.

I am working on this issue. I have implemented a function that converts the dictionary with string keys to pytensor. The pytensor variable for the corresponding name is found using the function "get_var_by_name".

I am raising the PR please review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner friendly enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants