R

Grpc4bmi allows you to wrap a Hydrological model written in the R language into a GRPC server.

Installing Requirements

The bmi-r package can be installed using the following devtools command

devtools::install_github("eWaterCycle/bmi-r")

Creating

A model must implement the basic model interface (bmi).

This can be done by sub-classing the AbstractBmi class found in the bmi-r R package.

A model (in the example called mymodel) can than be given a basic model interface with something like

library(R6)
library(bmi)
library(mymodel)

MyModelBmi <- R6Class(
    inherit = AbstractBmi,
    public = list(
        getComponentName = function() return('mymodel'),
        bmi_initialize = function(config_file) {
            # TODO Construct & initialize mymodel model
        },
        update = function() {
            # TODO evolve mymodel model to next time step
        },
        # TODO implement all other bmi functions
    )
)

For an example of a BMI interface of the Wageningen Lowland Runoff Simulator (WALRUS) see walrus-bmi.r

Running

Once the model has an BMI interface it can be run as a GRPC server by installing the grpc4bmi[R] Python package with

pip install grpc4bmi[R]

The server can be started with

run-bmi-server --lang R [--path <R file with BMI model>] --name [<PACKAGE>::]<CLASS> --port <PORT>

For the WALRUS model the command is

run-bmi-server --lang R --path ~/git/eWaterCycle/grpc4bmi-examples/walrus/walrus-bmi.r --name WalrusBmi --port 55555

The Python grpc4bmi Using the client can then be used to connect to the server. Note that the --port and --path arguments also can be specified as the respective environment variables BMI_PORT and BMI_PATH.