feat: add pretty run report#416
Conversation
saulshanabrook
left a comment
There was a problem hiding this comment.
Thank you for this! Added a few comments. Could you also add this to the changelog file with a link to this PR?
|
|
||
| @overload | ||
| def run(self, limit: int, /, *until: Fact, ruleset: Ruleset | None = None) -> bindings.RunReport: ... | ||
| def run(self, limit: int, /, *until: Fact, ruleset: Ruleset | None = None) -> PrettyRunReport: ... |
There was a problem hiding this comment.
I think we can just call it RunReport. I have a few places I use the same name in the high level in bindings, such as EGraph itself. Since the hope is that users won't ever have to import from bindings, this shouldn't clobber the name.
| """ | ||
| if egglog_key in self.egg_rule_to_command_decl: | ||
| return pretty_decl(self.__egg_decls__, self.egg_rule_to_command_decl[egglog_key]) | ||
| return egglog_key |
There was a problem hiding this comment.
Is there any cases where it won't find the saved command? If possible seems better to raise an exception instead of falling back.
| @dataclass | ||
| class PrettyRuleSetReport: | ||
| changed: bool | ||
| rule_reports: dict[str, list[PrettyRuleReport]] |
There was a problem hiding this comment.
Could we try storing them as actual rewrites/rules here instead of strings? That would allow users at runtime for example to extract the rule, run it on something, or compare equality without having to compare string equality. Also just in others forms I usually try to return runtime objects instead of strings.
This would also impact how they are stored in e-graph state.
Then also the pretty print won't show them as strings.
| rebuild_time_per_ruleset: dict[str, timedelta] | ||
|
|
||
| @classmethod | ||
| def from_bindings(cls, report: bindings.RunReport, state: EGraphState) -> PrettyRunReport: |
There was a problem hiding this comment.
Could we make these private, prefixing with _? I don't imagine that users would need to be able to translate between bindings and this.
| merge_time: timedelta | ||
|
|
||
| @classmethod | ||
| def from_bindings(cls, report: bindings.RuleSetReport, translate_key: callable) -> PrettyRuleSetReport: |
There was a problem hiding this comment.
Could this callable be more strongly typed?
Resolves #398.
Here is an example code:
Output before:
Output after: