inducer / arraycontext

Choose your favorite numpy-workalike!
6 stars 11 forks source link

eager arraycontext bug #258

Closed anderson2981 closed 5 months ago

anderson2981 commented 5 months ago

I have modified pyrometheus slightly to get a better estimate for Cp. Something like this:

return self._pyro_make_array([ self.usr_np.where(self.usr_np.greater(temperature, 6000.0), 15.857914857900802, self.usr_np.where(self.usr_np.greater(temperature, 1000.0), 6.21785087461938 + 0.0066860330395617*temperature + -1.79535702793147e-06*temperature**2 + 2.18865397063934e-10*temperature**3 + -1.01220733135537e-14*temperature**4, self.usr_np.where(self.usr_np.greater(temperature, 50.0), 3.73312012902641 + -0.00225161088114689*temperature + 2.35442451235782e-05*temperature**2 + -1.37084841614577e-08*temperature**3, 3.6776866372578287)))

where before it was like this

return self._pyro_make_array([ self.usr_np.where(self.usr_np.greater(temperature, 2000.0), 11.3144488322845 + 0.00199411450797709*temperature + -2.99633189643295e-07*temperature**2 + 1.89518716793814e-11*temperature**3 + -3.37402443785122e-16*temperature**4, 3.37402443785122 + 0.00843506109462805*temperature + 2.95775949418238e-07*temperature**2 + -1.43695501015373e-09*temperature**3 + 2.69921955028098e-13*temperature**4),

The biggest difference I can see is the nesting of actx.np.where(). If I run with a lazy array context this is fine however, when I run with an eager array context I get something like

File "/Users/someguy/work/CEESD/MirgeCom/Drivers/CEESD-Y3_prediction/emirge/arraycontext/arraycontext/impl/pyopencl/fake_numpy.py", line 362, in where return rec_multimap_array_container(where_inner, criterion, then, else_) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/someguy/work/CEESD/MirgeCom/Drivers/CEESD-Y3_prediction/emirge/arraycontext/arraycontext/container/traversal.py", line 338, in rec_multimap_array_container return _multimap_array_container_impl( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/someguy/work/CEESD/MirgeCom/Drivers/CEESD-Y3_prediction/emirge/arraycontext/arraycontext/container/traversal.py", line 193, in _multimap_array_container_impl return f(*args) ^^^^^^^^ File "/Users/someguy/work/CEESD/MirgeCom/Drivers/CEESD-Y3_prediction/emirge/arraycontext/arraycontext/impl/pyopencl/fake_numpy.py", line 359, in where_inner return cl_array.if_positive(inner_crit != 0, inner_then, inner_else, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/someguy/software/Install/Conda/envs/mirgeDriver.Y3prediction/lib/python3.11/site-packages/pyopencl/array.py", line 3054, in if_positive criterion.queue, criterion.shape, then_.dtype, ^^^^^^^^^^^^^^^ AttributeError: 'numpy.bool_' object has no attribute 'queue'

I was able to reproduce it, in a small example, it seems to be related to the temperature coming in as a np.float64 vs a plain old float

small reproducer: https://gist.github.com/anderson2981/0cc6f47e0b034caef7c76853e07a6b00