Skip to content

sympy.Max/Min(UWexpression, plain number) crashes at construction: AttributeError '_prec' #415

Closed

Description

@lmoresi

Found by the #302 adversarial review (2026-07-24), pre-existing (reproduced identically on unmodified development):

k = uw.expression(r'k', 1.0, 'constant')
sympy.Max(k, 0.5)   # AttributeError: 'UWexpression' object has no attribute '_prec'

UWexpression reports is_comparable=True, so sympy's Max/Min attempts an immediate numeric comparison and reaches for the Float internals (_prec) that a Symbol subclass doesn't have. The failure is loud (not a silent-bake hazard), but it blocks the natural way of writing clamped/floored constants — users must route through uw.maths.smooth_max or wrap differently.

Likely fix: UWexpression should not advertise is_comparable (it is symbolic until packed), or MathematicalMixin should intercept Max/Min construction. See src/underworld3/utilities/mathematical_mixin.py.

Underworld development team with AI support from Claude Code

Activity

  1. lmoresi commented on Jul 28, 2026

    @lmoresi
    MemberAuthor

    Fixed by PR #456, merged to development on 2026-07-28. (Manual close — PRs target development, so auto-close doesn't fire.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions