robertorolo / pyLPM

Educational geostatistical python package on top of gslib and plotly.
MIT License
9 stars 2 forks source link

Problem with Numba #3

Open lucas-luzzi opened 1 week ago

lucas-luzzi commented 1 week ago

When running H-scatter, varmap, and experimental variogram commands there is an error associated with the numba library. This happens even when running the Walker Lake demo.

PauloCarvalhoRJ commented 1 week ago

Hello,

Please, post the error message along the stack trace.

best,

PC

lucas-luzzi commented 1 week ago

TypingError Traceback (most recent call last) Cell In[10], line 3 1 # EXPERIMENTAL VARIOGRAMS 2 # Omni-direciotnal horizontal + Directional vertical ----> 3 pyLPM.gammapy.experimental(dataset=data,X='X',Y='Y',head='SPT',tail='SPT', 4 type_c=['Variogram','Variogram'], 5 nlags=[8,8], 6 lagsize=[2,1], 7 lineartol=[1,0.5], 8 htol=[0,20], 9 vtol=[15,20], 10 hband=[0,5], 11 vband=[3,5], 12 azimuth=[0,0], 13 dip=[0,90], 14 omni=[True,False], 15 show_pairs=True, 16 Z='Z', 17 choice=1.0,)

File ~\anaconda3\Lib\site-packages\pyLPM\gammapy.py:1539, in experimental(dataset, X, Y, head, tail, type_c, nlags, lagsize, lineartol, htol, vtol, hband, vband, azimuth, dip, omni, show_pairs, Z, choice) 1536 # Calculate experimental variograms for each directions 1538 for i in range(ndirections): -> 1539 dfs.append(_calculate_experimental_function(dataset, X, Y, Z, 1540 type_c[i], lagsize[i], lineartol[i], htol[i], vtol[i], hband[i], vband[i], azimuth[i], dip[i], 1541 nlags[i], head, tail, choice, omni[i])) 1543 # Plot experimental variograms 1545 size_row = 1 if len(dfs) < 4 else int(math.ceil(len(dfs)/4))

File ~\anaconda3\Lib\site-packages\pyLPM\gammapy.py:521, in _calculate_experimental_function(dataset, x_label, y_label, z_label, type_var, lagdistance, lineartolerance, htol, vtol, hband, vband, azimuth, dip, nlags, head_property, tail_property, choice, omni) 486 '''calculate_experimental_function 487 488 Args: (...) 517 df (pandas.DataFrame): Pandas Dataframe containing the experimental continuity functions of all lags 518 ''' 519 # Calculate all permissible distances --> 521 dist = _distances(dataset, nlags, x_label, y_label, z_label, lagdistance, head_property, tail_property, choice) 523 # Define the angles and tolerances 525 cos_Azimuth = np.cos(np.radians(90-azimuth))

File ~\anaconda3\Lib\site-packages\pyLPM\gammapy.py:254, in _distances(dataset, nlags, x_label, y_label, z_label, lagdistance, head_property, tail_property, choice) 250 points = np.array(list(zip(X,Y,Z,HEAD,TAIL))) 252 # Define the permissible combination of samples according the maximum distance --> 254 pairs = _combin(points,points.shape[0], max_dist) 256 # Define distance variables and dataset 258 distancex = _xdist(pairs)

File ~\anaconda3\Lib\site-packages\numba\core\dispatcher.py:468, in _DispatcherBase._compile_for_args(self, *args, **kws) 464 msg = (f"{str(e).rstrip()} \n\nThis error may have been caused " 465 f"by the following argument(s):\n{args_str}\n") 466 e.patch_message(msg) --> 468 error_rewrite(e, 'typing') 469 except errors.UnsupportedError as e: 470 # Something unsupported is present in the user code, add help info 471 error_rewrite(e, 'unsupported_error')

File ~\anaconda3\Lib\site-packages\numba\core\dispatcher.py:409, in _DispatcherBase._compile_for_args..error_rewrite(e, issue_type) 407 raise e 408 else: --> 409 raise e.with_traceback(None)

TypingError: Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function() found for signature:

array(list(UniTuple(array(float64, 1d, C) x 2)))

There are 2 candidate implementations:

During: resolving callee type: Function() During: typing of call at C:\Users\Lucas\anaconda3\Lib\site-packages\pyLPM\gammapy.py (171)

File "........\anaconda3\Lib\site-packages\pyLPM\gammapy.py", line 171: def _combin(points,n, max_dist):

        p += 1
return np.array(dist)

^

PauloCarvalhoRJ commented 1 week ago

Hello,

Can you, please, edit your last post so to enclose the messages between a ```bash and a ``` ? That will improve readability a lot.

thank you,

PC

lucas-luzzi commented 1 week ago

TypingError                               Traceback (most recent call last)
Cell In[10], line 3
      1 # EXPERIMENTAL VARIOGRAMS
      2 # Omni-direciotnal horizontal + Directional vertical 
----> 3 pyLPM.gammapy.experimental(dataset=data,X='X',Y='Y',head='SPT',tail='SPT',
      4                           type_c=['Variogram','Variogram'],
      5                           nlags=[8,8],
      6                           lagsize=[2,1],
      7                           lineartol=[1,0.5],
      8                           htol=[0,20],
      9                           vtol=[15,20],
     10                           hband=[0,5],
     11                           vband=[3,5],
     12                           azimuth=[0,0],
     13                           dip=[0,90],
     14                           omni=[True,False],
     15                           show_pairs=True,
     16                           Z='Z',
     17                           choice=1.0,)

File ~\anaconda3\Lib\site-packages\pyLPM\gammapy.py:1539, in experimental(dataset, X, Y, head, tail, type_c, nlags, lagsize, lineartol, htol, vtol, hband, vband, azimuth, dip, omni, show_pairs, Z, choice)
   1536 # Calculate experimental variograms for each directions 
   1538 for i in range(ndirections):
-> 1539     dfs.append(_calculate_experimental_function(dataset, X, Y, Z, 
   1540                 type_c[i], lagsize[i], lineartol[i], htol[i], vtol[i], hband[i], vband[i], azimuth[i], dip[i], 
   1541                 nlags[i], head, tail, choice, omni[i]))
   1543 # Plot experimental variograms 
   1545 size_row = 1 if len(dfs) < 4 else int(math.ceil(len(dfs)/4))

File ~\anaconda3\Lib\site-packages\pyLPM\gammapy.py:521, in _calculate_experimental_function(dataset, x_label, y_label, z_label, type_var, lagdistance, lineartolerance, htol, vtol, hband, vband, azimuth, dip, nlags, head_property, tail_property, choice, omni)
    486 '''calculate_experimental_function
    487 
    488 Args:
   (...)
    517     df (pandas.DataFrame): Pandas Dataframe containing the experimental continuity functions of all lags
    518 '''
    519 # Calculate all permissible distances
--> 521 dist = _distances(dataset, nlags, x_label, y_label, z_label, lagdistance, head_property, tail_property, choice)
    523 # Define the angles and tolerances 
    525 cos_Azimuth = np.cos(np.radians(90-azimuth))

File ~\anaconda3\Lib\site-packages\pyLPM\gammapy.py:254, in _distances(dataset, nlags, x_label, y_label, z_label, lagdistance, head_property, tail_property, choice)
    250     points = np.array(list(zip(X,Y,Z,HEAD,TAIL)))
    252 # Define the permissible combination of samples according the maximum distance
--> 254 pairs = _combin(points,points.shape[0], max_dist)
    256 # Define distance variables and dataset 
    258 distancex = _xdist(pairs) 

File ~\anaconda3\Lib\site-packages\numba\core\dispatcher.py:468, in _DispatcherBase._compile_for_args(self, *args, **kws)
    464         msg = (f"{str(e).rstrip()} \n\nThis error may have been caused "
    465                f"by the following argument(s):\n{args_str}\n")
    466         e.patch_message(msg)
--> 468     error_rewrite(e, 'typing')
    469 except errors.UnsupportedError as e:
    470     # Something unsupported is present in the user code, add help info
    471     error_rewrite(e, 'unsupported_error')

File ~\anaconda3\Lib\site-packages\numba\core\dispatcher.py:409, in _DispatcherBase._compile_for_args.<locals>.error_rewrite(e, issue_type)
    407     raise e
    408 else:
--> 409     raise e.with_traceback(None)

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function array>) found for signature:

 >>> array(list(UniTuple(array(float64, 1d, C) x 2))<iv=None>)

There are 2 candidate implementations:
    - Of which 2 did not match due to:
    Overload in function 'impl_np_array': File: numba\np\arrayobj.py: Line 5421.
      With argument(s): '(list(UniTuple(array(float64, 1d, C) x 2))<iv=None>)':
     Rejected as the implementation raised a specific error:
       TypingError: Failed in nopython mode pipeline (step: nopython frontend)
     No implementation of function Function(<intrinsic np_array>) found for signature:

      >>> np_array(list(UniTuple(array(float64, 1d, C) x 2))<iv=None>, none)

     There are 2 candidate implementations:
           - Of which 2 did not match due to:
           Intrinsic in function 'np_array': File: numba\np\arrayobj.py: Line 5395.
             With argument(s): '(list(UniTuple(array(float64, 1d, C) x 2))<iv=None>, none)':
            Rejected as the implementation raised a specific error:
              TypingError: array(float64, 1d, C) not allowed in a homogeneous sequence
       raised from C:\Users\Lucas\anaconda3\Lib\site-packages\numba\core\typing\npydecl.py:482

     During: resolving callee type: Function(<intrinsic np_array>)
     During: typing of call at C:\Users\Lucas\anaconda3\Lib\site-packages\numba\np\arrayobj.py (5432)

     File "..\..\..\..\anaconda3\Lib\site-packages\numba\np\arrayobj.py", line 5432:
         def impl(object, dtype=None):
             return np_array(object, dtype)
             ^

  raised from C:\Users\Lucas\anaconda3\Lib\site-packages\numba\core\typeinfer.py:1091

During: resolving callee type: Function(<built-in function array>)
During: typing of call at C:\Users\Lucas\anaconda3\Lib\site-packages\pyLPM\gammapy.py (171)

File "..\..\..\..\anaconda3\Lib\site-packages\pyLPM\gammapy.py", line 171:
def _combin(points,n, max_dist):
    <source elided>
            p += 1
    return np.array(dist)
 ^ ```
PauloCarvalhoRJ commented 1 week ago

Most of the geostats code in master branch is 5-year old. So, I'd recommend using Python 3.6 or 3.7 and compatible Numba and Jupyter Notebook. Which version of Python are you using?

lucas-luzzi commented 1 week ago

I was using Python 3.12, now I tried with 3.7 and 3.6 and got the same error. The version of Numba is 0.59.0 and the version of jupyter notebook is 7.0.8

PauloCarvalhoRJ commented 2 days ago

@robertorolo