egglog-python icon indicating copy to clipboard operation
egglog-python copied to clipboard

Simplifying an expression with a Map argument.

Open cgyurgyik opened this issue 1 year ago • 1 comments

m = egraph.let("map", Map[String, i64].empty().insert(String("a"), i64(42)))
egraph.simplify(m, 5)

Results in:

Traceback (most recent call last):
  File "/.../egg/working-version/../list.py", line 265, in <module>
    egraph.simplify(m, 5)
  File "/.../venv/lib/python3.10/site-packages/egglog/egraph.py", line 1025, in simplify
    (new_typed_expr,) = self._state.exprs_from_egg(extract_report.termdag, [extract_report.term], typed_expr.tp)
  File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 340, in exprs_from_egg
    return [state.from_expr(tp, term) for term in terms]
  File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 340, in <listcomp>
    return [state.from_expr(tp, term) for term in terms]
  File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 421, in from_expr
    expr_decl = self.from_call(tp, term)
  File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 465, in from_call
    args = tuple(self.resolve_term(a, tp)
  File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 465, in <genexpr>
    args = tuple(self.resolve_term(a, tp)
  File "/.../venv/lib/python3.10/site-packages/egglog/type_constraint_solver.py", line 83, in <genexpr>
    self._subtitute_typevars(a, cls_name) for a in chain(fn_args, repeat(fn_var_args) if fn_var_args else [])
  File "/.../venv/lib/python3.10/site-packages/egglog/type_constraint_solver.py", line 136, in _subtitute_typevars
    assert cls_name is not None

Interestingly, if I make it an argument to an Expr class and saturate(), i.e.,

class CMap(Expr):
    def __init__(self, m: Map[String, i64]) -> None: ...

egraph.let("map", CMap(Map[String, i64].empty().insert(String("a"), i64(42))))
egraph.saturate()

...then it works as expected (since I'm not simplifying).

cgyurgyik avatar May 14 '24 02:05 cgyurgyik

I get a (perhaps) related error when using Set and simplifying:

/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 468, in from_call
    raise ValueError(f"Could not find callable ref for call {term}")
ValueError: Could not find callable ref for call App("set-insert", [21, 3])

cgyurgyik avatar May 14 '24 03:05 cgyurgyik

Thanks for opening this! I'll take a look. I don't use the builtin collections much, so they haven't gotten as much testing.

saulshanabrook avatar May 23 '24 12:05 saulshanabrook

This was fixed in #168 and I just released version 7.2.0 which includes this bugfix.

saulshanabrook avatar May 23 '24 15:05 saulshanabrook