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

Refactor rawdem #224

Merged
merged 39 commits into from
Jan 4, 2024
Merged

Refactor rawdem #224

merged 39 commits into from
Jan 4, 2024

Conversation

rosepearson
Copy link
Owner

@rosepearson rosepearson commented Dec 3, 2023

@jennan refactor to try address Dask failures

Specifically:
Create mask arrays instead of repeatably clipping against geometries.
Revisit the save/load
Add a no_values_mask property

  • Make code change
  • Update tests
    • Update / create new tests
    • Ensure these tests have the expected behavour
    • Test locally and ensure tests are passing
  • Ensure tests passing on GH Actions
  • Update documentation
    • Doc strings
    • Wiki
  • Update package (version.py & pyproject.toml) version (if needed)

jennan added 18 commits December 3, 2023 01:24
It looks like if `*args` are passes to a logging function, a placeholder `%s`
is needed in the logging message, otherwise it issues an error.
As RawLidarDemGenerator is taking care of the temporary folder, and to avoid
hiding the I/O operation inside RawDem.add_lidar, I am moving it to one level
up, inside RawLidarDemGenerator.run. Overall, the idea is to separate the I/O
methods from the preparation methods in RawDem.
This is a continuation of splitting I/O from preparing the data preparation.
These 2 parameters are always the same and used in enough method that adding
them to the instance reduce the signature length of multiple methods.
`no_values_mask` is now a property, it is easy to check before adding a new
coarse DEM if it is needed, making the coarse DEM loop not too big to be
included in RawLidarDemGenerator
@jennan
Copy link
Collaborator

jennan commented Dec 7, 2023

Hi, here are my notes about what I have tried so far, in order to improve the behavior of the dask part on the example tile (i.e. getting good cpu utilisation, little transfer overhead reported in the dashboard and no worker timeout errors).

Trying without work stealing (https://distributed.dask.org/en/latest/work-stealing.html)

DASK_DISTRIBUTED__SCHEDULER__WORK_STEALING="False" python -m geofabrics --instruction instruction_lidar.json
  • poor utilisation (~65%)
  • terrible compute vs. transfer (more transfer than compute)
  • so... let's forget it

Trying to change priority (https://distributed.dask.org/en/stable/priority.html)

with dask.annotate(priority=10):
    dem["z"] = dem.z.where(mask , 0)
  • 70% to 90% cpu utilisation
  • transfer not neglectable but lower than compute

Trying to pre-scatter the mask to clip dem in add_lidar (for foreshore)

from distributed.client import default_client
mask = client.scatter(mask)
  • 70% to 90% utilisation
  • seems quite slow
  • repeated messages about large graph while no transfer (only compute)
  • but then timeout messages and transfer increase

Trying to get more reliable comms

DASK_DISTRIBUTED__COMM__RETRY__COUNT=3 python -m geofabrics --instruction instruction_lidar.json
  • doesn't seem to avoid timeout errors

Trying to remove all clipping/masking before self.raw_dem.save_dem(cached_file, ...)

  • cpu utilisation between 30 and 90%
  • no transfer overhead
  • no timeout error

Testing with different masking in add_lidar (just testing up to self.raw_dem.save_dem(cached_file, ...) and still without most rio.clip)

  • only masking dem.z: timeout errors (run a bit)
  • only masking dem.z / only clip_mask: timeout error (run a bit)
  • only masking dem.z / only dem.z < 0:
    • no timeout error and no transfer oberhead (run up to 80%)
    • then timeout errors but was playing with Dask profilers...
  • masking all dem components / only dem.z < 0: no timeout error and no transfer oberhead
  • masking all dem components / xarray.ones_like(dem.z, dtype=bool) | (dem.z <= 0)
    • mostly no timeout error and no transfer oberhead
    • but some timeout errors after 90% completion
  • masking all dem components / persist clip_mask: some timeout errors and transfer overhead
  • masking all dem components / (dem.z <= 0) | mask and mask not lazy
    • not so good cpu utilisation, transfer overhead
    • no timeout messages
  • mask all dem components / (dem.z <= 0) | mask and broadcasted mask
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
  • mask all dem components / (dem.z <= 0) | mask and dask.block
mask = ~clip_mask(dem.z, buffered_foreshore.geometry, None)

arrs = []
for i in range(0, mask.shape[0], self.chunk_size):
    sub_arrs = []
    for j in range(0, mask.shape[1], self.chunk_size):
        chunk = mask[i : i + self.chunk_size, j : j + self.chunk_size].copy()
        sub_arrs.append(chunk)
    arrs.append(sub_arrs)
mask = dask.array.block(arrs)
  • transfer overhead, timeout messages
  • masking all dem components / clip_mask without compute
    • some timeouts and transfer overhead, not too bad

But adding clip_mask back everywhere, transfer is bad (significant amount vs. compute) and timeout errors for dask workers :(.

TODO export DASK__DISTRIBUTED__COMM__TIMEOUTS__CONNECT="60s"
TODO check scheduling https://distributed.dask.org/en/latest/scheduling-policies.html

@jennan jennan self-requested a review January 4, 2024 20:56
Copy link
Collaborator

@jennan jennan left a comment

Choose a reason for hiding this comment

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

I approve on behalf of Rose :-).

@rosepearson rosepearson linked an issue Jan 4, 2024 that may be closed by this pull request
@rosepearson rosepearson merged commit 21827df into main Jan 4, 2024
2 checks passed
@rosepearson rosepearson deleted the refactor_rawdem branch November 6, 2024 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dask improvements
2 participants