diff --git a/docs/changelog.md b/docs/changelog.md index e73c670b..3da9ffa2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,7 @@ _This project uses semantic versioning_ ## UNRELEASED +- Add `egraph.stats()` method to print overall stats [#339](https://github.com/egraphs-good/egglog-python/pull/339) - Add `all_function_sizes` and `function_size` EGraph methods [#338](https://github.com/egraphs-good/egglog-python/pull/338) - Fix execution of docs [#337](https://github.com/egraphs-good/egglog-python/pull/337) - Emit warnings when functions omitted when visualizing [#336](https://github.com/egraphs-good/egglog-python/pull/336) @@ -14,6 +15,7 @@ _This project uses semantic versioning_ - Allow changing number of threads with env variable [#330](https://github.com/egraphs-good/egglog-python/pull/330) ## 11.0.0 (2025-08-08) + - Change conversion between binary operators to consider converting both types [#320](https://github.com/egraphs-good/egglog-python/pull/320) - Add ability to parse egglog expressions into Python values [#319](https://github.com/egraphs-good/egglog-python/pull/319) - Deprecates `.eval()` method on primitives in favor of `.value` which can be used with pattern matching. diff --git a/docs/reference/egglog-translation.md b/docs/reference/egglog-translation.md index 3c5f81e7..7bf13607 100644 --- a/docs/reference/egglog-translation.md +++ b/docs/reference/egglog-translation.md @@ -522,6 +522,15 @@ egraph.function_size(Math) egraph.all_function_sizes() ``` +## Overall Statistics + +The `(print-stats)` command is translated into `egraph.stats()` to get overall statistics about the EGraph. + +```{code-cell} python +# (print-stats) +egraph.stats() +``` + ## Include The `(include )` command is used to add modularity, by allowing you to pull in the source from another egglog file into the current file. diff --git a/python/egglog/egraph.py b/python/egglog/egraph.py index 778458e0..d73ab7d1 100644 --- a/python/egglog/egraph.py +++ b/python/egglog/egraph.py @@ -909,6 +909,14 @@ def _run_schedule(self, schedule: Schedule) -> bindings.RunReport: assert isinstance(command_output, bindings.RunScheduleOutput) return command_output.report + def stats(self) -> bindings.RunReport: + """ + Returns the overall run report for the egraph. + """ + (output,) = self._egraph.run_program(bindings.PrintOverallStatistics()) + assert isinstance(output, bindings.OverallStatistics) + return output.report + def check_bool(self, *facts: FactLike) -> bool: """ Returns true if the facts are true in the egraph. diff --git a/python/tests/test_high_level.py b/python/tests/test_high_level.py index d883fb6f..bdca5ddc 100644 --- a/python/tests/test_high_level.py +++ b/python/tests/test_high_level.py @@ -1048,3 +1048,7 @@ def test_all_function_size(): (C, 1), (E.cm, 1), } + + +def test_overall_run_report(): + assert EGraph().stats()