devitocodes / devito

DSL and compiler framework for automated finite-differences and stencil computation
http://www.devitoproject.org
MIT License
555 stars 225 forks source link

Weird Sympy Behavior with ConstantData #331

Closed mloubout closed 6 years ago

mloubout commented 7 years ago

So this issue is bit odd and not sure what is going on but here is a summary:

In[2]: from devito import TimeData, ConstantData
In[3]: import numpy as np
In[4]: field = TimeData(name='u', shape=(5, 6), space_order=2, time_order=2)
In[5]: m = ConstantData(name="m", value=.25, dtype=np.float32)
In[6]: 1/m*field
Traceback (most recent call last):
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-b0914f230786>", line 1, in <module>
    1/m*field
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/decorators.py", line 77, in __sympifyit_wrapper
    return func(a, b)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/decorators.py", line 118, in binary_op_wrapper
    return func(self, other)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/expr.py", line 141, in __mul__
    return Mul(self, other)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/operations.py", line 41, in __new__
    c_part, nc_part, order_symbols = cls.flatten(args)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/mul.py", line 181, in flatten
    if not a.is_zero and a.is_Rational:
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/assumptions.py", line 245, in getit
    return _ask(fact, self)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/assumptions.py", line 300, in _ask
    _ask(pk, obj)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/assumptions.py", line 300, in _ask
    _ask(pk, obj)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/assumptions.py", line 288, in _ask
    a = evaluate(obj)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/power.py", line 525, in _eval_is_prime
    return self.doit().is_prime
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/basic.py", line 1519, in doit
    for term in self.args]
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/basic.py", line 1520, in doit
    return self.func(*terms)
  File "/Users/mloubout/Dropbox/London/CodeGen/devito/devito/interfaces.py", line 342, in __new__
    return AbstractSymbol.__new__(cls, *args, **kwargs)
  File "/Users/mloubout/Dropbox/London/CodeGen/devito/devito/interfaces.py", line 147, in __new__
    newobj = Function.__new__(cls, *args)
  File "/Volumes/Users/mloubout/anaconda/lib/python2.7/site-packages/sympy/core/function.py", line 389, in __new__
    pr = max(cls._should_evalf(a) for a in result.args)
ValueError: max() arg is an empty sequence
In[7]: field/m
Out[7]: 
u(t, x, y)/m()

So mainly, it looks like sympy does not like 1/m for m ConstantData (same with sqrt (1/m) or 1/sqrt(m))

mloubout commented 7 years ago

Needed for #305 , I'll look into this.

mloubout commented 6 years ago

Ooooookkk, so took me a while, but turns out it's a sympy solve problem that disapear with simplify=false.

closing, and back at nicer ABC + freesurface (should be easy now).