-
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
Open
kaeun97
wants to merge
12
commits into
egraphs-good:main
Choose a base branch
from
kaeun97:kaeun97/pretty-report
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 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 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
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,142 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from datetime import timedelta | ||
|
|
||
| from . import bindings | ||
| from .declarations import BiRewriteDecl, Declarations, RewriteDecl, RuleDecl | ||
| from .egraph_state import EGraphState | ||
| from .pretty import pretty_decl | ||
|
|
||
| RewriteOrRuleDecl = RuleDecl | BiRewriteDecl | RewriteDecl | ||
|
|
||
|
|
||
| def _format_rule_key(decls: Declarations, key: RewriteOrRuleDecl) -> str: | ||
| return pretty_decl(decls, key) | ||
|
|
||
|
|
||
| @dataclass | ||
| class RuleReport: | ||
| plan: bindings.Plan | None | ||
| search_and_apply_time: timedelta | ||
| num_matches: int | ||
|
|
||
| @classmethod | ||
| def _from_bindings(cls, report: bindings.RuleReport) -> RuleReport: | ||
| return cls( | ||
| plan=report.plan, | ||
| search_and_apply_time=report.search_and_apply_time, | ||
| num_matches=report.num_matches, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class RuleSetReport: | ||
| _decls: Declarations = field(repr=False) | ||
| changed: bool = False | ||
| rule_reports: dict[RewriteOrRuleDecl, list[RuleReport]] = field(default_factory=dict) | ||
| search_and_apply_time: timedelta = field(default_factory=timedelta) | ||
| merge_time: timedelta = field(default_factory=timedelta) | ||
|
|
||
| @classmethod | ||
| def _from_bindings( | ||
| cls, report: bindings.RuleSetReport, rule_map: dict[str, RewriteOrRuleDecl], decls: Declarations | ||
| ) -> RuleSetReport: | ||
| rule_reports: dict[RewriteOrRuleDecl, list[RuleReport]] = {} | ||
| for k, v in report.rule_reports.items(): | ||
| translated = rule_map[k] | ||
| reports = [RuleReport._from_bindings(rr) for rr in v] | ||
| if translated in rule_reports: | ||
| rule_reports[translated].extend(reports) | ||
| else: | ||
| rule_reports[translated] = reports | ||
| return cls( | ||
| _decls=decls, | ||
| changed=report.changed, | ||
| rule_reports=rule_reports, | ||
| search_and_apply_time=report.search_and_apply_time, | ||
| merge_time=report.merge_time, | ||
| ) | ||
|
|
||
| def __repr__(self) -> str: | ||
| rule_reports_str = {_format_rule_key(self._decls, k): v for k, v in self.rule_reports.items()} | ||
| return ( | ||
| f"RuleSetReport(changed={self.changed}, " | ||
| f"rule_reports={rule_reports_str}, " | ||
| f"search_and_apply_time={self.search_and_apply_time}, " | ||
| f"merge_time={self.merge_time})" | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class IterationReport: | ||
| rule_set_report: RuleSetReport | ||
| rebuild_time: timedelta | ||
|
|
||
| @classmethod | ||
| def _from_bindings( | ||
| cls, report: bindings.IterationReport, rule_map: dict[str, RewriteOrRuleDecl], decls: Declarations | ||
| ) -> IterationReport: | ||
| return cls( | ||
| rule_set_report=RuleSetReport._from_bindings(report.rule_set_report, rule_map, decls), | ||
| rebuild_time=report.rebuild_time, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class RunReport: | ||
| """Python-friendly wrapper around bindings.RunReport.""" | ||
|
|
||
| _decls: Declarations = field(repr=False) | ||
| iterations: list[IterationReport] = field(default_factory=list) | ||
| updated: bool = False | ||
| search_and_apply_time_per_rule: dict[RewriteOrRuleDecl, timedelta] = field(default_factory=dict) | ||
| num_matches_per_rule: dict[RewriteOrRuleDecl, int] = field(default_factory=dict) | ||
| search_and_apply_time_per_ruleset: dict[str, timedelta] = field(default_factory=dict) | ||
| merge_time_per_ruleset: dict[str, timedelta] = field(default_factory=dict) | ||
| rebuild_time_per_ruleset: dict[str, timedelta] = field(default_factory=dict) | ||
|
|
||
| def __repr__(self) -> str: | ||
| time_per_rule = {_format_rule_key(self._decls, k): v for k, v in self.search_and_apply_time_per_rule.items()} | ||
| matches_per_rule = {_format_rule_key(self._decls, k): v for k, v in self.num_matches_per_rule.items()} | ||
| return ( | ||
| f"RunReport(iterations={self.iterations}, " | ||
| f"updated={self.updated}, " | ||
| f"search_and_apply_time_per_rule={time_per_rule}, " | ||
| f"num_matches_per_rule={matches_per_rule}, " | ||
| f"search_and_apply_time_per_ruleset={self.search_and_apply_time_per_ruleset}, " | ||
| f"merge_time_per_ruleset={self.merge_time_per_ruleset}, " | ||
| f"rebuild_time_per_ruleset={self.rebuild_time_per_ruleset})" | ||
| ) | ||
|
|
||
| @classmethod | ||
| def _from_bindings(cls, report: bindings.RunReport, state: EGraphState) -> RunReport: | ||
| rule_map = state.rule_name_to_command_decl | ||
| decls = state.__egg_decls__ | ||
|
|
||
| search_and_apply_time_per_rule: dict[RewriteOrRuleDecl, timedelta] = {} | ||
| for k, v in report.search_and_apply_time_per_rule.items(): | ||
| translated = rule_map[k] | ||
| if translated in search_and_apply_time_per_rule: | ||
| search_and_apply_time_per_rule[translated] += v | ||
| else: | ||
| search_and_apply_time_per_rule[translated] = v | ||
|
|
||
| num_matches_per_rule: dict[RewriteOrRuleDecl, int] = {} | ||
| for k, v in report.num_matches_per_rule.items(): | ||
| translated = rule_map[k] | ||
| if translated in num_matches_per_rule: | ||
| num_matches_per_rule[translated] += v | ||
| else: | ||
| num_matches_per_rule[translated] = v | ||
|
|
||
| return cls( | ||
| _decls=decls, | ||
| iterations=[IterationReport._from_bindings(it, rule_map, decls) for it in report.iterations], | ||
| updated=report.updated, | ||
| search_and_apply_time_per_rule=search_and_apply_time_per_rule, | ||
| num_matches_per_rule=num_matches_per_rule, | ||
| search_and_apply_time_per_ruleset=report.search_and_apply_time_per_ruleset, | ||
| merge_time_per_ruleset=report.merge_time_per_ruleset, | ||
| rebuild_time_per_ruleset=report.rebuild_time_per_ruleset, | ||
| ) |
Oops, something went wrong.
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.