Skip to content

Commit 3158446

Browse files
Merge pull request #339 from egraphs-good/list-function
Add `egraph.run_report()` method to print overall stats
2 parents 1a2ee10 + 78cab3c commit 3158446

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ _This project uses semantic versioning_
44

55
## UNRELEASED
66

7+
- Add `egraph.stats()` method to print overall stats [#339](https://github.com/egraphs-good/egglog-python/pull/339)
78
- Add `all_function_sizes` and `function_size` EGraph methods [#338](https://github.com/egraphs-good/egglog-python/pull/338)
89
- Fix execution of docs [#337](https://github.com/egraphs-good/egglog-python/pull/337)
910
- 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_
1415
- Allow changing number of threads with env variable [#330](https://github.com/egraphs-good/egglog-python/pull/330)
1516

1617
## 11.0.0 (2025-08-08)
18+
1719
- Change conversion between binary operators to consider converting both types [#320](https://github.com/egraphs-good/egglog-python/pull/320)
1820
- Add ability to parse egglog expressions into Python values [#319](https://github.com/egraphs-good/egglog-python/pull/319)
1921
- Deprecates `.eval()` method on primitives in favor of `.value` which can be used with pattern matching.

docs/reference/egglog-translation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,15 @@ egraph.function_size(Math)
522522
egraph.all_function_sizes()
523523
```
524524

525+
## Overall Statistics
526+
527+
The `(print-stats)` command is translated into `egraph.stats()` to get overall statistics about the EGraph.
528+
529+
```{code-cell} python
530+
# (print-stats)
531+
egraph.stats()
532+
```
533+
525534
## Include
526535

527536
The `(include <path>)` command is used to add modularity, by allowing you to pull in the source from another egglog file into the current file.

python/egglog/egraph.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,14 @@ def _run_schedule(self, schedule: Schedule) -> bindings.RunReport:
909909
assert isinstance(command_output, bindings.RunScheduleOutput)
910910
return command_output.report
911911

912+
def stats(self) -> bindings.RunReport:
913+
"""
914+
Returns the overall run report for the egraph.
915+
"""
916+
(output,) = self._egraph.run_program(bindings.PrintOverallStatistics())
917+
assert isinstance(output, bindings.OverallStatistics)
918+
return output.report
919+
912920
def check_bool(self, *facts: FactLike) -> bool:
913921
"""
914922
Returns true if the facts are true in the egraph.

python/tests/test_high_level.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,3 +1048,7 @@ def test_all_function_size():
10481048
(C, 1),
10491049
(E.cm, 1),
10501050
}
1051+
1052+
1053+
def test_overall_run_report():
1054+
assert EGraph().stats()

0 commit comments

Comments
 (0)