Implement in-house unification#2120
Draft
ricardoV94 wants to merge 2 commits into
Draft
Conversation
ricardoV94
commented
May 11, 2026
Comment on lines
+293
to
+297
| def _is_commutative_op(op) -> bool: | ||
| if getattr(op, "commutative", False): | ||
| return True | ||
| scalar_op = getattr(op, "scalar_op", None) | ||
| return bool(getattr(scalar_op, "commutative", False)) |
Member
Author
There was a problem hiding this comment.
Move this info to Elemwise (it can borrow it from the core op)
c268345 to
29d65cf
Compare
Drops logical-unification, kanren, etuples and cons as required deps; they move to the `pytensor[kanren]` extra (still pulled in by `pytensor[tests]`). Importing pytensor.graph.rewriting.kanren registers PatternVar via Var.register so external isinstance(x, unification.Var) / isvar(x) still hold. 10-20x faster match in microbenchmarks.
Commutativity is detected from op.commutative (or scalar_op.commutative for Elemwise). The matcher tries the original input order in place first; only on failure does it copy subs and backtrack through permutations. Asterisk preserves input order in both paths.
Member
Author
|
One reason I want this is that right now I'm weary of using PatternNodeRewriter rewrites even in cases where it's much cleaner to express like this because of poor performance. Eg noted a missing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second commit serves to illustrate the advantages of implementing our own unification machinery.
This should also facilitate integration with equality-saturation rewrites.
Also performance:
And less dependencies!
Closes #1609