precice / precice/python-bindings

Reduce overhead of read_data and write_data

Open
#202 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Cython
Stars
30
Forks
19
PR merge metrics
No merged PRs in 30d

Description

In this discourse thread, I tracked down the increased duration spent in the "do-nothing solver" down to read_data and write_data.

Most logical explanation would be the additional

  • input vertex_ids and values are copied to a vector, even though passing np.reshape(X, -1) to the preCICE API suffices and prevents copies.
  • output values are allocated, then passed to the API, then allocated to build an np.array
  • we do a lot of additional error checking (which is good)

Example of rhoVW on solver2, being vectorial data of large mesh:

  • Time measured in preCICE: 7ms (note: this doesn't allocate)
  • Time measured in Python: 40ms (including overhead from activating profiling in python, this needs to allocate, so overhead scales with size)

Notes:

  • With some tweaking I can get this down to 30ms. This makes the function actually shorter, simpler, and easier to follow.
  • np.flatten() copies the input, while np.reshape doesn't if it can avoid it.
  • The majority of the generated code seems to be error handling, which we could potentially be avoided by using the CPP API directly for calls to getDataDimensions and do this in one place.
  • This overhead could be profiled with something like https://github.com/precice/precice/issues/1647

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Python binding entry points read_data and write_data, using the linked Discourse thread to understand the reported overhead and the notes about reshape, allocations, and error checking. Compare Python-side timings with the preCICE timings, then verify that the functions retain their behavior while avoiding unnecessary copies and allocations.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
api, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.