pymbolic icon indicating copy to clipboard operation
pymbolic copied to clipboard

Do not simplify in overloaded operators, type mappers

Open inducer opened this issue 1 year ago • 2 comments

Closes #11. Closes #149.

What finally tipped the balance is that the overload-y operators are hard to precisely type, which made typing various downstream user packages unnecessarily hard.

  • [x] Add a mapper that applies these same simplifications.
  • [ ] Fix pymbolic CI
  • [ ] Fix downstream CIs
  • [ ] Finish typing at least the base mappers
  • [x] Figure out whether this can be compatible with present-day (unfixed) loopy enough to not break Firedrake
    • It cannot. See https://github.com/inducer/loopy/pull/871.
  • [ ] Reset ruff target version to 3.10
  • [ ] Upgrade Python min version in dependencies, adjust CI versions
    • [ ] loopy
    • [ ] pytato
    • [ ] pytential
    • [ ] grudge
    • [ ] modepy
    • [ ] sumpy
  • [ ] Updated required CI components

cc @kaushikcfd

inducer avatar Oct 06 '24 17:10 inducer

Downstreams seem very upset with it though :(

They sure are. I'm trying to figure out whether the damage can be controlled or whether we need to do this in a more piecemeal fashion.

inducer avatar Oct 21 '24 17:10 inducer

pytential seems to work with this patch (didn't run all the testsuite though)

diff --git a/pymbolic/geometric_algebra/__init__.py b/pymbolic/geometric_algebra/__init__.py
index fbc7e30..4291b74 100644
--- a/pymbolic/geometric_algebra/__init__.py
+++ b/pymbolic/geometric_algebra/__init__.py
@@ -526,6 +526,7 @@ class MultiVector(Generic[CoeffT]):
"""

space: Space
+    mapper_method = "map_multivector"

# {{{ construction

diff --git a/pymbolic/mapper/coefficient.py b/pymbolic/mapper/coefficient.py
index 99516f0..b09b4f6 100644
--- a/pymbolic/mapper/coefficient.py
+++ b/pymbolic/mapper/coefficient.py
@@ -100,6 +100,9 @@ class CoefficientCollector(Mapper):
return {1: expr}

def map_constant(self, expr):
+        if expr == 0:
+            return {}
+
return {1: expr}

def map_algebraic_leaf(self, expr):

EDIT: Well, that was wrong, there are other errors too :( EDIT: It seems to be missing some handling for MultiVector. Not sure why that worked before.. EDIT: Ugh, all the map_multivector need to be changed to map_multi_vector. Better to overwrite the default mapper_method for it?

alexfikl avatar Oct 23 '24 07:10 alexfikl