mcgibbon / sympl

A toolkit for building planetary/Earth system models in Python
http://sympl.readthedocs.io
Other
50 stars 14 forks source link

Unit handling code is slow #43

Open mcgibbon opened 6 years ago

mcgibbon commented 6 years ago

@JoyMonteiro brought up that currently when run in SCM mode, unit conversion checking takes up a significant amount of CliMT's runtime. We may want to add a faster backend for unit handling.

See climt/issues/75 for original discussion of this issue.

cfunits is a good candidate as a backend, but it appears to only work on Python 2. When I run cfunits-1.5.1 on Python 3, I get:

ValueError: Bad python version: cf requires 2.6 <= python < 3.0. Got 3.5.2

The more official package appears to be cf-units, hosted by the Met office, but that is also incompatible with Python 3 according to their docs and my attempt to download it through conda. We could try to fix it to work with Python 3 and submit a PR to them.

Or we could look for another option.

JoyMonteiro commented 5 years ago

cf-units now works on Python 3.6/3.7. Can we restart discussion/work around this issue?

JoyMonteiro commented 5 years ago

I was playing around with the code, and if I change this line: https://github.com/mcgibbon/sympl/blob/f97e21153c27e1659612699fd717be093ff106d6/sympl/_core/units.py#L81

With an equivalent statement using cf-units, the code is twice as fast. cf-units supports all aliases setup in this file. It does not understand 'dimensionless', and that needs to be handled. Otherwise, this should be easy to optimize -- use cfunits if it exists.