CalebBell / chemicals

chemicals: Chemical database of Chemical Engineering Design Library (ChEDL)
MIT License
186 stars 36 forks source link

lazy loading from chemicals.numba not working #15

Closed yoelcortes closed 4 years ago

yoelcortes commented 4 years ago

Seems like the fluids numba module jit compiles to_num, which makes us get this error:

>>> from chemicals.numba import heat_capacity
>>> heat_capacity.zabransky_dicts
Traceback (most recent call last):

  File "<ipython-input-9-aba4759ac2e4>", line 1, in <module>
    heat_capacity.zabransky_dicts

  File "C:\Users\yrc2\OneDrive\Code\chemicals\chemicals\heat_capacity.py", line 547, in __getattr__
    _load_Cp_data()

  File "C:\Users\yrc2\OneDrive\Code\chemicals\chemicals\heat_capacity.py", line 478, in _load_Cp_data
    values = to_num(line.strip('\n').split('\t'))

  File "C:\Users\yrc2\AppData\Roaming\Python\Python37\site-packages\numba\core\dispatcher.py", line 415, in _compile_for_args
    error_rewrite(e, 'typing')

  File "C:\Users\yrc2\AppData\Roaming\Python\Python37\site-packages\numba\core\dispatcher.py", line 358, in error_rewrite
    reraise(type(e), e, None)

  File "C:\Users\yrc2\AppData\Roaming\Python\Python37\site-packages\numba\core\utils.py", line 80, in reraise
    raise value.with_traceback(tb)

TypingError: No implementation of function Function(<class 'float'>) found for signature:

float(unicode_type)

There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'float': File: Unknown: Line <N/A>.
    With argument(s): '(unicode_type)':
   Rejected as the implementation raised a specific error:
     TypeError: float() only support for numbers
  raised from C:\Users\yrc2\AppData\Roaming\Python\Python37\site-packages\numba\core\typing\builtins.py:912

During: resolving callee type: Function(<class 'float'>)
During: typing of call at C:\Users\yrc2\OneDrive\Code\chemicals\chemicals\utils.py (96)

Could you take care of making sure to_num is not jit compiled? Thanks!

CalebBell commented 4 years ago

Hi Yoel, Good catch! I didn't think of that. I did add a filter to remove this function from being compilled; you can add to the list in the chemicals.numba file if there are other functions that shouldn't be part of the public numba API. As the numba wrapper comes in large part from fluids, the change needed to be reflected there. You will need to use the master branch of fluids to chemicals working. It was a quick fix so please let me know if I overlooked something.