Sign inSign up

ewatercycle/grpc4bmi-r

By ewatercycle

•Updated about 8 years ago

Starting point to make a R based hydrology model into a grpc4bmi server

Image
Languages & frameworks
Data science
0

10K+

ewatercycle/grpc4bmi-r repository overview

Wrap a model written in R which implements the basic model interface (bmi) in a gRPC server.

See https://github.com/eWaterCycle/grpc4bmi⁠ for the Python server/client implementation.

⁠Install

System requirements:

From R

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

⁠Usage

First the model should be wrapped in a basic model interface be subclassing the AbstractBmi class. Then the server can be started with:

export BMI_MODULE=<path to r script with bmi class>
export BMI_CLASS=<bmi class name>
export BMI_PORT=<port on which to run grpc server, default is 55555>
Rscript -e 'grpc4bmi::run()'

⁠Docker container

To install grpc is a bit of a hassle so a Docker image is provided called ewatercycle/grpc4bmi-r⁠ which contains R and grpc installation.

To create a Docker image of a R based hydrology model use this image as a start.

So for example for https://github.com/ClaudiaBrauer/WALRUS⁠

FROM ewatercycle/grpc4bmi-r

RUN installGithub.r ClaudiaBrauer/WALRUS

RUN mkdir /opt/walrus-bmi

COPY walrus-bmi.r /opt/walrus-bmi/walrus-bmi.r

ENV BMI_MODULE=/opt/walrus-bmi/walrus-bmi.r
ENV BMI_CLASS=WalrusBmi

To run server use

docker run -d -v $PWD:/data -p 55555:55555 <docker image from ewatercycle/grpc4bmi-r>

The config file for the bmi initialize function should be put in current working directory and the initialize function should be called with /data/<config filename.

To run server in debug mode use

docker run -d -v $PWD:/data -p 55555:55555 -e GRPC_TRACE=api -e GRPC_VERBOSITY=DEBUG <docker image from ewatercycle/grpc4bmi-r>

⁠Release

⁠Generate man pages

Rscript -e "devtools::document(roclets=c('rd', 'collate', 'namespace'))"

⁠Generate cpp files from proto file

cd src
protoc -I ../inst/proto --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../inst/proto/bmi.proto
protoc -I ../inst/proto --cpp_out=. ../inst/proto/bmi.proto
cd -

⁠Local build & install

Rscript -e 'Rcpp::compileAttributes();devtools::document()'
R CMD INSTALL .
Rscript -e 'grpc4bmi::run()'

Tag summary

Content type

Image

Digest

Size

448.4 MB

Last updated

about 8 years ago

docker pull ewatercycle/grpc4bmi-r