-
Notifications
You must be signed in to change notification settings - Fork 19
Fix lookup of value in cost model #401
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1568,3 +1568,37 @@ def __radd__(self, other: object) -> tuple[X, X]: ... | |
|
|
||
| assert X(1) + 10 == (X(1), 10) | ||
| assert 10 + X(1) == (X(10), X(1)) | ||
|
|
||
|
|
||
| def test_custom_cost_model_size(): | ||
| """ | ||
| https://egraphs.zulipchat.com/#narrow/channel/375765-egg.2Fegglog/topic/Cost.20function.3A.20using.20function.20values.20of.20subtrees/near/577062352 | ||
| """ | ||
|
|
||
| class KAT(Expr): | ||
| @classmethod | ||
| def eps(cls) -> KAT: ... | ||
saulshanabrook marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
|
|
||
| @classmethod | ||
| def emp(cls) -> KAT: ... | ||
saulshanabrook marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
|
|
||
| def func(self, other: KAT) -> KAT: ... | ||
saulshanabrook marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
|
|
||
| def size(self) -> i64: ... | ||
saulshanabrook marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
|
|
||
| eps, emp = KAT.eps(), KAT.emp() | ||
|
|
||
| eg = EGraph() | ||
| q0 = eg.let("q0", KAT.func(eps, emp)) | ||
|
|
||
| eg.register(set_(eps.size()).to(i64(1))) | ||
| eg.register(set_(emp.size()).to(i64(0))) | ||
|
|
||
| def conv_cost(eg, expr, child_costs): | ||
| if isinstance(expr, KAT): | ||
| args = get_callable_args(expr) | ||
| return sum(int(eg.lookup_function_value(cast("KAT", a).size())) for a in args) | ||
|
Comment on lines
+1597
to
+1600
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check for linting issues and find get_callable_args definition
ruff check python/tests/test_high_level.py --select ARG001,F405
echo "---"
rg -n "def get_callable_args|from \.deconstruct import get_callable_args|__all__" python/egglog/deconstruct.py python/egglog/__init__.pyRepository: egraphs-good/egglog-python Length of output: 50383 🏁 Script executed: #!/bin/bash
# Read the full function and surrounding context
sed -n '1590,1610p' python/tests/test_high_level.pyRepository: egraphs-good/egglog-python Length of output: 542 🏁 Script executed: #!/bin/bash
# Find the definition of get_callable_args to check return type
rg -A 10 "^def get_callable_args" python/egglog/Repository: egraphs-good/egglog-python Length of output: 1276 Harden
Suggested patch-def conv_cost(eg, expr, child_costs):
+def conv_cost(eg, expr, _child_costs):
if isinstance(expr, KAT):
- args = get_callable_args(expr)
+ args = get_callable_args(expr) or ()
return sum(int(eg.lookup_function_value(cast("KAT", a).size())) for a in args)🧰 Tools🪛 Ruff (0.15.2)[warning] 1597-1597: Unused function argument: (ARG001) [error] 1599-1599: (F405) 🤖 Prompt for AI Agents |
||
|
|
||
| return 2 | ||
|
|
||
| assert eg.extract(q0, include_cost=True, cost_model=conv_cost) == (KAT.eps().func(KAT.emp()), 1) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: egraphs-good/egglog-python
Length of output: 50383
🏁 Script executed:
Repository: egraphs-good/egglog-python
Length of output: 888
🏁 Script executed:
Repository: egraphs-good/egglog-python
Length of output: 1176
Add explicit import of
ValueDeclto fix Ruff F405.The new
isinstance(typed_expr.expr, ValueDecl)check at line 686 triggers Ruff F405 sinceValueDeclis only available through the star import. Add it to the explicit imports to keep the codebase lint-clean.Suggested patch
🧰 Tools
🪛 Ruff (0.15.2)
[error] 686-686:
ValueDeclmay be undefined, or defined from star imports(F405)
🤖 Prompt for AI Agents