Skip to content

Commit

Permalink
Test all walrus methods, all ok except get_input_var_names
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Oct 7, 2024
1 parent 73e3a9a commit fad9f4d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/remotebmi/R/route.R
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ create_route <- function(model) {

# Getters
route$add_handler("get", "/get_value/:name", get_value)
route$add_handler("get", "/get_value_at_indices/:name", get_value_at_indices)
route$add_handler("post", "/get_value_at_indices/:name", get_value_at_indices)

# Setters
route$add_handler("post", "/set_value/:name", set_value)
Expand Down
65 changes: 48 additions & 17 deletions R/remotebmi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,70 @@ With Python client test the model
```python
import os
from remotebmi.client.client import RemoteBmiClient
from remotebmi.reserve import reserve_values
from remotebmi.reserve import reserve_values, reserve_grid_padding, reserve_grid_shape
import numpy as np

client = RemoteBmiClient('http://localhost:50051')
!wget https://github.com/eWaterCycle/grpc4bmi-examples/raw/refs/heads/master/walrus/walrus.yml
!wget https://github.com/ClaudiaBrauer/WALRUS/raw/refs/heads/master/demo/data/PEQ_Hupsel.dat
# Make data path in walrus.yml absolute
client.initialize( os.getcwd() + '/walrus.yml')
client.update()
# model information functions
client.get_component_name()
'WALRUS'

client.update()
client.get_output_var_names()
['ETact', 'Q', 'fGS', 'fQS', 'dV', 'dVeq', 'dG', 'hQ', 'hS', 'w']
client.get_output_item_count()
10
client.get_input_var_names()
# kaput, R server returns '' instead of '[]', while reqres::format_json()(list()) does return '[]'
client.get_input_item_count()
0
# Time functions
client.get_current_time()
367417
client.get_time_units()
'hours since 1970-01-01 00:00:00.0 00:00'
client.get_output_var_names()
['ETact', 'Q', 'fGS', 'fQS', 'dV', 'dVeq', 'dG', 'hQ', 'hS', 'w']
# TODO add to AbstractBmi and WalrusBmi
# client.get_var_location('Q')
client.get_var_type('Q')
numpy.float64
client.get_time_step()
1
client.get_end_time()
368904
client.get_start_time()
367416
# Variable information functions
client.get_var_grid('Q')
0
client.get_grid_type(0)
'rectilinear'
client.get_var_type('Q')
numpy.float64
client.get_var_units('Q')
'mm/h'
client.get_var_itemsize('Q')
8
client.get_var_nbytes('Q')
8
client.get_var_location('Q')
'node'
# Variable getter and setter functions
client.get_value('Q', dest=np.array([.1]))
array([0.0044])
client.get_var_nbytes('Q')
'mm/h'
dest = reserve_values(client, 'Q')
r = client.get_value('Q', dest)
r
client.get_value_at_indices('Q', dest=np.array([0.0]), inds=np.array([0]))
array([0.0044]) # walrus ignores inds and just always returns lumped value
# setter not implemented in walrus
# Model grid functions
client.get_grid_rank(0)
2
client.get_grid_type(0)
'uniform_rectilinear'
client.getgrid_size(0)
1
client.get_grid_shape(0, reserve_grid_shape(client, 0))
array([1, 1])
client.get_grid_origin(0, reserve_grid_padding(client, 0))
array([ 6.6544, 52.0613])
client.get_grid_spacing(0, reserve_grid_padding(client, 0))
array([0, 0])
# Other grid function not needed for walrus
# And finally
client.finalize()

```

0 comments on commit fad9f4d

Please sign in to comment.