OceanParcels / Parcels

Main code for Parcels (Probably A Really Computationally Efficient Lagrangian Simulator)
https://www.oceanparcels.org
MIT License
294 stars 135 forks source link

'scipy' mode argument not causing moving_eddies to run in pure python #28

Closed Jacketless closed 8 years ago

Jacketless commented 8 years ago

I'm calling np.random functions in a RandomWalk function, as discussed in issue #27, and trying to use "pure python" mode for the moment as these functions are not implemented in the compiler.

However, when from the terminal I run pythonw2.7 tests/test_moving_eddies.py scipy --grid 200 200 -v -p 50 I still get the error File "<ast>", line 260, in AdvectionRK4RandomWalk NameError: global name 'np' is not defined

which does not makes sense because I believed calling mode 'scipy' did not even generate a AdvectionRK4RandomWalk C function, let alone not understand the np shorthand for numpy. If I force the default mode to be scipy rather than jit, I get the same error without the terminal line scipy argument, so this must be something else....

mlange05 commented 8 years ago

Ah, this is indeed a bug that is created due to the way we low-level concatenate two Python functions. The quick fix for this is to explicitly put an import statement (import numpy as np, or even from numpy import random) inside the RandomWalk kernel function itself. I'll see if I can fix the concatenation function to improve this.

mlange05 commented 8 years ago

Ok I think I figured out how to fix this (see PR #29). Thanks @Jacketless, this is a really important fix.

mlange05 commented 8 years ago

Given that PR #29 has landed, I believe this is now fixed; so closing.