Skip to content

Commit 374c39d

Browse files
committed
Add gprc4bmi dockerfile, instructions/docs.
1 parent 376ed6b commit 374c39d

4 files changed

Lines changed: 166 additions & 4 deletions

File tree

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
21
FROM ghcr.io/ecoextreml/stemmus_scope:1.5.0
2+
3+
LABEL maintainer="Bart Schilperoort <b.schilperoort@esciencecenter.nl>"
34
LABEL org.opencontainers.image.source = "https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing"
45

56
# Requirements for building Python 3.10
67
RUN apt-get update && apt-get -y upgrade
78
RUN apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev \
89
libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
10+
RUN apt-get install -y libhdf5-serial-dev
911

1012
# Get Python source and compile
1113
WORKDIR /python
@@ -22,9 +24,10 @@ COPY . /opt/PyStemmusScope
2224
RUN pip3.10 install /opt/PyStemmusScope/[docker]
2325
RUN pip3.10 install grpc4bmi==0.5.0
2426

25-
# Set the STEMMUS_SCOPE environmental variable, so the BMI can find the executable
27+
# # Set the STEMMUS_SCOPE environmental variable, so the BMI can find the executable
2628
WORKDIR /
27-
ENV STEMMUS_SCOPE ./STEMMUS_SCOPE
29+
ENV STEMMUS_SCOPE /STEMMUS_SCOPE
2830

31+
EXPOSE 55555
2932
# Start grpc4bmi server
3033
CMD run-bmi-server --name "PyStemmusScope.bmi.implementation.StemmusScopeBmi" --port 55555 --debug

docs/bmi.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@ Alternatively, if the environmental variable `STEMMUS_SCOPE` is configured, the
4343

4444
## Using the BMI
4545

46-
A [notebook demonstration the use of the Basic Model Interface](../notebooks/BMI_demo/) is available.
46+
A [notebook demonstration the use of the Basic Model Interface](notebooks/BMI_demo.ipynb) is available.
4747
For more information on using BMI, see the [CSDMS website](https://csdms.colorado.edu/wiki/BMI).
4848

4949
If you need access to other model variables that are not yet available in the BMI, please raise an issue on the [STEMMUS_SCOPE repository](https://github.com/EcoExtreML/STEMMUS_SCOPE/issues), or leave a comment if an issue is open already.
5050

51+
## grpc4bmi
52+
53+
A [Docker image is available](https://ghcr.io/ecoextreml/stemmus_scope-gprc4bmi) in which the model as well as the Python BMI have been wrapped in a container.
54+
This allows communication with a STEMMUS_SCOPE BMI through [gprc4bmi](https://grpc4bmi.readthedocs.io/en/latest/).
55+
56+
Doing so avoids the needs to install PyStemmusScope yourself, only Docker/apptainer and a python environment with gprc4bmi are required.
57+
58+
A demonstration is available [here](notebooks/gprc4bmi_demo.ipynb)
59+
5160
## Developer instructions
5261

5362
The Python BMI implemented in this package communicates with the Matlab code through STDIN/STDOUT, or via a socket to the Docker container.

docs/notebooks/gprc4bmi_demo.ipynb

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# grpc4bmi demonstration\n",
8+
"\n",
9+
"If you want to run the model plus BMI in a container, this is possible with the `stemmus_scope_grpc4bmi` docker image.\n",
10+
"\n",
11+
"The image contains both the STEMMUS_SCOPE model and the Python BMI. The interface uses [`grpc4bmi`](https://grpc4bmi.readthedocs.io/) for communication with the running container.\n",
12+
"\n",
13+
"To run this notebook you need to have grpc4bmi installed in your python environment."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 1,
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"from grpc4bmi.bmi_client_docker import BmiClientDocker\n",
23+
"\n",
24+
"model = BmiClientDocker(\n",
25+
" image='ghcr.io/ecoextreml/stemmus_scope-gprc4bmi:1.5.0', \n",
26+
" image_port=55555,\n",
27+
" work_dir=\"/home/bart/tmp/stemmus_scope\",\n",
28+
")"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"We can ensure that the model is named STEMMUS_SCOPE:"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 2,
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"data": {
45+
"text/plain": [
46+
"'STEMMUS_SCOPE'"
47+
]
48+
},
49+
"execution_count": 2,
50+
"metadata": {},
51+
"output_type": "execute_result"
52+
}
53+
],
54+
"source": [
55+
"model.get_component_name()"
56+
]
57+
},
58+
{
59+
"cell_type": "markdown",
60+
"metadata": {},
61+
"source": [
62+
"Initialization works like normal. Note that you do not want to have the `DockerImage` or `ExeFilePath` entries in your configuration file (!):"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 3,
68+
"metadata": {},
69+
"outputs": [
70+
{
71+
"data": {
72+
"text/plain": []
73+
},
74+
"execution_count": 3,
75+
"metadata": {},
76+
"output_type": "execute_result"
77+
}
78+
],
79+
"source": [
80+
"model.initialize(\"/home/bart/tmp/stemmus_scope/config_grpc4bmi.txt\")"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 4,
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"model.update()"
90+
]
91+
},
92+
{
93+
"cell_type": "markdown",
94+
"metadata": {},
95+
"source": [
96+
"We can succesfully request values from the model:"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 5,
102+
"metadata": {},
103+
"outputs": [
104+
{
105+
"data": {
106+
"text/plain": [
107+
"array([3.6085965])"
108+
]
109+
},
110+
"execution_count": 5,
111+
"metadata": {},
112+
"output_type": "execute_result"
113+
}
114+
],
115+
"source": [
116+
"import numpy as np\n",
117+
"model.get_value(\"respiration\", dest=np.zeros(1))"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": []
126+
}
127+
],
128+
"metadata": {
129+
"kernelspec": {
130+
"display_name": "PyStemmusScope",
131+
"language": "python",
132+
"name": "python3"
133+
},
134+
"language_info": {
135+
"codemirror_mode": {
136+
"name": "ipython",
137+
"version": 3
138+
},
139+
"file_extension": ".py",
140+
"mimetype": "text/x-python",
141+
"name": "python",
142+
"nbconvert_exporter": "python",
143+
"pygments_lexer": "ipython3",
144+
"version": "3.10.12"
145+
}
146+
},
147+
"nbformat": 4,
148+
"nbformat_minor": 2
149+
}

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ nav:
99
- BMI:
1010
- "BMI instructions": bmi.md
1111
- "BMI demonstration": notebooks/BMI_demo.ipynb
12+
- "grpc4bmi demonstration": notebooks/gprc4bmi_demo.ipynb
1213
- Contributing guide: CONTRIBUTING.md
1314
- API reference: reference.md
1415

0 commit comments

Comments
 (0)