Remote BMI
The Basic Model Interface (BMI) is a standard interface for models. The interface is available in different languages and a language agnosting version in SIDL.
To have a consumer of the model and the provider of the model seperated you can use grpc4bmi, but this only works on languages that have a grpc implementation. This Python package replaced the gRPC protocol with an REST API. The REST API specification is in the OpenAPI format.
Remotebmi is available in other languages see here.
Difference from BMI
- Request body and response body are in JSON format
- On errors you get 4xx and 5xx responses with Problem Details as response body
- Variable names must be URL safe
- Variable type must be in enum.
- get_value_ptr function is not available
Consumer
Installation
pip install remotebmi
A client can connect to a running server with the following code.
from remotebmi import RemoteBmiClient
model = RemoteBmiClient('http://localhost:50051')
# Now you can use the BMI methods on model
# for example
model.initialize('config.file')
model.update()
model.get_value('var_name')
A client can also start a Apptainer container containing the model and the server.
from remotebmi import BmiClientApptainer
model = BmiClientApptainer('my_model.sif', work_dir='/tmp')
The client picks a random port and expects the container to run the BMI web server on that port.
The port is passed to the container using the BMI_PORT environment variable.
A client can also start a Docker container containing the model and the server.
from remotebmi import BmiClientDocker
model = BmiClientDocker('ewatercycle/wflowjl:0.7.3', work_dir='/tmp')
The BMI web server inside the Docker container should be running on port 50051.
If the port is different, you can pass the port as the image_port argument to the BmiClientDocker constructor.
Provider
Given you have a model class called MyModel in a package mypackage then the web service can be started with the following command.
BMI_MODULE=mypackage BMI_CLASS=MyModel run-bmi-server
For example leakybucket:
pip install leakybucket
BMI_MODULE=leakybucket.leakybucket_bmi BMI_CLASS=LeakyBucketBmi run-bmi-server
and the client can connect to it with the following code.
> from remotebmi import RemoteBmiClient
> client = RemoteBmiClient('http://localhost:50051')
> client.get_component_name()
leakybucket
Documentation
In a Python environment, go to the docs directory, do pip install -r requirements.txt
and then make html.
Metadata
Release files for remotebmi 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| remotebmi-0.1.0.tar.gz | 55.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| remotebmi-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 72.4 kB
Release files / remotebmi-0.1.0.tar.gz
| Download URL | remotebmi-0.1.0.tar.gz |
|---|---|
| Size | 55.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
396a37f126df7207f12d16874130e0d490e51065f58c7c2faa45bb10a5ce863f
|
|
BLAKE2b-256 checksum How to use checksums |
c9b872cd61914903a2c174edbffa0b94c56fce17d4c1dbe4a8c86180f06a71f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2024.
Transparency logRelease files / remotebmi-0.1.0-py3-none-any.whl
| Download URL | remotebmi-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6e9c198379478637d33d8d940934429d054afddc0f72dad869d1e990bec5e93
|
|
BLAKE2b-256 checksum How to use checksums |
dab9abbfa2a098c8d0690068ad02c6558629ab583a6cda0308d89e7b204b5461
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2024.
Transparency log