Skip to content

Commit aba85fd

Browse files
committed
Pin UWexpression _op_priority back to sympy default (avoid Matrix/UWexpression regression)
The previous commit set MathematicalMixin._op_priority = 11.5 to win sympy dispatch over Matrix (10.01) for the bare-variable composition case. UWexpression inherits from MathematicalMixin (first in MRO), so that change inadvertently bumped UWexpression's priority too — and UWexpression has its OWN __rtruediv__ (and __rmul__, etc.) for sympy interop. Its __rmul__ explicitly handles MutableDenseMatrix; its __rtruediv__ does not, falling through to Symbol.__rtruediv__ which fails on MatrixBase. Result: solvers that compute Matrix / UWexpression (e.g. SNES_Diffusion's F0 expression `self.DuDt.bdf(0) / self.delta_t` at solvers.py:2499) broke with TypeError on every transient/Darcy/AdvDiff path. CI surfaced this on test_1005, test_1006, test_1100, test_1110. Fix: explicitly set UWexpression._op_priority = 10.0 to opt out of the mixin's bump. UWexpression already handles Matrix dispatch correctly through its own dunders (and via sympy's standard machinery for fall-through cases); it doesn't need the priority bump that pure MathematicalMixin classes (EnhancedMeshVariable, SwarmVariable) need. Verified: - #137 4-case reproducer still passes (the original fix is intact). - Previously-failing tests all pass: test_1005_TransientDarcyCartesian, test_1006_RichardsCartesian, test_1100_AdvDiffCartesian, test_1110_advDiffAnnulus — 8/8 pass. - pytest -m "level_1 and tier_a" on amr-dev: 56 passed, 3 skipped, 0 failed. Underworld development team with AI support from Claude Code
1 parent 57d156c commit aba85fd

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/underworld3/function/expressions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,18 @@ class UWexpression(MathematicalMixin, uw_object, Symbol):
629629
# Slot for unique ID used in _hashable_content (like sympy.Dummy)
630630
__slots__ = ('_uw_id',)
631631

632+
# Override the MathematicalMixin priority bump back to sympy's default.
633+
# MathematicalMixin sets _op_priority = 11.5 to win dispatch over
634+
# sympy.Matrix (10.01) for the bare-variable composition case (#137 —
635+
# MeshVariable / SwarmVariable on the right of a sympified subexpression).
636+
# UWexpression is itself a sympy.Symbol subclass with its own __rmul__ /
637+
# __rtruediv__ that already handle the Matrix case; inheriting the high
638+
# priority would route Matrix / UWexpression through UWexpression's
639+
# __rtruediv__ (which falls back to Symbol.__rtruediv__ → fails on
640+
# MutableDenseMatrix). Pin it back to 10.0 so sympy's standard
641+
# Matrix-dispatch path keeps handling these.
642+
_op_priority = 10.0
643+
632644
def __new__(
633645
cls,
634646
name,

0 commit comments

Comments
 (0)