CalebBell / chemicals

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

`TypeError` when operating in no-JIT mode #46

Closed ma-sadeghi closed 1 year ago

ma-sadeghi commented 1 year ago

Describe the bug When operating in no-JIT mode, we get the following error:

TypeError: return type must be specified for object mode

Minimal Reproducible Example This happened during our automated tests, please see here. Here's the log:

----------------------------- Captured stderr call -----------------------------
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/chemicals/vapor_pressure.py:2063: NumbaWarning: 
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "Ambrose_Walton" failed type inference due to: Untyped global name 'trunc_exp': Cannot determine Numba type of <class 'function'>

File "../../../../../opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/chemicals/vapor_pressure.py", line 2135:
def Ambrose_Walton(T, Tc, Pc, omega):
    <source elided>
    f2 = (-0.64771*tau + 2.41539*tau15 - 4.26979*tau25 + 3.25[259](https://github.com/PMEAL/OpenPNM/actions/runs/5651351031/job/15309317968#step:7:260)*tau5)
    return Pc*trunc_exp((f0 + omega*(f1 + f2*omega))/Tr)
    ^

  def Ambrose_Walton(T, Tc, Pc, omega):
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/numba/core/object_mode_passes.py:151: NumbaWarning: Function "Ambrose_Walton" was compiled in object mode without forceobj=True.

File "../../../../../opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/chemicals/vapor_pressure.py", line 2063:

def Ambrose_Walton(T, Tc, Pc, omega):
^

  warnings.warn(errors.NumbaWarning(warn_msg,
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/numba/core/object_mode_passes.py:161: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected. This is deprecated behaviour that will be removed in Numba 0.59.0.

For more information visit https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "../../../../../opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/chemicals/vapor_pressure.py", line 2063:

def Ambrose_Walton(T, Tc, Pc, omega):
^

  warnings.warn(errors.NumbaDeprecationWarning(msg,

---------- coverage: platform linux, python 3.9.17-final-0 -----------
Coverage XML written to file coverage.xml

=========================== short test summary info ============================
FAILED tests/unit/models/phase/DensityTest.py::DensityTest::test_chemicals_wrapper_for_pure_liq_molar_volume - TypeError: return type must be specified for object mode
FAILED tests/unit/models/phase/VaporPressureTest.py::VaporPressureTest::test_generic_chemicals_for_pure_liquid - TypeError: return type must be specified for object mode
============= 2 failed, 775 passed, 10 skipped in 86.56s (0:01:26) =============
Error: Process completed with exit code 1.
CalebBell commented 1 year ago

Hi Amin, It's always good to hear about these issues. A few places in the chemicals/thermo/ht test suites also fail with the NUMBA_DISABLE_JIT=1 environmental variable set. It's fairly confusing that any numba functions in my software work with that setting at all though; I create each function with the numba.njit decorator.

I found that I could disable those specific tests with the following pytest decorator:

jit_disabled = os.environ.get('NUMBA_DISABLE_JIT') == '1'

@pytest.mark.skipif(jit_disabled, reason='NUMBA JIT is disabled')
def your_test():

Unfortunately I'm not able to get to the bottom of what is going on. I believe numba is dropping this feature entirely in the November release.

ma-sadeghi commented 1 year ago

Thanks! I just disabled the failing tests.