Skip to content

Commit b9f201c

Browse files
Merge pull request #375 from egraphs-good/update-uv
Add support for setting report level with `egraph.set_report_level`
2 parents 6421045 + fe300b6 commit b9f201c

File tree

8 files changed

+587
-48
lines changed

8 files changed

+587
-48
lines changed

Cargo.lock

Lines changed: 231 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ crate-type = ["cdylib"]
1313
pyo3 = { version = "0.27", features = ["extension-module", "num-bigint", "num-rational"] }
1414
num-bigint = "*"
1515
num-rational = "*"
16-
# egglog = { git = "https://github.com/egraphs-good/egglog.git", branch = "main", default-features = false }
17-
# egglog-bridge = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
18-
# egglog-core-relations = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
19-
egglog = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again", default-features = false }
20-
egglog-bridge = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again" }
21-
egglog-core-relations = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again" }
22-
egglog-experimental = { git = "https://github.com/egraphs-good/egglog-experimental", branch = "update-egglog", default-features = false }
23-
egglog-ast = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again" }
16+
egglog = { git = "https://github.com/egraphs-good/egglog.git", branch = "main", default-features = false }
17+
egglog-bridge = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
18+
egglog-core-relations = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
19+
egglog-experimental = { git = "https://github.com/egraphs-good/egglog-experimental", branch = "main", default-features = false }
20+
egglog-ast = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
21+
egglog-reports = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
2422
egraph-serialize = { version = "0.3", features = ["serde", "graphviz"] }
2523
serde_json = "1"
26-
pyo3-log = { git = "https://github.com/a1phyr/pyo3-log.git", branch = "pyo3_0.27" }
24+
pyo3-log = "*"
2725
log = "0.4"
2826
lalrpop-util = { version = "0.22", features = ["lexer"] }
2927
ordered-float = "5"
@@ -33,13 +31,10 @@ base64 = "0.22.1"
3331

3432
# Use patched version of egglog in experimental
3533
[patch.'https://github.com/egraphs-good/egglog']
36-
# egglog = { git = "https://github.com/egraphs-good//egglog.git", branch = "main" }
37-
egglog = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again" }
38-
egglog-bridge = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again" }
39-
egglog-core-relations = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again" }
40-
egglog-ast = { git = "https://github.com/saulshanabrook/egg-smol.git", branch = "let-bindings-again" }
41-
# egglog = { path = "../egg-smol" }
42-
# egglog = { git = "https://github.com/egraphs-good//egglog.git", rev = "5542549" }
34+
# egglog = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
35+
# egglog-bridge = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
36+
# egglog-core-relations = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
37+
# egglog-ast = { git = "https://github.com/egraphs-good/egglog.git", branch = "main" }
4338

4439
# enable debug symbols for easier profiling
4540
[profile.release]

docs/changelog.md

Lines changed: 1 addition & 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 support for setting report level with `egraph.set_report_level` [#375](https://github.com/egraphs-good/egglog-python/pull/375)
78
- Make docs builds fail on notebook execution errors and fix all doc issues [#369](https://github.com/egraphs-good/egglog-python/pull/369)
89
- Add WIP `egglog.exp.any_expr` code for tracing arbitrary expressions with Python fallback [#366](https://github.com/egraphs-good/egglog-python/pull/366)
910
- BREAKING: Remove support for Python 3.11 now that pyo3 has dropped support.

python/egglog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from . import config, ipython_magic # noqa: F401
6-
from .bindings import EggSmolError # noqa: F401
6+
from .bindings import EggSmolError, StageInfo, TimeOnly, WithPlan # noqa: F401
77
from .builtins import * # noqa: UP029
88
from .conversion import *
99
from .deconstruct import *

python/egglog/bindings.pyi

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ __all__ = [
3333
"Float",
3434
"Function",
3535
"FunctionCommand",
36+
"FusedIntersect",
3637
"IdentSort",
3738
"Include",
3839
"Input",
3940
"Int",
41+
"Intersect",
42+
"IterationReport",
4043
"Let",
4144
"Lit",
4245
"NewSort",
4346
"Output",
4447
"OverallStatistics",
4548
"Panic",
4649
"PanicSpan",
50+
"Plan",
4751
"Pop",
4852
"PrintAllFunctionsSize",
4953
"PrintFunction",
@@ -58,26 +62,33 @@ __all__ = [
5862
"RewriteCommand",
5963
"Rule",
6064
"RuleCommand",
65+
"RuleReport",
66+
"RuleSetReport",
6167
"Run",
6268
"RunConfig",
6369
"RunReport",
6470
"RunSchedule",
6571
"RunScheduleOutput",
6672
"RustSpan",
6773
"Saturate",
74+
"Scan",
6875
"Schema",
6976
"Sequence",
7077
"SerializedEGraph",
7178
"Set",
79+
"SingleScan",
7280
"Sort",
7381
"SrcFile",
82+
"StageInfo",
83+
"StageStats",
7484
"String",
7585
"SubVariants",
7686
"Subsume",
7787
"TermApp",
7888
"TermDag",
7989
"TermLit",
8090
"TermVar",
91+
"TimeOnly",
8192
"Union",
8293
"Unit",
8394
"UnstableCombinedRuleset",
@@ -87,6 +98,7 @@ __all__ = [
8798
"Value",
8899
"Var",
89100
"Variant",
101+
"WithPlan",
90102
]
91103

92104
@final
@@ -118,6 +130,7 @@ class EGraph:
118130
max_calls_per_function: int | None = None,
119131
include_temporary_functions: bool = False,
120132
) -> SerializedEGraph: ...
133+
def set_report_level(self, level: _ReportLevel) -> None: ...
121134
def lookup_function(self, name: str, key: list[Value]) -> Value | None: ...
122135
def eval_expr(self, expr: _Expr) -> tuple[str, Value]: ...
123136
def value_to_i64(self, v: Value) -> int: ...
@@ -389,12 +402,99 @@ class IdentSort:
389402
@final
390403
class UserDefinedCommandOutput: ...
391404

405+
@final
406+
class SingleScan:
407+
atom: str
408+
column: tuple[str, int]
409+
410+
def __new__(cls, atom: str, column: tuple[str, int]) -> SingleScan: ...
411+
412+
@final
413+
class Scan:
414+
atom: str
415+
columns: list[tuple[str, int]]
416+
417+
def __new__(cls, atom: str, columns: list[tuple[str, int]]) -> Scan: ...
418+
419+
@final
420+
class StageStats:
421+
num_candidates: int
422+
num_succeeded: int
423+
424+
def __new__(cls, num_candidates: int, num_succeeded: int) -> StageStats: ...
425+
426+
@final
427+
class TimeOnly:
428+
def __new__(cls) -> TimeOnly: ...
429+
430+
@final
431+
class WithPlan:
432+
def __new__(cls) -> WithPlan: ...
433+
434+
@final
435+
class StageInfo:
436+
def __new__(cls) -> StageInfo: ...
437+
438+
_ReportLevel: TypeAlias = TimeOnly | WithPlan | StageInfo
439+
440+
@final
441+
class Intersect:
442+
scans: list[SingleScan]
443+
444+
def __new__(cls, scans: list[SingleScan]) -> Intersect: ...
445+
446+
@final
447+
class FusedIntersect:
448+
cover: Scan
449+
to_intersect: list[Scan]
450+
451+
def __new__(cls, cover: Scan, to_intersect: list[Scan]) -> FusedIntersect: ...
452+
453+
_Stage: TypeAlias = Intersect | FusedIntersect
454+
455+
@final
456+
class Plan:
457+
stages: list[tuple[_Stage, StageStats | None, list[int]]]
458+
459+
def __new__(cls, stages: list[tuple[_Stage, StageStats | None, list[int]]]) -> Plan: ...
460+
461+
@final
462+
class RuleReport:
463+
plan: Plan | None
464+
search_and_apply_time: timedelta
465+
num_matches: int
466+
467+
def __new__(cls, plan: Plan | None, search_and_apply_time: timedelta, num_matches: int) -> RuleReport: ...
468+
469+
@final
470+
class RuleSetReport:
471+
changed: bool
472+
rule_reports: dict[str, list[RuleReport]]
473+
search_and_apply_time: timedelta
474+
merge_time: timedelta
475+
476+
def __new__(
477+
cls,
478+
changed: bool,
479+
rule_reports: dict[str, list[RuleReport]],
480+
search_and_apply_time: timedelta,
481+
merge_time: timedelta,
482+
) -> RuleSetReport: ...
483+
484+
@final
485+
class IterationReport:
486+
rule_set_report: RuleSetReport
487+
rebuild_time: timedelta
488+
489+
def __new__(cls, rule_set_report: RuleSetReport, rebuild_time: timedelta) -> IterationReport: ...
490+
392491
@final
393492
class Function:
394493
name: str
395494

396495
@final
397496
class RunReport:
497+
iterations: list[IterationReport]
398498
updated: bool
399499
search_and_apply_time_per_rule: dict[str, timedelta]
400500
num_matches_per_rule: dict[str, int]
@@ -404,6 +504,7 @@ class RunReport:
404504

405505
def __new__(
406506
cls,
507+
iterations: list[IterationReport],
407508
updated: bool,
408509
search_and_apply_time_per_rule: dict[str, timedelta],
409510
num_matches_per_rule: dict[str, int],
@@ -688,7 +789,11 @@ class Constructor:
688789
def __new__(cls, span: _Span, name: str, schema: Schema, cost: int | None, unextractable: bool) -> Constructor: ...
689790

690791
@final
691-
class PrintOverallStatistics: ...
792+
class PrintOverallStatistics:
793+
span: _Span
794+
file: str | None
795+
796+
def __new__(cls, span: _Span, file: str | None) -> PrintOverallStatistics: ...
692797

693798
@final
694799
class UserDefined:

python/egglog/egraph.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"vars_",
106106
]
107107

108+
108109
T = TypeVar("T")
109110
P = ParamSpec("P")
110111
EXPR_TYPE = TypeVar("EXPR_TYPE", bound="type[Expr]")
@@ -869,6 +870,12 @@ def _add_decls(self, *decls: DeclerationsLike) -> None:
869870
for d in decls:
870871
self._state.__egg_decls__ |= d
871872

873+
def set_report_level(self, level: bindings._ReportLevel) -> None:
874+
"""
875+
Set the level of detail recorded in subsequent run reports.
876+
"""
877+
self._egraph.set_report_level(level)
878+
872879
@property
873880
def as_egglog_string(self) -> str:
874881
"""
@@ -948,7 +955,7 @@ def stats(self) -> bindings.RunReport:
948955
"""
949956
Returns the overall run report for the egraph.
950957
"""
951-
(output,) = self._egraph.run_program(bindings.PrintOverallStatistics())
958+
(output,) = self._egraph.run_program(bindings.PrintOverallStatistics(span(1), None))
952959
assert isinstance(output, bindings.OverallStatistics)
953960
return output.report
954961

0 commit comments

Comments
 (0)