devito icon indicating copy to clipboard operation
devito copied to clipboard

prevent failure in pow_to_mul when using Piecewise in an equation

Open mmohrhard opened this issue 2 months ago • 0 comments

Previously the test would fail with:

    def test_piecewise():
        grid = Grid(shape=(11,))
        u = Function(name='u', grid=grid, space_order=2)
        v = Function(name='u', grid=grid, space_order=2)
        eq_u = Eq(u, Piecewise((1, v < 10), (2, True)))
>       op = Operator(eq_u)
             ^^^^^^^^^^^^^^

tests/test_symbolics.py:1112:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
devito/operator/operator.py:173: in __new__
    op = cls._build(expressions, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devito/operator/operator.py:206: in _build
    irs, byproduct = cls._lower(expressions, profiler=profiler, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devito/operator/operator.py:288: in _lower
    clusters = cls._lower_clusters(expressions, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devito/tools/timing.py:76: in __call__
    retval = self.func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
devito/operator/operator.py:397: in _lower_clusters
    clusters = cls._specialize_clusters(clusters, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devito/tools/timing.py:76: in __call__
    retval = self.func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
devito/core/cpu.py:178: in _specialize_clusters
    clusters = optimize_pows(clusters)
               ^^^^^^^^^^^^^^^^^^^^^^^
devito/ir/clusters/visitors.py:174: in __call__
    processed = [maybe_timed(c, *args) if self.cond(c) else c
                 ^^^^^^^^^^^^^^^^^^^^^
devito/ir/clusters/visitors.py:167: in <lambda>
    timed_pass(self.func, self.func.__name__)(*_args, **kwargs)
devito/tools/timing.py:76: in __call__
    retval = self.func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
devito/passes/clusters/misc.py:423: in optimize_pows
    return cluster.rebuild(exprs=[pow_to_mul(e) for e in cluster.exprs])
                                  ^^^^^^^^^^^^^
devito/symbolics/manipulation.py:360: in pow_to_mul
    args = [pow_to_mul(i) for i in expr.args]
            ^^^^^^^^^^^^^
devito/symbolics/manipulation.py:360: in pow_to_mul
    args = [pow_to_mul(i) for i in expr.args]
            ^^^^^^^^^^^^^
E           TypeError: ExprCondPair.__new__() got an unexpected keyword argument 'evaluate'

devito/symbolics/manipulation.py:373: TypeError

mmohrhard avatar Oct 20 '25 19:10 mmohrhard