Skip to content

Commit

Permalink
Compatibility for numpy 2.0 and scipy 1.14
Browse files Browse the repository at this point in the history
General improvements
  • Loading branch information
CalebBell committed Jul 26, 2024
1 parent c819d08 commit f846699
Show file tree
Hide file tree
Showing 70 changed files with 4,172 additions and 2,390 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ jobs:
architecture: ${{ matrix.architecture }}

- name: cache Linux
uses: actions/cache@v2
uses: actions/cache@v4
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements_test.txt') }}
restore-keys: |
${{ runner.os }}-${{ runner.architecture }}-${{ runner.python-version }}pip-
- name: cache MacOS
uses: actions/cache@v2
uses: actions/cache@v4
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements_test.txt') }}
restore-keys: |
${{ runner.os }}-${{ runner.architecture }}-${{ runner.python-version }}pip-
- name: cache Windows
uses: actions/cache@v2
uses: actions/cache@v4
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,5 @@ Citation

To cite Thermo in publications use::

Caleb Bell and Contributors (2016-2023). Thermo: Chemical properties component of Chemical Engineering Design Library (ChEDL)
Caleb Bell and Contributors (2016-2024). Thermo: Chemical properties component of Chemical Engineering Design Library (ChEDL)
https://github.com/CalebBell/thermo.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def pytest_ignore_collect(path):
return True
if 'conf.py' in path:
return True
if ver_tup < (3, 7) or ver_tup >= (3, 12) or is_pypy:
if ver_tup < (3, 7) or ver_tup >= (3, 13) or is_pypy:
# numba does not yet run under pypy
if 'numba' in path:
return True
Expand Down
4 changes: 2 additions & 2 deletions docs/activity_coefficients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ Other json libraries can be used besides the standard json library by design.

Storing and recreating objects with Python's :py:func:`pickle.dumps` library is also tested; this can be faster than using JSON at the cost of being binary data.

All models have a :obj:`__hash__ <thermo.activity.GibbsExcess.__hash__>` method that can be used to compare different models to see if they are absolutely identical (including which values have been calculated already).
All models have a :obj:`__hash__ <thermo.activity.GibbsExcess.exact_hash>` method that can be used to compare different models to see if they are absolutely identical (including which values have been calculated already).

They also have a :obj:`model_hash <thermo.activity.GibbsExcess.model_hash>` method that can be used to compare different models to see if they have identical model parameters.

They also have a :obj:`state_hash <thermo.activity.GibbsExcess.state_hash>` method that can be used to compare different models to see if they have identical temperature, composition, and model parameters.
They also have a :obj:`state_hash <thermo.activity.GibbsExcess.state_hash>` method that can be used to compare different models to see if they have identical temperature, composition, and model parameters. This is the __hash__ method.

Activity Coefficient Identities
-------------------------------
Expand Down
8 changes: 5 additions & 3 deletions docs/cubic_equations_of_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,17 @@ True
>>> PR_case.state_hash() == PR_case2.state_hash()
False

And finally it is possible to see if two objects are exactly identical, including cached calculation results, by using the :obj:`__hash__ <thermo.eos.GCEOS.__hash__>` method:
:obj:`state_hash <thermo.eos.GCEOS.state_hash>` is the __hash__ method of the object.

And finally it is possible to see if two objects are exactly identical, including cached calculation results, by using the :obj:`exact_hash <thermo.eos.GCEOS.exact_hash>` method:

>>> PR_case3 = PRMIX(T=115, P=1E6, Tcs=[126.1, 190.6], Pcs=[33.94E5, 46.04E5], omegas=[0.04, 0.011], zs=[0.5, 0.5], kijs=[[0,0.41],[0.41,0]])
>>> PR_case.state_hash() == PR_case3.state_hash()
True
>>> hash(PR_case) == hash(PR_case3)
>>> PR_case.exact_hash() == PR_case3.exact_hash()
True
>>> _ = PR_case.da_alpha_dT_ijs
>>> hash(PR_case) == hash(PR_case3)
>>> PR_case.exact_hash() == PR_case3.exact_hash()
False

Serialization
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Citation

To cite Thermo in publications use::

Caleb Bell and Contributors (2016-2023). Thermo: Chemical properties component of Chemical Engineering Design Library (ChEDL)
Caleb Bell and Contributors (2016-2024). Thermo: Chemical properties component of Chemical Engineering Design Library (ChEDL)
https://github.com/CalebBell/thermo.


Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial_phases_and_flash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ Storing and recreating objects with Python's :py:func:`pickle.dumps` library is

Hashing
^^^^^^^
All models have a :obj:`__hash__ <thermo.phases.Phase.__hash__>` method that can be used to compare different phases to see if they are absolutely identical (including which values have been calculated already).
All models have a :obj:`__hash__ <thermo.phases.Phase.exact_hash>` method that can be used to compare different phases to see if they are absolutely identical (including which values have been calculated already).

They also have a :obj:`model_hash <thermo.phases.Phase.model_hash>` method that can be used to compare different phases to see if they have identical model parameters.

They also have a :obj:`state_hash <thermo.phases.Phase.state_hash>` method that can be used to compare different phases to see if they have identical temperature, composition, and model parameters.
They also have a :obj:`state_hash <thermo.phases.Phase.state_hash>` method that can be used to compare different phases to see if they have identical temperature, composition, and model parameters. This is the __hash__ method.



Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy
scipy
scipy>=1.6.0
pandas
coolprop
fluids>=1.0.25
fluids>=1.0.26
chemicals>=1.1.5
7 changes: 6 additions & 1 deletion requirements_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ scipy
numpydoc
pint
nbsphinx
fluids>=1.0.25
fluids>=1.0.26
chemicals>=1.1.5
IPython
ipython
Expand All @@ -12,5 +12,10 @@ pandas
sphinxcontrib-katex
sphinx-sitemap
sphinx==4.3.0
sphinxcontrib-applehelp==1.0.4
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
matplotlib
mpmath
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ numpy
scipy
pandas
sympy
fluids>=1.0.25
fluids>=1.0.26
chemicals>=1.1.5
pytest
pytest-cov
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Education',
Expand All @@ -61,7 +62,7 @@
version = '0.2.27',
description = 'Chemical properties component of Chemical Engineering Design Library (ChEDL)',
author = 'Caleb Bell',
install_requires=['fluids>=1.0.25', 'scipy', 'pandas', 'chemicals>=1.1.5'],
install_requires=['fluids>=1.0.26', "scipy>=1.6.0", 'pandas', 'chemicals>=1.1.5'],
extras_require = {
'Coverage documentation': ['wsgiref>=0.1.2', 'coverage>=4.0.3']
},
Expand Down
54 changes: 53 additions & 1 deletion tests/test_chemical_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def test_ChemicalConstantsPackage_json_version_exported():
c2 = ChemicalConstantsPackage.from_json(json.loads(string))
assert 'py/object' in string
assert 'json_version' in string
assert not hasattr(c2, 'json_version')

def test_ChemicalConstantsPackage_json_export_does_not_change_hashes():
# There was a nasty bug where the hashing function was changing its result
Expand Down Expand Up @@ -208,3 +207,56 @@ def test_chemical_package_recreation():
obj = ChemicalConstantsPackage.correlations_from_IDs(IDs=['water', 'hexane', 'toluene'])
copy = eval(str(obj))
assert obj == copy

def test_chemical_package_recreation_another_issue():
constants = ChemicalConstantsPackage(atom_fractions={'H': 0.6666666666666666, 'C': 0.16666666666666666, 'O': 0.16666666666666666}, atomss=[{'H': 4, 'C': 1, 'O': 1}],
CASs=['67-56-1'], charges=[0], conductivities=[4.4e-05], dipoles=[1.7],
formulas=['CH4O'], Gfgs=[-162000.13000000003], Gfgs_mass=[-5055890.325967345], Hcs=[-764464.0], Hcs_lower=[-676489.1], Hcs_lower_mass=[-21112666.368306957], Hcs_mass=[-23858290.373904638],
Hfgs=[-200700.0], Hfgs_mass=[-6263681.321870828], Hfus_Tms=[3215.0000000000005], Hfus_Tms_mass=[100337.49601302797], Hvap_298s=[37486.47944178592], Hvap_298s_mass=[1169922.078237216],
Hvap_Tbs=[35170.873821707064], Hvap_Tbs_mass=[1097653.9383702152], LFLs=[0.06], logPs=[-0.74], molecular_diameters=[3.7995699999999997],
MWs=[32.04186], names=['methanol'], omegas=[0.5589999999999999], Parachors=[1.574169046057019e-05], Pcs=[8084000.0], phase_STPs=['l'], Psat_298s=[16905.960312551426], PSRK_groups=[{15: 1}],
Pts=[0.1758862695025245], PubChems=[887], rhocs=[8547.008547008547], rhocs_mass=[273.86205128205125], rhol_STPs=[24494.78614922483], rhol_STPs_mass=[784.8585085234012], RIs=[1.3288], S0gs=[239.9],
S0gs_mass=[7487.080962216301], Sfgs=[-129.7999999999999], Sfgs_mass=[-4050.950849919446], similarity_variables=[0.18725504699165404], Skins=[True], smiless=['CO'], STELs=[(250.0, 'ppm')],
StielPolars=[0.027243902847492674], Stockmayers=[685.96], Tautoignitions=[713.15], Tbs=[337.65], Tcs=[512.5], Tflashs=[282.15], Tms=[175.15], Tts=[175.59], UFLs=[0.36],
UNIFAC_Dortmund_groups=[{15: 1}], UNIFAC_groups=[{15: 1}], Van_der_Waals_areas=[358000.0], Van_der_Waals_volumes=[2.1709787e-05], Vcs=[0.000117], Vml_STPs=[4.0825014511573776e-05],
Vml_Tms=[3.541058756059562e-05], Zcs=[0.22196480200068586], UNIFAC_Rs=[1.4311], UNIFAC_Qs=[1.432], rhos_Tms=[1013.0221439813405], Vms_Tms=[3.162996997683616e-05], solubility_parameters=[29315.58469262365],
Vml_60Fs=[4.033573571273147e-05], rhol_60Fs_mass=[794.3789652976724], rhol_60Fs=[24791.91174599953])

VaporPressures = [VaporPressure(exp_poly_fit=(175.7, 512.49, [-1.446088049406911e-19, 4.565038519454878e-16, -6.278051259204248e-13, 4.935674274379539e-10,
-2.443464113936029e-07, 7.893819658700523e-05, -0.016615779444332356, 2.1842496316772264, -134.19766175812708])), ]
HeatCapacityGases = [HeatCapacityGas(poly_fit=(50.0, 1000.0, [2.3511458696647882e-21, -9.223721411371584e-18, 1.3574178156001128e-14, -8.311274917169928e-12,
4.601738891380102e-10, 1.78316202142183e-06, -0.0007052056417063217, 0.13263597297874355, 28.44324970462924])), ]
HeatCapacityLiquids = [HeatCapacityLiquid(poly_fit=(180.0, 503.1, [-5.042130764341761e-17, 1.3174414379504284e-13, -1.472202211288266e-10, 9.19934288272021e-08,
-3.517841445216993e-05, 0.008434516406617465, -1.2381765320848312, 101.71442569958393, -3508.6245143327947])),]
VolumeLiquids = [VolumeLiquid(poly_fit=(175.7, 502.5, [3.5725079384600736e-23, -9.031033742820083e-20, 9.819637959370411e-17, -5.993173551565636e-14,
2.2442465416964825e-11, -5.27776114586072e-09, 7.610461006178106e-07, -6.148574498547711e-05, 0.00216398089328537])), ]
EnthalpyVaporizations = [EnthalpyVaporization(Tc=512.5, poly_fit_ln_tau=(175.7, 512.499, 512.5, [-0.004536133852590396, -0.2817551666837462, -7.344529282245696, -104.02286881045083,
-860.5796142607192, -4067.8897875259267, -8952.300062896637, 2827.0089241465225, 44568.12528999141])),]
HeatCapacitySolids = [HeatCapacitySolid(poly_fit=(1.0, 5000.0, [-4.2547351607351175e-26, 9.58204543572984e-22, -8.928062818728625e-18, 4.438942190507877e-14,
-1.2656161406049876e-10, 2.0651464217978594e-07, -0.0001691371394823046, 0.2038633833421581, -0.07254973910767148])),]
SublimationPressures = [SublimationPressure(exp_poly_fit=(61.5, 179.375, [-1.9972190661146383e-15, 2.1648606414769645e-12, -1.0255776193312338e-09, 2.7846062954442135e-07,
-4.771529410705124e-05, 0.005347189071525987, -0.3916553642749777, 18.072103851054266, -447.1556383160345])),]
EnthalpySublimations = [EnthalpySublimation(poly_fit=(1.7515, 175.59, [2.3382707698778188e-17, -2.03890965442551e-12, 1.5374109464154768e-09, -4.640933157748743e-07,
6.931187040484687e-05, -0.004954625422589015, 0.045058888152305354, 32.52432385785916, 42213.605713250145])),]
VolumeSolids = [VolumeSolid(poly_fit=(52.677, 175.59, [3.9379562779372194e-30, 1.4859309728437516e-27, 3.897856765862211e-24, 5.012758300685479e-21, 7.115820892078097e-18,
9.987967202910477e-15, 1.4030825662633013e-11, 1.970935889948393e-08, 2.7686131179275174e-05])),]

SurfaceTensions = [SurfaceTension(CASRN='67-56-1', method="SOMAYAJULU2")]

ThermalConductivityLiquids=[ThermalConductivityLiquid(poly_fit=(390.65, 558.9, [-1.7703926719478098e-31, 5.532831178371296e-28, -7.157706109850407e-25, 4.824017093238245e-22, -1.678132299010268e-19, 1.8560214447222824e-17, 6.274769714658382e-15, -0.00020340000228224661, 0.21360000021862866])),]
ThermalConductivityGases=[ThermalConductivityGas(poly_fit=(390.65, 558.9, [1.303338742188738e-26, -5.948868042722525e-23, 1.2393384322893673e-19, -1.5901481819379786e-16, 1.4993659486913432e-13, -1.367840742416352e-10, 1.7997602278525846e-07, 3.5456258123020795e-06, -9.803647813554084e-05])),]
ViscosityLiquids=[ViscosityLiquid(extrapolation_min=0, exp_poly_fit=(190.0, 391.9, [1.8379049563136273e-17, -4.5666126233131545e-14, 4.9414486397781785e-11, -3.042378423089263e-08, 1.166244931040138e-05, -0.0028523723735774113, 0.4352378275340892, -37.99358630363772, 1456.8338572042996])),]
ViscosityGases=[ViscosityGas(extrapolation_min=0, poly_fit=(390.65, 558.9, [4.166385860107714e-29, -1.859399624586853e-25, 3.723945144634823e-22, -4.410000193606962e-19, 3.412270901850386e-16, -1.7666632565075753e-13, 5.266250837132718e-11, 1.8202807683935545e-08, -3.7907568022643496e-07])),]

correlations = PropertyCorrelationsPackage(constants, VaporPressures=VaporPressures, HeatCapacityGases=HeatCapacityGases, HeatCapacityLiquids=HeatCapacityLiquids, VolumeLiquids=VolumeLiquids,
EnthalpyVaporizations=EnthalpyVaporizations, HeatCapacitySolids=HeatCapacitySolids, SublimationPressures=SublimationPressures,
SurfaceTensions=SurfaceTensions,
ViscosityLiquids=ViscosityLiquids, ViscosityGases=ViscosityGases,
ThermalConductivityGases=ThermalConductivityGases, ThermalConductivityLiquids=ThermalConductivityLiquids,
EnthalpySublimations=EnthalpySublimations, VolumeSolids=VolumeSolids)
correlations2 = eval(repr(correlations))
for name in correlations.correlations:
assert getattr(correlations, name) == getattr(correlations2, name)
assert hash_any_primitive(getattr(correlations, name)) == hash_any_primitive(getattr(correlations2, name))

assert correlations == correlations2
2 changes: 1 addition & 1 deletion tests/test_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ def test_model_encode_json_eos():
for eos in eos_iter:
e = eos(Tc=Tc, Pc=Pc, omega=omega, T=300, P=1E5)
s = e.as_json()
assert 'json_version' in s
assert 'json_version' in str(s)
assert type(s) is dict
e1 = eos.from_json(s)
assert e.__dict__ == e1.__dict__
Expand Down
6 changes: 3 additions & 3 deletions tests/test_eos_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4392,7 +4392,7 @@ def test_model_encode_json_gceosmix():
for eos in eos_mix_no_coeffs_list:
obj1 = eos(T=T, P=P, zs=zs, omegas=omegas, Tcs=Tcs, Pcs=Pcs, kijs=kijs)
s = obj1.as_json()
assert 'json_version' in s
assert 'json_version' in str(s)
assert type(s) is dict
obj2 = GCEOSMIX.from_json(s)
assert obj1.__dict__ == obj2.__dict__
Expand Down Expand Up @@ -4675,8 +4675,8 @@ def test_eos_mix_one_minus_kijs():
import pickle
eos = PRSV2MIX(Tcs=[507.6], Pcs=[3025000], omegas=[0.2975], zs=[1], T=299., P=1E6, kappa1s=[0.05104], kappa2s=[0.8634], kappa3s=[0.460])
json_copy = eos.as_json()
assert 'kijs' in json_copy
assert 'one_minus_kijs' not in json_copy
assert 'kijs' in str(json_copy)
assert 'one_minus_kijs' not in str(json_copy)
json_stuff = pickle.dumps(json_copy)
new_eos = GCEOSMIX.from_json(pickle.loads(json_stuff))

Expand Down
3 changes: 2 additions & 1 deletion tests/test_eos_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def validate_volume(args, solver, rtol=1e-15):
(138.48863713938846, 3.0538555088340556e-06, 2.2081238710001263e-05, 2.2081238710001263e-05, 0.0, 0.14823101466889332),
(242.01282647944032, 6.892612104351147e-21, 2.208123871000126e-05, 2.208123871000126e-05, 0.0, 0.09892412606156903),
(4714.866363457429, 0.01, 2.8986924337681703e-05, 4.923467294821763e-05, -8.306951335097421e-10, 1.810368573677903e-13),
(222.04, 120.66, 12.736158671821732, 25.472317343643464, -162.20973771381992, 580349.6463695838),
]

hard_solutions = {}
Expand Down Expand Up @@ -137,7 +138,7 @@ def validate_volume(args, solver, rtol=1e-15):
hard_solutions[(138.48863713938846, 3.0538555088340556e-06, 2.2081238710001263e-05, 2.2081238710001263e-05, 0.0, 0.14823101466889332)] = ((5.228993310247619e-05+0j), (5.436208452435612e-05+0j), (377050778.3368337+0j))
hard_solutions[(242.01282647944032, 6.892612104351147e-21, 2.208123871000126e-05, 2.208123871000126e-05, 0.0, 0.09892412606156903)] = ((1.3540386918605232e-05-3.003691156915976e-05j), (1.3540386918605232e-05+3.003691156915976e-05j), (2.919367241929447e+23+0j))
hard_solutions[(4714.866363457429, 0.01, 2.8986924337681703e-05, 4.923467294821763e-05, -8.306951335097421e-10, 1.810368573677903e-13)] = ((-6.252127279461262e-05+0j), (1.328659984639961e-05+0j), (3920158.012884476+0j))

hard_solutions[(222.04, 120.66, 12.736158671821732, 25.472317343643464, -162.20973771381992, 580349.6463695838)] = ((-5.6505121319507525-63.703933152753j), (-5.6505121319507525+63.703933152753j), (13.865240859233307+0j))

# TODO important make mpmath cache answers here

Expand Down
Loading

0 comments on commit f846699

Please sign in to comment.