Skip to content

Commit c7711b5

Browse files
Merge fix-lookup-value into polynomials
2 parents f5d993b + 27f70d1 commit c7711b5

9 files changed

Lines changed: 1790 additions & 1746 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "egglog_python"
3-
version = "12.0.0"
3+
version = "13.0.1"
44
edition = "2024"
55

66

context7.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"url": "https://context7.com/egraphs-good/egglog-python",
3+
"public_key": "pk_OgxDfp3XyhQai6fY0aQTI"
4+
}

docs/changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ _This project uses semantic versioning_
44

55
## UNRELEASED
66

7-
- Support using facts as union actions, add conversions to multisets, and update multiset examlpe [#382](https://github.com/egraphs-good/egglog-python/pull/382)
7+
## 13.0.1 (2026-03-04)
8+
9+
- Fix install by adding cloudpickle as required dependency [#405](https://github.com/egraphs-good/egglog-python/pull/405)
10+
- Add __classdictcell__ to ignored attributes (Python 3.14 support) [#403](https://github.com/egraphs-good/egglog-python/pull/403)
11+
## 13.0.0 (2026-03-03)
12+
13+
- Support using facts as union actions, add conversions to multisets, and update multiset example [#382](https://github.com/egraphs-good/egglog-python/pull/382)
14+
- 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))
815

916
## 12.0.0 (2025-11-16)
1017

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers = [
2626
"Topic :: Software Development :: Interpreters",
2727
"Typing :: Typed",
2828
]
29-
dependencies = ["typing-extensions", "black", "graphviz", "anywidget"]
29+
dependencies = ["typing-extensions", "black", "graphviz", "anywidget", "cloudpickle>=3"]
3030

3131
[project.optional-dependencies]
3232

@@ -35,8 +35,7 @@ array = [
3535
"array_api_compat",
3636
"numba>=0.59.1",
3737
"llvmlite>=0.42.0",
38-
"numpy>2",
39-
"cloudpickle>=3",
38+
"numpy>2"
4039
]
4140
dev = [
4241
"ruff",

python/egglog/egraph.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@
130130
"__firstlineno__",
131131
"__static_attributes__",
132132
"__match_args__",
133+
# Added in 3.14
134+
# https://egraphs.zulipchat.com/#narrow/channel/375765-egg.2Fegglog/topic/Cost.20function.3A.20using.20function.20values.20of.20subtrees/near/577236488
135+
"__classdictcell__",
133136
# Ignore all reflected binary method
134137
*(f"__r{m[2:]}" for m in NUMERIC_BINARY_METHODS),
135138
}

python/egglog/egraph_state.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ def _generate_callable_egg_name(self, ref: CallableRef) -> str:
680680
assert_never(ref)
681681

682682
def typed_expr_to_value(self, typed_expr: TypedExprDecl) -> bindings.Value:
683+
if isinstance(typed_expr.expr, ValueDecl):
684+
return typed_expr.expr.value
683685
egg_expr = self.typed_expr_to_egg(typed_expr, False)
684686
return self.egraph.eval_expr(egg_expr)[1]
685687

python/tests/test_high_level.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,3 +1568,37 @@ def __radd__(self, other: object) -> tuple[X, X]: ...
15681568

15691569
assert X(1) + 10 == (X(1), 10)
15701570
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(i64(1)))
1595+
eg.register(set_(emp.size()).to(i64(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)

uv.lock

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

0 commit comments

Comments
 (0)