grpc4bmi demonstration¶
If you want to run the model plus BMI in a container, this is possible with the stemmus_scope_grpc4bmi
docker image.
The image contains both the STEMMUS_SCOPE model and the Python BMI. The interface uses grpc4bmi
for communication with the running container.
To run this notebook you need to have grpc4bmi installed in your python environment.
Note that your directory setup (work_dir
and input_dir
) may differ from this example, depending on where the config file, input directory and output directory are located.
from grpc4bmi.bmi_client_docker import BmiClientDocker
model = BmiClientDocker(
image='ghcr.io/ecoextreml/stemmus_scope-grpc4bmi:1.5.0',
image_port=55555,
work_dir="/home/bart/tmp/stemmus_scope",
)
We can ensure that the model is named STEMMUS_SCOPE:
model.get_component_name()
'STEMMUS_SCOPE'
Initialization works like normal. But note that you do not want to have the DockerImage
or ExeFilePath
entries in your configuration file
model.initialize("/home/bart/tmp/stemmus_scope/config_grpc4bmi.txt")
model.update()
We can succesfully request values from the model:
import numpy as np
model.get_value("respiration", dest=np.zeros(1))
array([3.6085965])
When finishing up, you can finalize the model, which will make the process inside the container exit cleanly:
model.finalize()
To kill the docker container and remove the logs, you (explicitly) delete the object:
del model