GeezerVison is showing github.com — Fix lookup of value in cost model · mjdhasan/egglog-python@b18d3e7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/changelog.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ _This project uses semantic versioning_ | 13 | 13 | - Improve doctest support, teaching expressions about their `__module__`, `__dir__`, and special methods. | 14 | 14 | - Surface original Python exceptions from the runtime and tighten pretty-printing of values that cannot be re-parsed to make debugging e-graph executions easier. | 15 | 15 | - Update the bundled Egglog crate, visualizer, and related dev dependencies (including `ipykernel`) to pick up the latest backend fixes. | | 16 | +- Fix lookup of cost model based on value (see [zulip for issue](https://egraphs.zulipchat.com/#narrow/channel/375765-egg.2Fegglog/topic/Cost.20function.3A.20using.20function.20values.20of.20subtrees/near/577062352)) | 16 | 17 |
| 17 | 18 | ## 11.4.0 (2025-10-02) | 18 | 19 |
| |
Collapse file Copy file name to clipboardExpand all lines: python/egglog/egraph_state.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -683,6 +683,8 @@ def _generate_callable_egg_name(self, ref: CallableRef) -> str: | 683 | 683 | assert_never(ref) | 684 | 684 |
| 685 | 685 | def typed_expr_to_value(self, typed_expr: TypedExprDecl) -> bindings.Value: | | 686 | + if isinstance(typed_expr.expr, ValueDecl): | | 687 | + return typed_expr.expr.value | 686 | 688 | egg_expr = self.typed_expr_to_egg(typed_expr, False) | 687 | 689 | return self.egraph.eval_expr(egg_expr)[1] | 688 | 690 |
| |
Collapse file Copy file name to clipboardExpand all lines: python/tests/test_high_level.py +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1568,3 +1568,37 @@ def __radd__(self, other: object) -> tuple[X, X]: ... | 1568 | 1568 |
| 1569 | 1569 | assert X(1) + 10 == (X(1), 10) | 1570 | 1570 | assert 10 + X(1) == (X(10), X(1)) | | 1571 | + | | 1572 | + | | 1573 | +def test_custom_cost_model_size(): | | 1574 | + """ | | 1575 | + https://egraphs.zulipchat.com/#narrow/channel/375765-egg.2Fegglog/topic/Cost.20function.3A.20using.20function.20values.20of.20subtrees/near/577062352 | | 1576 | + """ | | 1577 | + | | 1578 | + class KAT(Expr): | | 1579 | + @classmethod | | 1580 | + def eps(cls) -> KAT: ... | | 1581 | + | | 1582 | + @classmethod | | 1583 | + def emp(cls) -> KAT: ... | | 1584 | + | | 1585 | + def func(self, other: KAT) -> KAT: ... | | 1586 | + | | 1587 | + def size(self) -> i64: ... | | 1588 | + | | 1589 | + eps, emp = KAT.eps(), KAT.emp() | | 1590 | + | | 1591 | + eg = EGraph() | | 1592 | + q0 = eg.let("q0", KAT.func(eps, emp)) | | 1593 | + | | 1594 | + eg.register(set_(eps.size()).to(1)) | | 1595 | + eg.register(set_(emp.size()).to(0)) | | 1596 | + | | 1597 | + def conv_cost(eg, expr, child_costs): | | 1598 | + if isinstance(expr, KAT): | | 1599 | + args = get_callable_args(expr) | | 1600 | + return sum(int(eg.lookup_function_value(cast("KAT", a).size())) for a in args) | | 1601 | + | | 1602 | + return 2 | | 1603 | + | | 1604 | + assert eg.extract(q0, include_cost=True, cost_model=conv_cost) == (KAT.eps().func(KAT.emp()), 1) |
|