improver: mask slowdown issue

Currently the nightly suite run demonstrates issues with some commands involving mask handling.

ppdev suite output:

MEM		INPUT		OUTPUT		CPU		TIME		USER		SYS		COMMAND
534816		84391		13683		99%		0:04.61		4.07		0.52		improver regrid --regrid-mode nearest --regridded-title...
632688		1717887		11174		99%		3:24.80		196.23		8.30		improver regrid --regrid-mode nearest-with-mask --land-sea-mask-vicinity 25000 --regridded-title...

Note the difference in run-time between the two.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (20 by maintainers)

Most upvoted comments

The issue with regrid is two-fold:

The first and most significant is that we are currently calling AdjustLandSeaPoints.correct_where_input_true, once for land and once for ocean, for EACH x-y slice of the input cube (“multi-realization data”). This then unnecessarily re-evaluates an unstructured nearest neighbour problem via calls to scipy.interpolate.griddata for each of these slices. Nearest neighbour calculations need only be calculated once for land and once for ocean…

https://github.com/metoppv/improver/blob/1088b59c1fe32a8bfab267b6be956b737633a966/improver/regrid/landsea.py#L260

The second ‘issue’ is then where dask rears its head, which is that we create these x-y slices as well as create various copies. Due to the change in chunking rules for NetCDF in recent iris, we are then hit (as with the weighted blending) with an unnecessary read from disk bottleneck.

Based on some quick changes locally: caching the nearest neighbour regridder by utilising ckdtree and also realising the data on load, I can confirm we can go from ~2m40s to <15s

@BelligerG @LaurenceBeard to raise visibility. Green team might not check this board too often 😃

From our chat Monday, it seemed that it might be acceptable for now, to read the data into memory on load. I’m not familiar with clize or to a great extent of Python typing, but it looks as though options for load_cube in particular no_lazy_load are not exposed to the CLI.

https://github.com/metoppv/improver/blob/43054bd803f6789c1cee3e36d3b31c495489e3e2/improver/utilities/load.py#L114-L118

The load is achieved through typing via the clize value_converter decorator.

https://github.com/metoppv/improver/blob/43054bd803f6789c1cee3e36d3b31c495489e3e2/improver/cli/weighted_blending.py#L40-L41

I think ideally this should be exposed to any of the commands (weighted-blending, regrid or otherwise) performing a load. Then perhaps we can apply this argument within the improver-suite for the cases effected.

We could expose this to the top-level improver CLI but perhaps that would be nasty to then have it as a global var.

Any suggestions?

Cheers

Definitely the issue is due to iris’ change of chunking as raised in SciTools/iris#4107 Replace, as_lazy_data from _lazy_data.py in iris version: 3.0.3 with the one from iris version: 2.2.0 and we get down to 11s

So running improver 0.19.0 against scitools/production-os43-2 gives the speeds we expect because as I thought the chunksizes are in line with how we are slicing the cube.

That is, debugging the same variables we described in https://github.com/metoppv/improver/issues/1579#issuecomment-938788589, gives:

cube_to_collapse.lazy_data().chunksize
(1, 1, 970, 1042)
first_slice.lazy_data().chunksize
(1, 970, 1042)

As we can see, this time the original dask array has chunksizes of 1 in BOTH the first and second dimension, meaning that the cube slices aren’t realising more than they need (i.e. we don’t have the x23 extra data that we have in recent versions where the chunksize is 23 in the second dim).

The question then becomes, what has caused this change in chunksizes assigned to the dask array of cube_to_collapse. A few possibilities:

  • improver where we do something to derive this cube differently (perhaps we do through an operation effecting chunksizes differently now - for example merge/slice/concatenation pathways).
  • iris where it instantiates our loaded cube (the dask array contained within it) with a different chunksize.
  • dask if iris or otherwise through dask usage results in a different heuristic in defining the chunksizes.