Skip to content

Python BMI bindings - #112

Closed
robmtud wants to merge 8 commits into
CSHS-CWRA:mainfrom
robmtud:robmtud/python_bmi
Closed

robmtud wants to merge 8 commits into
CSHS-CWRA:mainfrom
robmtud:robmtud/python_bmi

Conversation

@robmtud

@robmtud robmtud commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Important

This pull request supersedes pull request #111. It includes the same changes on top which the functionality of this pull request is implemented. Only one of the two should be accepted. Please see issue #110 for a discussion of both pull requests.

This pull request adds Python bindings for Raven's Basic Model Interface to the project.
For a detailed description, discussion and examples please see issue #110.

robmtud and others added 8 commits September 18, 2026 14:10
- BMI only supports flux output for now
- config variables are the same as for CustomOutput:
    - To:SOIL[0]: flux
    - From:SOIL[0]: flux
    - Between:SOIL[0].And.SOIL[1]: flux
- check if state var named in config.txt is present in model
- check if model was previously initialized when executing 'CRavenBMI::Finalize'
- previously the output array was indexed by the values in the index array
  e.g requesting indices [0, 5, 10] would try to write to out[0], out[5]
  and out[10]
- now the output array is indexed by the the position of the index in
  the index array
The python bindings are a thin wrapper around the c++ BMI code and do
not implement the BMI python standard, but the resulting python module
can be wrapped in pure python to more easily implement the BMI python
variant.

List of changes / additions:

- move c++ and python code related to python module into './python'
  directory
- 'Binder' was used to generate the Pybind11 bindings for BMI c++ code
  (https://github.com/RosettaCommons/binder), auto generated bindings
  have been cleaned up manualy and no dependency on Binder has been
  added
- use 'scikit-build-core' to build python module / wheel
- add static library build of raven to staticly link the raven code with
  the python module
- some small 'CMakeLists.txt' clean ups
GetValue and SetValue use void pointer arguments for the destination and
source arrays respectively. Wrap these functions to use vectors for the
python bindings.
GetValueAtIndices and SetValueAtIndices use void pointer arguments for
the destination and source arrays respectively. Wrap these functions to
use vectors for the python bindings.
- replace vectors with Numpy arrays
- revert getter functions signatures back to C++ BMI style with provided
  output array; the BMI python bindings also do this

@analytophile analytophile left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggest that the python wrapper is maintained as an independent repo

The rest of the changes were integrated from a parallel commit

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.

2 participants