Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the renaming of ESMF Python module #639

Merged

Conversation

sadielbartholomew
Copy link
Member

@sadielbartholomew sadielbartholomew commented Apr 26, 2023

Close #633. Note the following:

  • As discussed, we are allowing either esmpy (new name) or esmf (old) to be imported for backwards compatibility, for now, as advertised on the new change log entry.
  • As part of this, to cater for that, I updated the internal _get_module_info function to cater for a possible alternative module name, since that might occur for other modules, but even if not it allows that method to be re-used for this case as it was before. Now cf.environment picks up the module under either name, so is listed as esmpy/ESMF rather than ESMF in the output dict.
  • All ESMF_* methods (e.g. ) have become esmpy_* methods (now esmpy_regrid_1d), i.e. the name conversion has also been made on method names. This makes sense to me, because the capitalised old name was defying naming conventions for methods and was ugly and weird in that way, plus now we use the newer name going forward. But please do confirm that this is OK, since it is an API change. (ON a related note, very few of those methods seem to be documented - is that something that needs addressing?)

Other issues flagged

I don't think this is related to this PR, but I need to investigate further... test_Field_regrid_2d_field is currently hanging for me locally (I can't test this on main without downgrading my ESMPy and conda hates downgrading anything so it will be a bit tricky to check quickly...). With the PR, all other test_regrid.py methods pass and in fact the whole test suite passes other than that when I skip it to stop to hanging, indicating things are fine otherwise.

Please let me know if you see this too! I suspect it could be to do with the newer ESMPy version and I will bump this to a new issue if we see further evidence of that!

Specifically, it hangs (I waited 5 mins or so before assuming that) so I apply:

diff --git a/cf/test/test_regrid.py b/cf/test/test_regrid.py
index ec4c9a4a0..34317cd7e 100644
--- a/cf/test/test_regrid.py
+++ b/cf/test/test_regrid.py
@@ -140,7 +140,8 @@ class RegridTest(unittest.TestCase):
     dst = dst_src[0]
     src = dst_src[1]
 
-    @unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
+    @unittest.skipIf(True, "HANGING BUT WHY?")
+    # Unless(esmpy_imported, "Requires esmpy/ESMF package.")
     def test_Field_regrid_2d_field(self):
         """2-d regridding with Field destination grid."""
         self.assertFalse(cf.regrid_logging())

to skip the hanging test and everything passes:

$ py test_regrid.py 
Run date: 2023-04-26 09:49:42.736762
Platform: Linux-4.15.0-54-generic-x86_64-with-glibc2.10 
HDF5 library: 1.14.0 
netcdf library: 4.9.2 
udunits2 library: /home/sadie/anaconda3/envs/cf-env/lib/libudunits2.so.0 
esmpy/ESMF: 8.4.1 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/esmpy/__init__.py
Python: 3.8.16 /home/sadie/anaconda3/envs/cf-env/bin/python
dask: 2023.1.0 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/dask/__init__.py
netCDF4: 1.6.3 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/netCDF4/__init__.py
psutil: 5.9.4 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/psutil/__init__.py
packaging: 23.0 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/packaging/__init__.py
numpy: 1.24.2 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/numpy/__init__.py
scipy: 1.10.1 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/scipy/__init__.py
matplotlib: 3.4.3 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/matplotlib/__init__.py
cftime: 1.6.0 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cftime/__init__.py
cfunits: 3.3.5 /home/sadie/cfunits/cfunits/__init__.py
cfplot: 3.1.18 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfplot/__init__.py
cfdm: 1.10.1.0 /home/sadie/cfdm/cfdm/__init__.py
cf: 3.14.1 /home/sadie/cf-python/cf/__init__.py

test_Field_regrid_2d_field (__main__.RegridTest)
2-d regridding with Field destination grid. ... skipped 'HANGING BUT WHY?'
test_Field_regridc_1d_field (__main__.RegridTest)
1-d Cartesian regridding with Field destination grid. ... ok
test_Field_regridc_2d_coords (__main__.RegridTest)
2-d Cartesian regridding with coords destination grid. ... ok
test_Field_regridc_3d_field (__main__.RegridTest)
3-d Cartesian regridding with Field destination grid. ... ok
test_Field_regridc_domain (__main__.RegridTest)
Spherical regridding with Domain destination grid. ... ok
test_Field_regrids_bad_dst (__main__.RegridTest)
Disallowed destination grid types raise an exception. ... ok
test_Field_regrids_coords (__main__.RegridTest)
Spherical regridding with coords destination grid. ... ok
test_Field_regrids_domain (__main__.RegridTest)
Spherical regridding with Domain destination grid. ... ok
test_Field_regrids_field_operator (__main__.RegridTest)
Spherical regridding with operator destination grid. ... ok
test_Field_regrids_non_coordinates (__main__.RegridTest)
Check setting of non-coordinate metadata. ... ok

----------------------------------------------------------------------
Ran 10 tests in 26.558s

OK (skipped=1)

@sadielbartholomew sadielbartholomew added installation Rrelating to installing the library regridding Relating to regridding operations labels Apr 26, 2023
@sadielbartholomew sadielbartholomew added this to the 3.15.0 milestone Apr 26, 2023
@sadielbartholomew
Copy link
Member Author

The CI test suite jobs are failing on setup, namely package dependency conflicts RE cf and cfdm (cf-python 3.14.1 requires cfdm<1.10.1.0,>=1.10.0.3, but you have cfdm 1.10.1.0 which is incompatible.) so can be ignored, those it might be useful to see those later so I could bodge the constraints if need be. I'll await your review first, David.

Copy link
Collaborator

@davidhassell davidhassell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Sadie - very thorough job. Thanks. I have tested the new code with both 8.2.0 and 8.4.0, and both work just fine. I have one minor question about nested try/except clauses, which you should resolve in anyway you like (including ignoring it).

Please merge whenever you're ready.

cf/regrid/regrid.py Outdated Show resolved Hide resolved
Changelog.rst Show resolved Hide resolved
@sadielbartholomew
Copy link
Member Author

@davidhassell thanks for the review. What do you see with regards to my comment under 'Other issues flagged' in #639 (comment)?

@davidhassell
Copy link
Collaborator

Hi Sadie - I've run test_regrid.py with ESMF versions 8.2.0 and 8.4.0 on my system, and both run fine, taking ~90 seconds and ~
~80 seconds respectively.

@sadielbartholomew
Copy link
Member Author

Thanks David. Indeed, I was not being patient enough, having not noticed that that one test method takes quite a while relative to the others. Hence assuming it was hanging. I just got:

$ time py test_regrid.py 
Run date: 2023-04-26 14:20:19.667060
Platform: Linux-4.15.0-54-generic-x86_64-with-glibc2.10 
HDF5 library: 1.14.0 
netcdf library: 4.9.2 
udunits2 library: /home/sadie/anaconda3/envs/cf-env/lib/libudunits2.so.0 
esmpy/ESMF: 8.4.1 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/esmpy/__init__.py
Python: 3.8.16 /home/sadie/anaconda3/envs/cf-env/bin/python
dask: 2023.1.0 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/dask/__init__.py
netCDF4: 1.6.3 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/netCDF4/__init__.py
psutil: 5.9.4 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/psutil/__init__.py
packaging: 23.0 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/packaging/__init__.py
numpy: 1.24.2 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/numpy/__init__.py
scipy: 1.10.1 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/scipy/__init__.py
matplotlib: 3.4.3 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/matplotlib/__init__.py
cftime: 1.6.0 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cftime/__init__.py
cfunits: 3.3.5 /home/sadie/cfunits/cfunits/__init__.py
cfplot: 3.1.18 /home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/cfplot/__init__.py
cfdm: 1.10.1.0 /home/sadie/cfdm/cfdm/__init__.py
cf: 3.14.1 /home/sadie/cf-python/cf/__init__.py

test_Field_regrid_2d_field (__main__.RegridTest)
2-d regridding with Field destination grid. ... ok
test_Field_regridc_1d_field (__main__.RegridTest)
1-d Cartesian regridding with Field destination grid. ... ok
test_Field_regridc_2d_coords (__main__.RegridTest)
2-d Cartesian regridding with coords destination grid. ... ok
test_Field_regridc_3d_field (__main__.RegridTest)
3-d Cartesian regridding with Field destination grid. ... ok
test_Field_regridc_domain (__main__.RegridTest)
Spherical regridding with Domain destination grid. ... ok
test_Field_regrids_bad_dst (__main__.RegridTest)
Disallowed destination grid types raise an exception. ... ok
test_Field_regrids_coords (__main__.RegridTest)
Spherical regridding with coords destination grid. ... ok
test_Field_regrids_domain (__main__.RegridTest)
Spherical regridding with Domain destination grid. ... ok
test_Field_regrids_field_operator (__main__.RegridTest)
Spherical regridding with operator destination grid. ... ok
test_Field_regrids_non_coordinates (__main__.RegridTest)
Check setting of non-coordinate metadata. ... ok

----------------------------------------------------------------------
Ran 10 tests in 109.699s

OK

real	1m51.548s
user	1m52.335s
sys	0m2.182s

So that was a non-issue in the end. Thanks for your help there. All good.

I'll respond to your feedback and let you know once that's done. Should be 15 minutes or so. Then I think we're ready to merge unless you feel otherwise.

@davidhassell
Copy link
Collaborator

All good!

@davidhassell
Copy link
Collaborator

Hang on! docs/source/installation.rst needs updating too:

conda install -c conda-forge "esmpy>=8.0.0"

ought to do it, I think.

@davidhassell
Copy link
Collaborator

... and the conda command appears twice in that file.

@sadielbartholomew
Copy link
Member Author

Hang on! docs/source/installation.rst needs updating too

Oh, another good spot. One moment, I'll add a further commit. For now note I've resolved, I believe, the try/except nest conversion.

@sadielbartholomew
Copy link
Member Author

Hi David, I should have addressed everything you have raised, now, so ready for re-review. Thanks.

Copy link
Collaborator

@davidhassell davidhassell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. I've re-tested with both versions, and everything works. Good to go, I think.

@sadielbartholomew sadielbartholomew merged commit 951f5be into NCAS-CMS:main Apr 26, 2023
@sadielbartholomew sadielbartholomew deleted the esmf-py-module-renaming branch April 26, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installation Rrelating to installing the library regridding Relating to regridding operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adapt to ESMF Python interface module name change
2 participants