Skip to content

Commit

Permalink
Add Julia support to gprc4bmi
Browse files Browse the repository at this point in the history
Refs #101
  • Loading branch information
sverhoeven committed Sep 29, 2023
1 parent 271ff01 commit b913f8d
Show file tree
Hide file tree
Showing 7 changed files with 727 additions and 4 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ on the client (Python) side. If your server model is implemented in Python, do t
pip install grpc4bmi[R]
```

If the model is implemented in Julia, run instead

```bash
pip install grpc4bmi[julia]
```

in the server environment. For bleeding edge version from GitHub use

```bash
Expand Down Expand Up @@ -90,6 +96,25 @@ For example with [WALRUS](https://github.com/eWaterCycle/grpc4bmi-examples/tree/
run-bmi-server --lang R --path ~/git/eWaterCycle/grpc4bmi-examples/walrus/walrus-bmi.r --name WalrusBmi --port 55555
```

### Models written in Julia

The grpc4bmi Python package can also run BMI models written in Julia if the model has an implementation of the [BasicModelInterface.jl](https://github.com/Deltares/BasicModelInterface.jl).

Run the Julia model as a server with

```bash
run-bmi-server --lang julia --name <PACKAGE>,<BMI-IMPLEMENTATION-NAME>,<MODEL-NAME> --port <PORT>
```

For example with [Wflow.jl](https://github.com/Deltares/Wflow.jl/) use

```bash
# Install Wflow.jl package in the Julia environment managed by the juliacall Python package.
python3 -c 'from grpc4bmi.bmi_julia_model import install;install("Wflow")'
# Run the server
run-bmi-server --lang julia --name Wflow,Wflow.BMI,Wflow.Model --port 55555
```

### The client side

The client side has only a Python implementation. The default BMI client assumes a running server process on a given port.
Expand Down Expand Up @@ -154,7 +179,3 @@ 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>.
After this, simply executing the `proto_gen.sh` script should do the job.

## Future work

More language bindings are underway.
24 changes: 24 additions & 0 deletions docs/container/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ The WALRUS model has a `Dockerfile`_ file which can be used as an example.

.. _Dockerfile: https://github.com/eWaterCycle/grpc4bmi-examples/blob/master/walrus/Dockerfile

Julia
-----

The docker file for the model container simply contains the installation instructions of grpc4bmi and the BMI-enabled model itself, and as entrypoint the ``run-bmi-server`` command. For the :ref:`python example <python-example>` the Docker file will read

.. code-block:: Dockerfile
FROM ubuntu:jammy
MAINTAINER your name <your email address>
# Install grpc4bmi
RUN pip install grpc4bmi
# Install your BMI model:
python3 -c 'from grpc4bmi.bmi_julia_model import install;install("<JULIA-PACKAGE-NAME>")'
# Run bmi server
ENTRYPOINT ["run-bmi-server", "--lang", "julia", "--name", "<PACKAGE>,<BMI-IMPLEMENTATION-NAME>,<MODEL-NAME>"]
# Expose the magic grpc4bmi port
EXPOSE 55555
The port 55555 is the internal port in the Docker container that the model communicates over. It is the default port for ``run_bmi_server`` and also the default port that all clients listen to.

C/C++/Fortran
-------------

Expand Down
47 changes: 47 additions & 0 deletions docs/server/Julia.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Julia
=====

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

.. _Julia language: https://julialang.org/

Creating
--------

The model should implement `BasicModelInterface.jl`_.

.. _BasicModelInterface.jl: https://github.com/Deltares/BasicModelInterface.jl

See `Wflow.jl`_ for an example.

.. _Wflow.jl: https://deltares.github.io/Wflow.jl/dev/

Running
-------

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

.. code-block:: bash
pip install grpc4bmi[julia]
The model Julia package must be installed in the Julia environment managed by juliacall,
for Wflow use

.. code-block:: bash
python3 -c 'from grpc4bmi.bmi_julia_model import install;install("Wflow")'
The server can be started with

.. code-block:: sh
run-bmi-server --lang julia --name <PACKAGE>,<BMI-IMPLEMENTATION-NAME>,<MODEL-NAME> --port <PORT>
For example with [Wflow.jl](https://github.com/Deltares/Wflow.jl/) use

.. code-block:: sh
run-bmi-server --lang julia --name Wflow,Wflow.BMI,Wflow.Model --port 55555
The Python grpc4bmi :ref:`usage` can then be used to connect to the server.
1 change: 1 addition & 0 deletions docs/server/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Creating a BMI server

python
R
Julia
Cpp
Loading

0 comments on commit b913f8d

Please sign in to comment.