Skip to main content

Basic Model Interface over openapi specification

Project description

Remote BMI

Contributor Covenant Codecov test coverage

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remotebmi-0.1.0.tar.gz (55.5 kB view details)

Uploaded Source

Built Distribution

remotebmi-0.1.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file remotebmi-0.1.0.tar.gz.

File metadata

  • Download URL: remotebmi-0.1.0.tar.gz
  • Upload date:
  • Size: 55.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for remotebmi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 396a37f126df7207f12d16874130e0d490e51065f58c7c2faa45bb10a5ce863f
MD5 609078c7c58588fcb68cd49d155ef024
BLAKE2b-256 c9b872cd61914903a2c174edbffa0b94c56fce17d4c1dbe4a8c86180f06a71f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for remotebmi-0.1.0.tar.gz:

Publisher: python-publish.yml on eWaterCycle/remotebmi

Attestations:

File details

Details for the file remotebmi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: remotebmi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for remotebmi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6e9c198379478637d33d8d940934429d054afddc0f72dad869d1e990bec5e93
MD5 aac091b77b320192a7e384baba293527
BLAKE2b-256 dab9abbfa2a098c8d0690068ad02c6558629ab583a6cda0308d89e7b204b5461

See more details on using hashes here.

Provenance

The following attestation bundles were made for remotebmi-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on eWaterCycle/remotebmi

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page