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

Combine 0.2.x branch with master #124

Merged
merged 178 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
35ebc87
Merge pull request #58 from eWaterCycle/singularity-from-notebook-56-…
sverhoeven Feb 19, 2020
12d7414
Prep for 0.2.4 release
sverhoeven Feb 19, 2020
1ef38b6
Attempt to create grpc channel on occupied port (#64)
sverhoeven Mar 13, 2020
2a1cc40
Prep for v0.2.5 release
sverhoeven Mar 24, 2020
e73ed9e
Prep for 0.2.6 release
sverhoeven Mar 24, 2020
f7f422f
Added extra_volumes arg to BmiClientDocker
sverhoeven Jul 27, 2020
479a848
Added extra_volumes arg to BmiClientSingularity
sverhoeven Jul 27, 2020
82e47a4
Merge pull request #71 from eWaterCycle/extra-volumes-0.2.0
sverhoeven Jul 29, 2020
24eccec
Prep for 0.2.7 release
sverhoeven Jul 29, 2020
cb639df
Backport 4ca0fe305ca46167774c328d9d38c1a006a33f7b
sverhoeven Jul 30, 2020
9ef3a2b
Added test to trigger RESOURCE_EXHAUSTED error
sverhoeven Aug 11, 2020
b7f1ec2
Implemented chunked get_value
sverhoeven Aug 11, 2020
8c2a915
Swap travis for GH action
sverhoeven Aug 11, 2020
51dd5ae
Revert "Swap travis for GH action"
sverhoeven Aug 11, 2020
3e05977
Swap travis for GH action
sverhoeven Aug 11, 2020
314fd54
Build & install bmi-c
sverhoeven Aug 11, 2020
48d4a32
Added sonar-project.properties
sverhoeven Aug 11, 2020
c285914
Merge branch '0.2-gh-action' into value-too-big-0.2.x
sverhoeven Aug 11, 2020
9189b46
No debug cli arg in 0.2.x branch
sverhoeven Aug 11, 2020
d13ddec
Revert "No debug cli arg in 0.2.x branch"
sverhoeven Aug 11, 2020
65d985d
No debug cli arg in 0.2.x branch, take 2
sverhoeven Aug 11, 2020
2d00924
Merge pull request #78 from eWaterCycle/value-too-big-0.2.x
sverhoeven Aug 11, 2020
15a82db
Prep for 0.2.8 release
sverhoeven Aug 11, 2020
c1460b7
Added sleep to BmiClientSingularity
sverhoeven Oct 19, 2020
f425f68
Merge pull request #85 from eWaterCycle/sing-sleep-84
sverhoeven Oct 19, 2020
1ad1969
Prep for 0.2.9
sverhoeven Oct 19, 2020
2d49220
Replace parent env with injected env var
sverhoeven Oct 19, 2020
fe89680
Prep for 0.2.10 release
sverhoeven Oct 19, 2020
7480d73
Raise required singularity version so `--env` works.
sverhoeven Oct 19, 2020
98d7d8a
Use sing v.3.6.4
sverhoeven Oct 19, 2020
54beca8
Merge pull request #86 from eWaterCycle/sing-env-84
sverhoeven Oct 19, 2020
a3d1350
Replace bad chars in singularity version
sverhoeven Jan 26, 2021
ad4fa0e
Use setup-singularity@v5 in CI job
sverhoeven Jan 26, 2021
bfbbc32
Use ewatercycle/setup-grpc@v3 in CI
sverhoeven Jan 26, 2021
27b8e22
Merge pull request #89 from eWaterCycle/semver-valueerror-88
sverhoeven Jan 26, 2021
dbad2d5
Prep for 0.2.11 release
sverhoeven Jan 26, 2021
4fc30b3
Use ubuntu-20.04 for ci
sverhoeven Mar 5, 2021
180b3b6
cpp workflow also compiles grpc instead of using prebuilt binary swit…
sverhoeven Mar 5, 2021
4b90f29
Use patched version of setup-singularity
sverhoeven Mar 5, 2021
d8bc8b2
Use v6 of sing action
sverhoeven Mar 5, 2021
d5f8cab
Use setup-grpc@v4 action
sverhoeven Mar 8, 2021
ded4038
Add unit test for work_dir
sverhoeven Mar 18, 2021
0eafaa8
Refactored BmiClientSingularity arguments
sverhoeven Mar 19, 2021
e09fd3b
English
sverhoeven Mar 19, 2021
56f0b67
Refactored BmiClientDocker to behave similar to BmiClientSingularity
sverhoeven Mar 19, 2021
c4dc591
Added example for parallel model runs
sverhoeven Mar 19, 2021
87ca8ab
Correct existing tests
sverhoeven Mar 19, 2021
300c695
For api docs have 1 module per file
sverhoeven Mar 19, 2021
9a21710
Updated docs to use refactored classes
sverhoeven Mar 19, 2021
b6d632c
More checks and tests
sverhoeven Mar 19, 2021
aff4255
More docs
sverhoeven Mar 19, 2021
d55b250
Docs layout
sverhoeven Mar 19, 2021
4ae8070
Explain delay, timeout better
sverhoeven Mar 19, 2021
ac02211
Rename utils to contstants as that is all it contains now
sverhoeven Mar 19, 2021
f23f919
More tests based on examples in doc string
sverhoeven Mar 19, 2021
854b809
Correct path to data file inside image
sverhoeven Mar 22, 2021
47916f7
Use same version of singularity as installed on Cartesius
sverhoeven Mar 22, 2021
37c80eb
Made `work_dir` required
sverhoeven Mar 22, 2021
609fe59
Remove default work_dir from docstrings
sverhoeven Mar 22, 2021
4127706
Apply suggestions from code review
sverhoeven Mar 24, 2021
c148520
Use *.sif in example
sverhoeven Mar 24, 2021
9523367
Use the sif
sverhoeven Mar 24, 2021
0177061
Use typeguard to assert argument types for better errors + explain wf…
sverhoeven Mar 24, 2021
934ca91
Add extra check for input_dirs as str == Iterable[str]
sverhoeven Mar 24, 2021
92a60ac
Merge pull request #94 from eWaterCycle/93-workdir-identity-mount
sverhoeven Mar 26, 2021
15213c4
Prep for 0.2.12 release
sverhoeven Mar 26, 2021
5219ea1
Added MemoizedBmi
sverhoeven Mar 30, 2021
c7e3434
Added `stdout`, `stderr` argument to BmiClientSingularity constructor
sverhoeven Jul 16, 2021
20f23fc
Use correct name
sverhoeven Jul 16, 2021
d6e6326
Unused import
sverhoeven Jul 16, 2021
bca8189
Silence semver deprecation warning
sverhoeven Jul 19, 2021
e55e7dc
Add logs() to BmiClientSingularity and BmiClientDocker
sverhoeven Jul 19, 2021
659721a
Prep for 0.2.13 release
sverhoeven Jul 20, 2021
e9a38b5
Use own method
sverhoeven Jul 20, 2021
6001693
Dedup container exception
sverhoeven Jul 20, 2021
1882d5f
Merge pull request #102 from eWaterCycle/sing-capture-output
sverhoeven Jul 20, 2021
bedee90
Use sing 3.8.3
sverhoeven Oct 13, 2021
ec82a5e
Merge pull request #107 from eWaterCycle/sing-383-in-ci
sverhoeven Oct 20, 2021
cc355ab
Use Bmi class from basic_modeling_interface
sverhoeven Nov 8, 2021
ada138d
Merge pull request #97 from eWaterCycle/memoized_bmi_client
sverhoeven Nov 11, 2021
798950a
Prep for 0.2.14 release
sverhoeven Nov 11, 2021
d4e644a
Use older docutils to fix build on readthedocs
sverhoeven Nov 11, 2021
0d0f3dd
Drop futures as it failed to install
sverhoeven Sep 20, 2022
54f3485
Allow apptainer to be used by BmiClientSingularity
sverhoeven Sep 20, 2022
531fcc9
Make sonar cloud happy
sverhoeven Sep 20, 2022
251ed72
Dont run double CI on push to PR
sverhoeven Sep 20, 2022
df506fd
Add test for BmiR
sverhoeven Sep 20, 2022
d2ee26a
Use Python 3.10 in CI + use absolute path to fake.r
sverhoeven Sep 20, 2022
2b407b1
YAML strips 0, use string instead
sverhoeven Sep 20, 2022
2a30308
Pin scipy
sverhoeven Sep 20, 2022
2e84d30
Add R code
sverhoeven Sep 20, 2022
00fb1b3
Make sure pytest has R_LIBS_USER env var set
sverhoeven Sep 20, 2022
8d432bc
Use export for env vars
sverhoeven Sep 20, 2022
d275a4f
For some reason get_value_ref fails on CI, skipping
sverhoeven Sep 20, 2022
4646f1e
Set R_LIBS_USER once
sverhoeven Oct 18, 2022
e1e9608
Use PEP440 and packaging package to check if apptainer/singularity ve…
sverhoeven Oct 18, 2022
a8cd7ca
Fixed heat model, so no longer need to pin scipy
sverhoeven Oct 18, 2022
89a3b48
Use setup-r GH action to set R_LIBS_USER env
sverhoeven Oct 18, 2022
fc538c3
Pin protobuf to v3
sverhoeven Oct 18, 2022
1e9272a
Dont install protobuf v4 and then downgrade
sverhoeven Oct 18, 2022
c1d6f1b
Try to figure out which test is hanging
sverhoeven Oct 18, 2022
6d510ea
CI: Use apptainer + use system R
sverhoeven Oct 18, 2022
ed18d05
Merge pull request #112 from eWaterCycle/allow-apptainer-version
sverhoeven Oct 18, 2022
c5ed76f
Prep for 0.2.15 release
sverhoeven Oct 18, 2022
a16813e
Add apptainer client
sverhoeven Nov 8, 2022
17c4abb
Add apptainer to some more places.
sverhoeven Nov 15, 2022
768c10e
Add required work_dir to examples
sverhoeven Nov 15, 2022
00d00fa
Point doc badge to 0.2.x version on readthedocs.
sverhoeven Nov 15, 2022
ad7fed1
Merge pull request #119 from eWaterCycle/116-apptainer-client
sverhoeven Nov 15, 2022
1953b8c
Prep for 0.2.16 release
sverhoeven Nov 15, 2022
01826b2
Merge remote-tracking branch 'origin/0.2.x' into bmi2
sverhoeven Jan 5, 2023
5a138ae
Replace setup.py + requirements.txt with pyproject.toml
sverhoeven Jan 5, 2023
f8f3284
Fixing test suite
sverhoeven Jan 5, 2023
b17a180
Fix protobuf-cpp and protobuf-python have potential Denial of Service…
sverhoeven Jan 5, 2023
e6cc822
Fix tests for MemoizedBmi
sverhoeven Jan 6, 2023
50b00d6
Enable branch coverage + only look for tests in test/
sverhoeven Jan 6, 2023
acc5b64
Fix BmiClientDocker tests
sverhoeven Jan 6, 2023
06faa70
Use latest GH actions
sverhoeven Jan 6, 2023
f23154b
Fix R tests
sverhoeven Jan 6, 2023
f001150
Fix sing tests
sverhoeven Jan 6, 2023
3461796
Fix legacy server tests
sverhoeven Jan 6, 2023
c00852c
More legacy server tests
sverhoeven Jan 6, 2023
ebf97bc
Use newer grpc on CI job for C++
sverhoeven Jan 6, 2023
86e2608
Legacy docs
sverhoeven Jan 6, 2023
68cf69e
Fix sphinx warning
sverhoeven Jan 11, 2023
98d5e7e
Heat model now is 1d
sverhoeven Jan 11, 2023
d450d54
Added OptionalDestBmi class
sverhoeven Jan 11, 2023
4f7ff5e
Force readthedocs build to use Python 3.10
sverhoeven Jan 11, 2023
df21720
Force installation of sphinx extensions on readthedocs
sverhoeven Jan 11, 2023
1d7f8ac
Use docs extra + added copy button extension
sverhoeven Jan 11, 2023
dd0e4e1
Format docstring
sverhoeven Jan 11, 2023
49a38ef
Generate bindings with protobuf v4
sverhoeven Jan 20, 2023
d36c2d8
Add Dockerfiles for heat model using different versions
sverhoeven Jan 20, 2023
2017ecb
Revert "Add Dockerfiles for heat model using different versions"
sverhoeven Jan 20, 2023
56a1fc3
Add Dockerfiles for heat model using different versions
sverhoeven Jan 20, 2023
939dff0
Use latest @actions/cache
sverhoeven Jan 20, 2023
75856ca
Working on wrapping heatcxx in a grpc4bmi server container image
sverhoeven Jan 20, 2023
99e0a47
Move bmi-c submodule to v2.1 tag
sverhoeven Jan 23, 2023
8a4024b
Stuck on linker
sverhoeven Jan 23, 2023
f0e0e14
Get grpc4bmi from gh instead of local mount
sverhoeven Jan 23, 2023
ede0a47
Fix compile
sverhoeven Jan 26, 2023
117dc24
const
sverhoeven Jan 26, 2023
3bb6070
Dont install
sverhoeven Jan 26, 2023
a573637
More debug
sverhoeven Jan 26, 2023
19247c4
More prints
sverhoeven Jan 26, 2023
8c5849d
Add reflection
sverhoeven Jan 26, 2023
3adfe23
Ignore sif files for git and docker
sverhoeven Jan 30, 2023
84fb60d
Prefer install of bmi-c + bmi-cxx over git submodule
sverhoeven Jan 30, 2023
727f3bc
Got working server from bmi-example-cxx
sverhoeven Jan 30, 2023
0926af9
More cleanup
sverhoeven Jan 30, 2023
80dd5b9
Remove deps of deps
sverhoeven Jan 30, 2023
f0fce18
Make sure bmi.hxx is imported
sverhoeven Jan 30, 2023
2241fe8
Wrap bmiheatc with grpc
sverhoeven Jan 30, 2023
2e937b3
Install bmi-c and bmi-cxx in CI
sverhoeven Jan 30, 2023
4fb5946
Allocate strings
sverhoeven Jan 31, 2023
f4d5155
Drop cache buster
sverhoeven Jan 31, 2023
c606b5a
Old python heat model is missing get_var_itemsize, added workaround
sverhoeven Feb 8, 2023
f3323b9
Add image with `run-bmi-server --bmi-version 0.2 ...`
sverhoeven Feb 8, 2023
e023b4a
Add build command + simplify non-python dirs
sverhoeven Feb 21, 2023
732f5fd
Correct GetGridRank wrapper c function was calling get_grid_size
sverhoeven Feb 21, 2023
3798bbc
Structure readme
sverhoeven Feb 21, 2023
5a129ad
Make typeguard==3 compatible
sverhoeven Mar 16, 2023
6ab8927
Add check back as str is iterable which passes typechecked
sverhoeven Mar 16, 2023
b12e5f3
Fix thing I broke with prev commit
sverhoeven Mar 16, 2023
11c7965
One more test to fix
sverhoeven Mar 16, 2023
4850b2c
Pin protobuf to v4
sverhoeven Mar 16, 2023
c209b22
Merge pull request #129 from eWaterCycle/typeguard3-compat
sverhoeven Mar 16, 2023
570a1b6
Apply suggestions from code review
sverhoeven Mar 16, 2023
cf9928f
Made py image names consistent
sverhoeven Mar 16, 2023
eb91cfc
Merge pull request #126 from eWaterCycle/latest-protobuf
sverhoeven Mar 20, 2023
5cbfd99
Document how legacy containers can be used
sverhoeven Mar 20, 2023
b091821
Sync version in docs/conf.py with pyproject.toml
sverhoeven Mar 20, 2023
c55ceb0
Prep for 0.4.0 release
sverhoeven Mar 20, 2023
487899a
Make sif create command multiline
sverhoeven Mar 20, 2023
13cde02
Clearify dest2 is same as dest
sverhoeven Mar 20, 2023
c5cc9b9
Mention get_value_at_indices signature change in class docstring
sverhoeven Mar 20, 2023
f6a7679
Dont use branches that are removed after PR is merged.
sverhoeven Mar 20, 2023
48d8e31
Use builtin int instead of numpy.int_ alias
sverhoeven Mar 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,48 @@ name: CI

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]

jobs:
python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.6
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
- name: Setup Singularity
uses: eWaterCycle/setup-singularity@v6
python -m pip install --upgrade pip wheel
pip install -e .[dev,R]
- name: Setup Apptainer
uses: eWaterCycle/setup-apptainer@v2
with:
singularity-version: 3.6.4
apptainer-version: 1.1.3
- name: Pull Docker image
run: docker pull ewatercycle/walrus-grpc4bmi:v0.3.1
- name: Cache Singularity image
id: cache-singularity-image
- name: Cache Apptainer image
id: cache-apptainer-image
uses: actions/cache@v2
with:
path: ~/.singularity
key: singularity-image
- name: Pull Singularity image
if: steps.cache-singularity-image.outputs.cache-hit != 'true'
run: singularity pull docker://ewatercycle/walrus-grpc4bmi:v0.3.1
path: ~/.apptainer
key: apptainer-image
- name: Pull Apptainer image
if: steps.cache-apptainer-image.outputs.cache-hit != 'true'
run: apptainer pull docker://ewatercycle/walrus-grpc4bmi:v0.3.1
- uses: r-lib/actions/setup-r@v2
with:
install-r: false
- name: Install R dependencies
run: |
Rscript -e "install.packages('remotes')"
Rscript -e "install.packages('R6')"
- name: Test with pytest
run: pytest --cov=grpc4bmi --cov-report xml
run: |
pytest -vv --cov=grpc4bmi --cov-report xml
- name: Correct coverage paths
run: sed -i "s+$PWD/++g" coverage.xml
- name: SonarCloud analysis
Expand All @@ -46,19 +55,22 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
cpp:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
- name: Install grpc
uses: ewatercycle/setup-grpc@v4
with:
grpc-version: 1.27.2
grpc-version: 1.48.2
- name: Copy grpc to system default
run: |
sudo rsync -a $GRPC_ROOT/ /usr/local
sudo ldconfig
- name: Build & install bmi-c
run: mkdir -p build && cd build && cmake .. && sudo make install
working-directory: cpp/bmi-c
- name: Build dir
run: mkdir -p cpp/build
- name: configure
Expand All @@ -70,3 +82,4 @@ jobs:
- name: ctest
run: ctest -V
working-directory: cpp/build
# TODO use https://github.com/marketplace/actions/sonarcloud-scan-for-c-and-c
16 changes: 16 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
sverhoeven marked this conversation as resolved.
Show resolved Hide resolved

build:
os: "ubuntu-22.04"
tools:
python: "3.10"

sphinx:
configuration: docs/conf.py

python:
install:
- method: pip
path: .
extra_requirements:
- docs
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Purpose

This software allows you to wrap your Basic Model Interface (BMI) implementation ([https://github.com/csdms/bmi](https://github.com/csdms/bmi)) in a server process and communicate with it via the included Python client. The communication is serialized to protocol buffers by gRPC ([https://grpc.io/](https://grpc.io/)) and occurs over network ports.
This software allows you to wrap your [Basic Model Interface (BMI)](https://github.com/csdms/bmi) implementation in a server process and communicate with it via the included Python client. The communication is serialized to protocol buffers by [GRPC](https://grpc.io/) and occurs over network ports. Can run models in isolated containers using Docker or Apptainer.

## Installation

Expand Down Expand Up @@ -43,13 +43,17 @@ in the cpp folder.

### Model written in Python

For inspiration look at the example in the test directory. To start a server process that allows calls to your BMI implementation, type
A model should be a subclass of the `Bmi` class from the [bmipy](https://pypi.org/project/bmipy/2.0/) package.

For inspiration look at the [example](test/fake_models.py) in the test directory.

To start a server process that allows calls to your BMI implementation, type

```bash
run-bmi-server --name <PACKAGE>.<MODULE>.<CLASS> --port <PORT> --path <PATH>
```

where ```<PACKAGE>, <MODULE>``` are the Python package and module containing your implementation, ```<CLASS>``` is your
where ```<PACKAGE>, <MODULE>``` are the python package and module containing your implementation, ```<CLASS>``` is your
bmi model class name, ```<PORT>``` is any available port on the host system, and optionally ```<PATH>``` denotes an
additional path that should be added to the system path to make your implementation work. The name option above is
optional, and if not provided the script will look at the environment variables ```BMI_PACKAGE```, ```BMI_MODULE``` and
Expand Down Expand Up @@ -99,9 +103,8 @@ mymodel.initialize(<FILEPATH>)
...further BMI calls...
```

The package contains also client implementation that own the server process, either as a Python subprocess or a docker
image or a singularity image running the ```run-bmi-server``` script. For instance

The package contains also client implementation that own the server process, either as a Python subprocess or a Docker
container or a Singularity container or a Apptainer container running the ```run-bmi-server``` script. For instance
```python
from grpc4bmi.bmi_client_subproc import BmiClientSubProcess
mymodel = BmiClientSubProcess(<PACKAGE>.<MODULE>.<CLASS>)
Expand All @@ -110,18 +113,25 @@ mymodel = BmiClientSubProcess(<PACKAGE>.<MODULE>.<CLASS>)
will automatically launch the server in a sub-process and

```python
from grpc4bmi.bmi_client_subproc import BmiClientDocker
mymodel = BmiClientDocker(<IMAGE>,<PORT>)
from grpc4bmi.bmi_client_docker import BmiClientDocker
mymodel = BmiClientDocker(<IMAGE>, <WORK DIR TO MOUNT>, input_dirs=[<INPUT DIRECTORIES TO MOUNT>])
```

will launch a docker container, assuming that a gRPC BMI server will start and exposes the port ```<PORT>```.
will launch a Docker container based on supplied Docker image
and will mount supplied directories to share files between the container and host.

```python
from grpc4bmi.bmi_client_singularity import BmiClientSingularity
mymodel = BmiClientSingularity(<IMAGE>,<PORT>)
mymodel = BmiClientSingularity(<IMAGE>, <WORK DIR TO MOUNT>, input_dirs=[<INPUT DIRECTORIES TO MOUNT>])
Peter9192 marked this conversation as resolved.
Show resolved Hide resolved
```
will launch a singularity container on based supplied Singularity image
and will mount supplied directories to share files between the container and host.

will launch a singularity container, assuming that a gRPC BMI server will start and exposes the port ```<PORT>```.
```python
from grpc4bmi.bmi_client_apptainer import BmiClientApptainer
mymodel = BmiClientApptainer(<IMAGE>, <WORK DIR TO MOUNT>, input_dirs=[<INPUT DIRECTORIES TO MOUNT>])
```
will launch a Apptainer container on based supplied Apptainer image
and will mount supplied directories to share files between the container and host.

For more documentation see [https://grpc4bmi.readthedocs.io/](https://grpc4bmi.readthedocs.io/).

Expand All @@ -130,10 +140,16 @@ For more documentation see [https://grpc4bmi.readthedocs.io/](https://grpc4bmi.r
When developers change the proto-file, it is necessary to install gRPC tools Python packages in your Python environment:

```bash
pip install -r requirements.txt
pip install -e .
# Create virtual env
python3 -m venv .venv
. venv/bin/activate
# Make sure latest pip and wheel are install
pip install -U pip wheel
pip install -e .[dev]
# For R integration also install the R extras with
pip install -e .[R]
# For building docs (cd docs && make html) also install the docs extras with
pip install -e .[docs]
```

and install the C++ runtime and `protoc` command as described in <https://github.com/google/protobuf/blob/master/src/README.md>.
Expand Down
3 changes: 2 additions & 1 deletion docs/_static/design-overview.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/_static/design-overview.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<mxfile modified="2019-03-29T15:45:23.435Z" host="www.draw.io" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/8.8.0 Chrome/61.0.3163.100 Electron/2.0.2 Safari/537.36" etag="E8JU1hGCv8wWEk0ACa1m" version="10.5.9" type="device"><diagram id="g6TwU9qutF0pdJ5EpEK3" name="Page-1">5VrbcpswEP0az6QPzYC42DzGJGk704vHnl6mbwoooEZGrpBv/fpKIDAgnJDW2JPYL4iVWFnnaFd7sAeWP9+8Y3ARf6IhIgNghJuBdT0AwDRdIC7Sss0tQ8PODRHDoRq0M8zwH6SMhrIucYjS2kBOKeF4UTcGNElQwGs2yBhd14fdU1KfdQEjpBlmASS69TsOeaysrmPvOt4jHMW8XLGX98xhMVotJY1hSNcVk3UzsHxGKc9b842PiESvACZ/7nZPb/nNGEp4lwem38Y/vIV//TNY//qJPqZ/3OmPt2oZK0iWasWTLY9pImwX6DK6FNfPlKM7Sh/eqGXwbQEOo8skRNK9MbDG6xhzNFvAQPauxXYQtpjPibgzRXOFGMcC2CuCo0TYOJUDUs7oQwmtwGSsvpAYjTZ7V2qW+Imdh+gccbYVQ9QDwFIcqE1nFxSsKxSOlC2usuep7QrVtolK3ztgRUNh+wycHQ3nAXCJmHYc4pVoRrI5/vShsIpJKh1PIF9BuY2Ee0yITwll2bPWffaRdprwWzjHRML0cRngEIpZfJqkVM5zECbsOhOOCXQm3BYmLKMnIkYtRDTARUl4JVOHuAsITFMc1DHuhhsKtczyJGoVVJwWUAobQwRyvKq7b0NKzTChWExckmLbRp2UYQPslC5ZgNRT1YzScDQCTzjikEWIa44y4spl/zuXxSFRITOaTnyZsxBfU/YgWhNGOQ0oKQLrjhVBBWRym6LfS5RybQ+ILc/rrOeZqoijhCaoEVrKBFV+CwTZiLUkvjkOw2yftMVqPbCPEKGO0+DQasmV3jEj1DQ1Vq9p8CCwBLcznERLAhnm2xwIDnEie45xMoUwjTOf8qFIZgbl/wA0jJox2UJDCXmVBmD0xgPYF10zxFYSdOMiLxb+szKoI22e9sQaDRtEFBVsNR6GLUTYTl88WBoPWaFwDui7AFw63fDvLx/pNXKhc3xx3RExADI4pq+aD3fYlY/+4qFTLf01zTJUztCrrqltp2NN7fQWIe6+k8InGGUVY8dc9XJQd06P+rAlDs5MymgKZGTXXXSVMpomajrqW8routTK9cmCbDVaz1edeHbb+dOmT0BfcQf0ekwjKBJILZqSQd5MIBe4J5kFGNIalCImH7UXNfWKE94VkxjPRdM0m+EChhqYx1YZnobma1B7j+ycR3PlkdEv9sNjGk/ciTWPX1ZZ+yz8N3UFoYLDOrXwA/qLECX8zpUS7/RqsEj2j6hBxU4uB/38cksZZ/CFafUDMGZapxeMoE0wnlmhbDVOfrcZIJ3f+ZsNR17D0Z5CWaALt5VhCzkgfcYX9mq/bopG7vGgVTjQhawpq/CZWBSvHIrNnxLsfJCoJPaP0bbc+RTxzS3jjPSM0Lb3+yvhden8ZfpCCZL96n8TwD4MYaYxtOuMgTbZZR+GMnG7+xNEHsm7/5JYN38B</diagram></mxfile>
<mxfile modified="2022-11-15T11:35:34.226Z" host="app.diagrams.net" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" etag="v_puD-7TxF7KD0VfFUmk" version="20.4.0" type="device"><diagram id="g6TwU9qutF0pdJ5EpEK3" name="Page-1">5Vpbb5swFP41SNvDKjCXhMeGrtukXaJE26q9ueCCVwcz49z262eDSQCTlm2hWZeqEubY2Pj7zjk+XxLDDhabNwxmyQcaIWIAM9oY9pUBgOUAYMh/M9qWltHYKw0xw5EatDfM8U+kjKayLnGE8sZATinhOGsaQ5qmKOQNG2SMrpvD7ihprprBGGmGeQiJbv2KI54oq+c6+463CMdJtbTl+WXPAlaj1VbyBEZ0XTPZrw07YJTysrXYBIhI9CpgyueuD/Tu3oyhlPd5YPZlcuNnwdW3cP39G3qf//RmN6/UNlaQLNWOp1ue0FTYXqCL+EJcP1KObim9f6m2wbcVOIwu0wjJ6U3DnqwTzNE8g6HsXQt3ELaEL4i4s0RzhRjHAthLguNU2DiVA3LO6P0OWoHJRN+W2qmcAG1qJrXNN4guEGdbMUT1AltxoJzOqShY1ygcK1tSZ89X7gqV28S7uffAiobC9jdwdjWcDeARsewkwivRjGVz8uFdZRWL1DoeQb6GchcJd5iQgBLKimftu+JP2mnKr+ECEwnT+2WIIyhWCWiaU7nOUZhwmky4FtCZ8DqYsM2BiBh3ENECF6XRpUwd4i4kMM9x2MT4j3FDUSPZ6KjVUHE7QKlsDBHI8aqZorqQUitMKRZvsiPFccwmKaMW2DldshCpp+oZpTXRGDwyEYcsRlybqCBut+0/57I6JGpkxrNpIHMW4mvK7kVryiinISVVYN2yKqiATG4z9GOJcq75gPBv3mS9zFRVHKU0Ra3QUiao8lso2EesI/EtcBQVftIVq83AfoIIdd0Wh3ZHrvSfMkItS2P1iob3AktwfZllHOJUtiUMVfspzqUI5kkxp3wolnlBzX8EEsbtiOwgYQd4nQRgDsYCOBRbc8RWBQEvylLhL+uCJtLWac+r8ahFhNdxXo06iHDcoXiwNR6KMuEc0PcAuHD74T9cNtIr5ErlBOK6J8IAMjhm/zUf3qgvH8PFQ69K+nOujgjJ0H9dUTtuz4raHSxCvEMnRUAwKurFnrnq+aDunh71UUccnJmQ0fTH2GlO0VfIaIqoPdHQQkZXpXapTjKy1Wg9X23iO13nT5c6AUPFHdDrMY2gWCCVtSWDvJlCLnBPCwswpTXciZhyVH/Udp95wttqXfNBNC2rHS5gpIH51CrD19B8ZlrvYSd53NVPh33lDQ8pPHEn9jz5h4vav8V/09QPKjTsU8s+oH8IomTfuVLin14LVqn+AS2o2CnFYFBerinjDP7LSn0Yxiz79HIRdMnFMyuT7da577UDpPfn/VZrIr810YEyWaALt7VhmRyQ/8YL+41vNmVtUMx41Boc6DLWkjX4XGyK1w7F9tcITjlIVBKHx2gudz4lfNtl3LGeEbp8f7gCXhfOn2bPlCDZr34zAZzjEGaZI6fJGOgSXc5xKBO3+x9AlJG8/x2J/foX</diagram></mxfile>
13 changes: 11 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', 'sphinx.ext.intersphinx', 'sphinxarg.ext']
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode',
'sphinx.ext.napoleon', 'sphinx.ext.intersphinx',
'sphinxarg.ext', 'sphinxcontrib.apidoc',
'sphinx_copybutton',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -63,7 +67,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -76,6 +80,11 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False

apidoc_module_dir = "../grpc4bmi"
apidoc_separate_modules = True
apidoc_toc_file = False
# Ignore generated files
apidoc_excluded_paths = ["bmi_pb2_grpc.py", "bmi_pb2.py"]
Peter9192 marked this conversation as resolved.
Show resolved Hide resolved

# -- Options for HTML output ----------------------------------------------

Expand Down
54 changes: 48 additions & 6 deletions docs/container/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ Grpc4bmi can run containers with `Docker engine`_.

Use the :class:`grpc4bmi.bmi_client_docker.BmiClientDocker` class to start a Docker container and get a client to interact with the model running inside the container.



For example the PCR-GLOBWB model can be started in a Docker container with

.. code-block:: python

from grpc4bmi.bmi_client_docker import BmiClientDocker

model = BmiClientDocker(image='ewatercycle/pcrg-grpc4bmi:latest', image_port=55555,
input_dir="./input",
output_dir="./output")
work_dir="./input")
# Interact with model
model.initialize('config.cfg')

Expand All @@ -27,6 +26,8 @@ For example the PCR-GLOBWB model can be started in a Docker container with

.. _Docker engine: https://docs.docker.com/

.. _Singularity-section:

Singularity
-----------

Expand All @@ -48,15 +49,56 @@ Use the :class:`grpc4bmi.bmi_client_singularity.BmiClientSingularity` class to s
.. code-block:: python

from grpc4bmi.bmi_client_singularity import BmiClientSingularity

image = '<docker image name of grpc4bmi server of a bmi model>'
client = BmiClientSingularity(image, input_dir='<directory with models input data files>')
input_dir = '<directory with models input data files>'
work_dir = '<directory where model can write output files>'
client = BmiClientSingularity(image, work_dir, input_dirs=[input_dir])

# Interact with model
client.initialize('<absolute path to config file in the input directory>')

# Stop container
del client

For example for the wflow Docker image the commands would be the following

.. code-block:: python

from grpc4bmi.bmi_client_singularity import BmiClientSingularity

image = 'docker://ewatercycle/wflow-grpc4bmi:latest'
client = BmiClientSingularity(image, input_dir='wflow_rhine_sbm', output_dir='wflow_output')
work_dir = '/tmp/run1'
client = BmiClientSingularity(image, work_dir, input_dirs=['/scratch/input/wflow_rhine_sbm'])

# Interact with model
client.initialize('/scratch/input/wflow_rhine_sbm/wflow_sbm_bmi.ini')

# Stop container
del client


.. _Singularity: https://www.sylabs.io/guides/latest/user-guide/

Apptainer
---------

Grpc4bmi can run containers on `Apptainer`_.

Apptainer is an open source fork of singularity.

Apptainer behaves very similar to singularity so everything described in :ref:`Singularity-section` chapter also goes for Apptainer.
You will need to replace the `singularity` command with `apptainer` and :class:`grpc4bmi.bmi_client_singularity.BmiClientSingularity` class with
:class:`grpc4bmi.bmi_client_apptainer.BmiClientApptainer` class.

.. _Apptainer: https://apptainer.org/docs/user/main/

Sharing files between host computer and container
-------------------------------------------------

Containers run in an isolated file system and by default can not read/write any files on host computer.
To get a directory on your host computer inside a container you have mount them with `input_dirs` and
`work_dir` arguments of :py:class:`grpc4bmi.bmi_client_docker.BmiClientDocker` and
:py:class:`grpc4bmi.bmi_client_singularity.BmiClientSingularity`.

See :py:class:`grpc4bmi.bmi_client_singularity.BmiClientSingularity` for examples using `input_dirs` and `work_dir`.
2 changes: 1 addition & 1 deletion docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Introduction

The Basic Modeling Interface (BMI, see https://github.com/csdms/bmi) is a multi-language library interface tailored to earth system models. This software allows you to wrap a BMI implementation in a server process and communicate with it via the included python client. The communication is serialized to protocol buffers by GRPC (https://grpc.io/) and occurs over network ports. On the server side, we support BMI implementations in :ref:`python <pythonservice>`, R or C/C++. Fortran models need to be linked against the C-version of the BMI. On the client side, we expose the standard python BMI (https://github.com/csdms/bmi-python/).

This setup enables you to wrap your BMI-enabled model in a Docker (https://www.docker.com/) or Singularity (https://singularity.lbl.gov/) container and communicate with it from a python process on the host machine.
This setup enables you to wrap your BMI-enabled model in a Docker (https://www.docker.com/) or Singularity (https://singularity.lbl.gov/) or Apptainer (https://apptainer.org) container and communicate with it from a python process on the host machine.

.. image:: _static/design-overview.svg
2 changes: 1 addition & 1 deletion docs/python_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Python API
.. toctree::
:maxdepth: 4

grpc4bmi
api/grpc4bmi
19 changes: 17 additions & 2 deletions docs/server/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ and inside the ``mymodule.py`` the bmi implementation

.. code-block:: python

from bmi import Bmi
from bmipy import Bmi

class MyBmi(Bmi):
def __init__(self):
Expand All @@ -63,4 +63,19 @@ Then we launch this toy model as a service by executing

$ run-bmi-server --name mypackage.mymodule.MyBmi

This will report the chosen port number in the standard output stream. It can be used to connect to the service via the BMI :ref:`grpc python client <python-grpc4bmi-client>`.
This will report the chosen port number in the standard output stream. It can be used to connect to the service via the BMI :ref:`grpc python client <python-grpc4bmi-client>`.

Legacy version
--------------

The grpc4bnmi by default uses the `v2.0 version of the Basic Model Interface (BMI) <https://pypi.org/project/bmipy/2.0/>`_ on the client and server side..
Peter9192 marked this conversation as resolved.
Show resolved Hide resolved
Grpc4bmi has support for `legacy version 0.2 of BMI <https://pypi.org/project/basic-modeling-interface/0.2/>`_ on the server side.

A legacy model can be launched with

.. code-block:: sh

$ run-bmi-server --bmi-version 0.2 --name mypackage.mymodule.MyLegacyBmi

The functions only present in v0.2 will not be callable.
Copy link
Contributor

Choose a reason for hiding this comment

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

So this means that people that were installing grpc4bmi with the v0.2 bmi will loose this functionality when they change over to the new master branch release. Should we somehow provide update instructions for them?

One option is to make a last release of the v0.2 branch with a message that this will be the last release and people are encouraged to update to the latest version of grpc4bmi and remove the deprecated bmi calls in their models

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, is there a diff somewhere to see which functions differ between bmi v2 and v0.2?

The functions only present in v2.0 will throw not implemented errors.
Loading