Skip to content
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

Ambiguity for symbols in the sympy layer #1417

Open
BenWeber42 opened this issue Oct 31, 2023 · 2 comments
Open

Ambiguity for symbols in the sympy layer #1417

BenWeber42 opened this issue Oct 31, 2023 · 2 comments

Comments

@BenWeber42
Copy link
Contributor

BenWeber42 commented Oct 31, 2023

In our sympy layer, there exist multiple implementations to query symbols in a symbolic expression. They give vastly different results for various expressions:

from ast import parse
from dace.symbolic import pystr_to_symbolic, symbols_in_ast, symlist

pystr_to_symbolic("x").free_symbols
# -> {x}
symbols_in_ast(parse("x"))
# -> ['x']
symlist(pystr_to_symbolic("x"))
# -> {'x': x}

pystr_to_symbolic("a[i]").free_symbols
# -> {i}
symbols_in_ast(parse("a[i]"))
# -> ['a', 'i']
symlist(pystr_to_symbolic("a[i]"))
# -> {'i': i}

pystr_to_symbolic("a.b").free_symbols
# -> {a.b}
symbols_in_ast(parse("a.b"))
# -> ['a']
symlist(pystr_to_symbolic("a.b"))
# -> {'a': a, 'b': b}

pystr_to_symbolic("a.b[i]").free_symbols
# -> {a.b(i)}
symbols_in_ast(parse("a.b[i]"))
# -> ['i', 'a']
symlist(pystr_to_symbolic("a.b[i]"))
# -> {'a': a, 'i': i}

We should:

  1. clearly define different concepts around symbolic expressions (symbolic variables, array variables, attribute variables or similar)
  2. precisely specify the return values of these functions w.r.t. to these definitions.

For consistent specifications there must be consistent return values.

@tbennun
Copy link
Collaborator

tbennun commented Nov 2, 2023

see #1423

@tbennun
Copy link
Collaborator

tbennun commented Nov 2, 2023

updated results:

In [2]: from ast import parse
   ...: from dace.symbolic import pystr_to_symbolic, names_in_ast, symlist

In [3]: pystr_to_symbolic("a[i]").free_symbols
Out[3]: {i}

In [4]: names_in_ast(parse("a[i]"))
Out[4]: ['a', 'i']

In [5]: symlist(pystr_to_symbolic("a[i]"))
Out[5]: {'i': i}

In [6]: pystr_to_symbolic("a.b").free_symbols
Out[6]: {a.b}

In [7]: names_in_ast(parse("a.b"))
Out[7]: ['a']

In [8]: symlist(pystr_to_symbolic("a.b"))
Out[8]: {'a.b': a.b}

In [9]: pystr_to_symbolic("a.b[i]").free_symbols
Out[9]: {a.b(i)}

In [10]: names_in_ast(parse("a.b[i]"))
Out[10]: ['a', 'i']

In [11]: symlist(pystr_to_symbolic("a.b[i]"))
Out[11]: {'a.b(i)': a.b(i)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants