From dbf79f8ca5f8bae1a5e7c3cd3052e414b012ff46 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Fri, 29 Aug 2025 11:33:27 -0600 Subject: [PATCH 1/3] Emit warnings when functions omitted when visualizing Adds support for upstream egglog change to emit when serializing and functions or calls were omitted based on maxmimums --- python/egglog/egraph.py | 7 +++++++ python/egglog/egraph_state.py | 8 ++++++++ python/tests/test_high_level.py | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/python/egglog/egraph.py b/python/egglog/egraph.py index 20904852..471ae58b 100644 --- a/python/egglog/egraph.py +++ b/python/egglog/egraph.py @@ -23,6 +23,7 @@ get_type_hints, overload, ) +from warnings import warn import graphviz from typing_extensions import Never, ParamSpec, Self, Unpack, assert_never @@ -1024,6 +1025,12 @@ def _serialize( max_calls_per_function=max_calls_per_function, include_temporary_functions=include_temporary_functions, ) + if serialized.discarded_functions: + msg = ", ".join(set(self._state.possible_egglog_functions(serialized.discarded_functions))) + warn(f"Ommitted: {msg}", stacklevel=3) + if serialized.truncated_functions: + msg = ", ".join(set(self._state.possible_egglog_functions(serialized.truncated_functions))) + warn(f"Truncated: {msg}", stacklevel=3) if split_primitive_outputs or split_functions: additional_ops = set(map(self._callable_to_egg, split_functions)) serialized.split_classes(self._egraph, additional_ops) diff --git a/python/egglog/egraph_state.py b/python/egglog/egraph_state.py index 8ad314f2..aee48900 100644 --- a/python/egglog/egraph_state.py +++ b/python/egglog/egraph_state.py @@ -354,6 +354,14 @@ def op_mapping(self) -> dict[str, str]: if len(v) == 1 } + def possible_egglog_functions(self, names: list[str]) -> Iterable[str]: + """ + Given a list of egglog functions, returns all the possible Python function strings + """ + for name in names: + for c in self.egg_fn_to_callable_refs[name]: + yield pretty_callable_ref(self.__egg_decls__, c) + def typed_expr_to_egg(self, typed_expr_decl: TypedExprDecl, transform_let: bool = True) -> bindings._Expr: # transform all expressions with multiple parents into a let binding, so that less expressions # are sent to egglog. Only for performance reasons. diff --git a/python/tests/test_high_level.py b/python/tests/test_high_level.py index c5bb13e2..9bb543c3 100644 --- a/python/tests/test_high_level.py +++ b/python/tests/test_high_level.py @@ -958,6 +958,28 @@ def __hash__(self) -> int: assert hash(A()) == 42 +def test_serialize_warning_max_functions(): + class A(Expr): + def __init__(self) -> None: ... + + egraph = EGraph() + egraph.register(A()) + with pytest.warns(UserWarning, match="A"): + egraph._serialize(max_functions=0) + + +def test_serialize_warning_max_calls(): + class A(Expr): ... + + @function + def f(x: StringLike) -> A: ... + + egraph = EGraph() + egraph.register(f("a"), f("b")) + with pytest.warns(UserWarning, match="f"): + egraph._serialize(max_calls_per_function=1) + + EXAMPLE_FILES = list((pathlib.Path(__file__).parent / "../egglog/examples").glob("*.py")) From 6586a4b03d11d95e9a75b55e92babba842178091 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 1 Sep 2025 14:25:20 -0700 Subject: [PATCH 2/3] Update python/egglog/egraph.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- python/egglog/egraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/egglog/egraph.py b/python/egglog/egraph.py index 471ae58b..cc07d7e7 100644 --- a/python/egglog/egraph.py +++ b/python/egglog/egraph.py @@ -1027,7 +1027,7 @@ def _serialize( ) if serialized.discarded_functions: msg = ", ".join(set(self._state.possible_egglog_functions(serialized.discarded_functions))) - warn(f"Ommitted: {msg}", stacklevel=3) + warn(f"Omitted: {msg}", stacklevel=3) if serialized.truncated_functions: msg = ", ".join(set(self._state.possible_egglog_functions(serialized.truncated_functions))) warn(f"Truncated: {msg}", stacklevel=3) From f85b35d75aca8cdc43eb06a54f3f756de638ef13 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 1 Sep 2025 21:30:21 +0000 Subject: [PATCH 3/3] Add changelog entry for PR #336 --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index cbccdfce..43c902ee 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,7 @@ _This project uses semantic versioning_ ## UNRELEASED +- Emit warnings when functions omitted when visualizing [#336](https://github.com/egraphs-good/egglog-python/pull/336) ## 11.1.0 (2025-08-21) - Allow changing number of threads with env variable [#330](https://github.com/egraphs-good/egglog-python/pull/330)