-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add pretty run report #416
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
Merged
saulshanabrook
merged 16 commits into
egraphs-good:main
from
kaeun97:kaeun97/pretty-report
Jun 3, 2026
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2007b1a
feat: add pretty run report
kaeun97 86133fa
feat: add test for pretty run report
kaeun97 f554bb2
chore: rename to runreport
kaeun97 c554d1a
chore: pre-commit
kaeun97 810bd95
fix: store CommandDecl
kaeun97 c09c7de
fix: make methods private
kaeun97 3d7bec7
feat: update changelog
kaeun97 ff7f688
chore: use 2e5657b egglog
kaeun97 01802ec
fix: numberic name approach for better performance
kaeun97 8ca9d10
chore: better types
kaeun97 e217a3f
fix: add assertion for specific text in test
kaeun97 3e45d9c
chore: clean up by removing egg_rule_to_command_decl fallback and cle…
kaeun97 7ecc467
chore: test_run_report is functional style
kaeun97 3603683
chore: remove _format_rule_key
kaeun97 5182add
chore: skip eggcc-2mm
kaeun97 568d6bf
chore: update changelog
kaeun97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import timedelta | ||
|
|
||
| from . import bindings | ||
| from .egraph_state import EGraphState | ||
|
|
||
|
|
||
| @dataclass | ||
| class PrettyRuleReport: | ||
| plan: bindings.Plan | None | ||
| search_and_apply_time: timedelta | ||
| num_matches: int | ||
|
|
||
| @classmethod | ||
| def from_bindings(cls, report: bindings.RuleReport) -> PrettyRuleReport: | ||
| return cls( | ||
| plan=report.plan, | ||
| search_and_apply_time=report.search_and_apply_time, | ||
| num_matches=report.num_matches, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class PrettyRuleSetReport: | ||
| changed: bool | ||
| rule_reports: dict[str, list[PrettyRuleReport]] | ||
|
kaeun97 marked this conversation as resolved.
Outdated
|
||
| search_and_apply_time: timedelta | ||
| merge_time: timedelta | ||
|
|
||
| @classmethod | ||
| def from_bindings(cls, report: bindings.RuleSetReport, translate_key: callable) -> PrettyRuleSetReport: | ||
|
kaeun97 marked this conversation as resolved.
Outdated
|
||
| return cls( | ||
| changed=report.changed, | ||
| rule_reports={ | ||
| translate_key(k): [PrettyRuleReport.from_bindings(rr) for rr in v] | ||
| for k, v in report.rule_reports.items() | ||
| }, | ||
| search_and_apply_time=report.search_and_apply_time, | ||
| merge_time=report.merge_time, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class PrettyIterationReport: | ||
| rule_set_report: PrettyRuleSetReport | ||
| rebuild_time: timedelta | ||
|
|
||
| @classmethod | ||
| def from_bindings(cls, report: bindings.IterationReport, translate_key: callable) -> PrettyIterationReport: | ||
| return cls( | ||
| rule_set_report=PrettyRuleSetReport.from_bindings(report.rule_set_report, translate_key), | ||
| rebuild_time=report.rebuild_time, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class PrettyRunReport: | ||
| """Python-friendly wrapper around bindings.RunReport.""" | ||
|
|
||
| iterations: list[PrettyIterationReport] | ||
| updated: bool | ||
| search_and_apply_time_per_rule: dict[str, timedelta] | ||
| num_matches_per_rule: dict[str, int] | ||
| search_and_apply_time_per_ruleset: dict[str, timedelta] | ||
| merge_time_per_ruleset: dict[str, timedelta] | ||
| rebuild_time_per_ruleset: dict[str, timedelta] | ||
|
kaeun97 marked this conversation as resolved.
Outdated
|
||
|
|
||
| @classmethod | ||
| def from_bindings(cls, report: bindings.RunReport, state: EGraphState) -> PrettyRunReport: | ||
|
kaeun97 marked this conversation as resolved.
Outdated
|
||
| return cls( | ||
| iterations=[PrettyIterationReport.from_bindings(it, state.translate_rule_key) for it in report.iterations], | ||
| updated=report.updated, | ||
| search_and_apply_time_per_rule={ | ||
| state.translate_rule_key(k): v for k, v in report.search_and_apply_time_per_rule.items() | ||
| }, | ||
| num_matches_per_rule={state.translate_rule_key(k): v for k, v in report.num_matches_per_rule.items()}, | ||
|
kaeun97 marked this conversation as resolved.
Outdated
|
||
| search_and_apply_time_per_ruleset={ | ||
| state.translate_rule_key(k): v for k, v in report.search_and_apply_time_per_ruleset.items() | ||
| }, | ||
| merge_time_per_ruleset={state.translate_rule_key(k): v for k, v in report.merge_time_per_ruleset.items()}, | ||
| rebuild_time_per_ruleset={ | ||
| state.translate_rule_key(k): v for k, v in report.rebuild_time_per_ruleset.items() | ||
| }, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| # mypy: disable-error-code="empty-body" | ||
| from __future__ import annotations | ||
|
|
||
| from datetime import timedelta | ||
|
|
||
| from egglog import * | ||
|
|
||
|
|
||
| class TestPrettyRunReport: | ||
| def _setup_simple_egraph(self): | ||
| egraph = EGraph() | ||
|
|
||
| class Num(Expr): | ||
| def __init__(self, n: i64Like) -> None: ... | ||
| def __add__(self, other: Num) -> Num: ... | ||
|
|
||
| x, y = vars_("x y", Num) | ||
| egraph.register(rewrite(x + y).to(y + x)) | ||
| egraph.register(Num(1) + Num(2)) | ||
| return egraph | ||
|
|
||
| def test_run_returns_pretty_report(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
| assert type(report).__name__ == "PrettyRunReport" | ||
|
|
||
| def test_stats_returns_pretty_report(self): | ||
| egraph = self._setup_simple_egraph() | ||
| egraph.run(10) | ||
| report = egraph.stats() | ||
| assert type(report).__name__ == "PrettyRunReport" | ||
|
|
||
| def test_rule_names_translated_in_top_level_dicts(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
|
|
||
| for key in report.search_and_apply_time_per_rule: | ||
| assert "rewrite" in key, f"Expected Python rewrite syntax, got: {key}" | ||
| assert "__main__" not in key, f"Key should not contain mangled egglog names: {key}" | ||
|
|
||
| for key in report.num_matches_per_rule: | ||
| assert "rewrite" in key, f"Expected Python rewrite syntax, got: {key}" | ||
| assert "__main__" not in key, f"Key should not contain mangled egglog names: {key}" | ||
|
|
||
| def test_rule_names_translated_in_iterations(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
|
|
||
| assert len(report.iterations) > 0 | ||
| for iteration in report.iterations: | ||
| for key in iteration.rule_set_report.rule_reports: | ||
| assert "__main__" not in key, f"Iteration rule key not translated: {key}" | ||
| assert "rewrite" in key, f"Expected Python rewrite syntax, got: {key}" | ||
|
|
||
| def test_updated_field(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
| assert isinstance(report.updated, bool) | ||
| assert report.updated is True | ||
|
|
||
| def test_num_matches(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
|
|
||
| total_matches = sum(report.num_matches_per_rule.values()) | ||
| assert total_matches > 0 | ||
|
|
||
| def test_timedelta_types(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
|
|
||
| for v in report.search_and_apply_time_per_rule.values(): | ||
| assert isinstance(v, timedelta) | ||
| for v in report.search_and_apply_time_per_ruleset.values(): | ||
| assert isinstance(v, timedelta) | ||
| for v in report.merge_time_per_ruleset.values(): | ||
| assert isinstance(v, timedelta) | ||
| for v in report.rebuild_time_per_ruleset.values(): | ||
| assert isinstance(v, timedelta) | ||
|
|
||
| def test_iteration_reports_are_pretty(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
|
|
||
| for it in report.iterations: | ||
| assert type(it).__name__ == "PrettyIterationReport" | ||
| assert type(it.rule_set_report).__name__ == "PrettyRuleSetReport" | ||
| for rule_reports in it.rule_set_report.rule_reports.values(): | ||
| for rr in rule_reports: | ||
| assert type(rr).__name__ == "PrettyRuleReport" | ||
|
|
||
| def test_str_no_egglog_sexprs(self): | ||
| egraph = self._setup_simple_egraph() | ||
| report = egraph.run(10) | ||
| output = str(report) | ||
|
|
||
| assert "(rewrite" not in output, f"str() still contains egglog s-expressions:\n{output}" | ||
| assert "__main__" not in output, f"str() still contains mangled names:\n{output}" | ||
|
|
||
| def test_multiple_rules(self): | ||
| egraph = EGraph() | ||
|
|
||
| class Math(Expr): | ||
| def __init__(self, value: i64Like) -> None: ... | ||
| def __add__(self, other: Math) -> Math: ... | ||
| def __mul__(self, other: Math) -> Math: ... | ||
|
|
||
| a, b = vars_("a b", Math) | ||
| egraph.register( | ||
| rewrite(a + b).to(b + a), | ||
| rewrite(a * b).to(b * a), | ||
| ) | ||
| egraph.register(Math(1) + Math(2), Math(3) * Math(4)) | ||
| report = egraph.run(10) | ||
|
|
||
| # should have two distinct translated rule keys | ||
| rule_keys = list(report.search_and_apply_time_per_rule.keys()) | ||
| assert len(rule_keys) == 2 | ||
| for key in rule_keys: | ||
| assert "__main__" not in key, f"Key not translated: {key}" | ||
|
|
||
| def test_empty_run(self): | ||
| egraph = EGraph() | ||
| report = egraph.run(1) | ||
| assert type(report).__name__ == "PrettyRunReport" | ||
| assert isinstance(report.updated, bool) | ||
|
|
||
| def test_named_rule(self): | ||
| egraph = EGraph() | ||
|
|
||
| class Num(Expr): | ||
| def __init__(self, n: i64Like) -> None: ... | ||
| def __add__(self, other: Num) -> Num: ... | ||
|
|
||
| x, y = vars_("x y", Num) | ||
| egraph.register(rule(x + y, name="comm").then(union(x + y).with_(y + x))) | ||
| egraph.register(Num(1) + Num(2)) | ||
| report = egraph.run(10) | ||
|
|
||
| output = str(report) | ||
| assert "__main__" not in output, f"str() still contains mangled names:\n{output}" | ||
|
|
||
| def test_unnamed_rule_decl(self): | ||
| egraph = EGraph() | ||
|
|
||
| class Num(Expr): | ||
| def __init__(self, n: i64Like) -> None: ... | ||
| def __add__(self, other: Num) -> Num: ... | ||
|
|
||
| x, y = vars_("x y", Num) | ||
| egraph.register(rule(x + y).then(union(x + y).with_(y + x))) | ||
| egraph.register(Num(1) + Num(2)) | ||
| report = egraph.run(10) | ||
|
|
||
| output = str(report) | ||
| assert "__main__" not in output, f"Unnamed RuleDecl key not translated:\n{output}" | ||
| # Should contain Python rule() syntax somewhere in the keys | ||
| rule_keys = list(report.search_and_apply_time_per_rule.keys()) | ||
| assert len(rule_keys) > 0 | ||
| for key in rule_keys: | ||
| assert "__main__" not in key, f"RuleDecl key not translated: {key}" | ||
|
|
||
| def test_birewrite_decl(self): | ||
| egraph = EGraph() | ||
|
|
||
| class Num(Expr): | ||
| def __init__(self, n: i64Like) -> None: ... | ||
| def __add__(self, other: Num) -> Num: ... | ||
| def __mul__(self, other: Num) -> Num: ... | ||
|
|
||
| x, y = vars_("x y", Num) | ||
| egraph.register(birewrite(x + y).to(y + x)) | ||
| egraph.register(Num(1) + Num(2)) | ||
| report = egraph.run(10) | ||
|
|
||
| output = str(report) | ||
|
kaeun97 marked this conversation as resolved.
Outdated
|
||
| assert "__main__" not in output, f"BiRewriteDecl key not translated:\n{output}" | ||
| rule_keys = list(report.search_and_apply_time_per_rule.keys()) | ||
| assert len(rule_keys) > 0 | ||
| for key in rule_keys: | ||
| assert "__main__" not in key, f"BiRewriteDecl key not translated: {key}" | ||
| assert "birewrite" in key, f"Expected birewrite() syntax, got: {key}" | ||
|
|
||
| def test_rewrite_decl(self): | ||
| egraph = EGraph() | ||
|
|
||
| class Num(Expr): | ||
| def __init__(self, n: i64Like) -> None: ... | ||
| def __add__(self, other: Num) -> Num: ... | ||
|
|
||
| x, y = vars_("x y", Num) | ||
| egraph.register(rewrite(x + y).to(y + x)) | ||
| egraph.register(Num(1) + Num(2)) | ||
| report = egraph.run(10) | ||
|
|
||
| rule_keys = list(report.search_and_apply_time_per_rule.keys()) | ||
| assert len(rule_keys) == 1 | ||
| key = rule_keys[0] | ||
| assert "rewrite" in key, f"Expected rewrite() syntax, got: {key}" | ||
| assert "__main__" not in key, f"RewriteDecl key not translated: {key}" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.