Support for Numba (chemicals.numba)¶
Basic module which wraps most of chemicals functions and classes to be compatible with the Numba dynamic Python compiler. Numba is only supported on Python 3, and may require the latest version of Numba. Numba is rapidly evolving, and hopefully in the future it will support more of the functionality of fluids.
Using the numba-accelerated version of chemicals is easy; simply call functions and classes from the chemicals.numba namespace. The chemicals.numba module must be imported separately on Python < 3.7; it is not loaded automatically as part of chemicals.
>>> import chemicals
>>> import chemicals.numba
>>> chemicals.numba.Antoine(180, A=8.95894, B=510.595, C=-15.95)
702271.05185795
There is a delay while the code is compiled when using Numba; the speed is not quite free.
Some parts of chemicals are not supported in the Numba interface.
Any data lookup function like Tc()
and omega_methods()
are not numba compatible.
These functions could not be speed up anyway though as they are memory-bound
and numba helps with things that are compute-bound.
Today, the list of things known not to work is as follows:
Everything in
chemicals.identifiers
Everything in
chemicals.combustion
(uses dictionaries)Everything in
chemicals.elements
(uses dictionaries, periodic_table class, string parsing)Everything in
chemicals.critical
except the mixture critical point routinesIn
chemicals.flash_basic
,flash_Tb_Tc_Pc()
andflash_ideal()
have not been ported but can be made compatible.In
chemicals.dippr
, onlyEQ102()
is unsupported as it uses a complex hyp2f1 call.In
chemicals.reaction
,stoichiometric_matrix()
(dictionaries),balance_stoichiometry()
(scipy functions, fractional numbers).In
chemicals.safety
,LFL_ISO_10156_2017()
(dictionaries)The assorted functions
collision_integral_Kim_Monroe()
,Henry_pressure_mixture()
,T_converter()
,Wilke()
,Wilke_prefactors()
,Brokaw()
viscosity_converter()
,CAS_to_int()
,int_to_CAS()
,sorted_CAS_key()
may or may not be able to be ported but have not yet been.
All of the regular Numba-compiled functions are built with the nogil flag, which means you can use Python’s threading mechanism effectively to get the speed of parallel processing.