Skip to content

Commit

Permalink
Able to talk to Julia heat model from Python
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Sep 24, 2024
1 parent b30e32f commit 99f141a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ __pycache__
python/.venv/
python/heat.toml
RemoteBMI.jl/example/Project.toml
RemoteBMI.jl/example/heat.toml
openapi-generator-cli.jar
openapitools.json
17 changes: 14 additions & 3 deletions RemoteBMI.jl/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add https://github.com/csdms/bmi-example-julia#b5d963e6bf864f5d42769e6cc0814dd7b
dev ..
CTRL-D
# Run server
export BMI_SERVER_PORT=50555
export BMI_PORT=50555
julia --project=$PWD heat_bmi_server.jl
```

Expand All @@ -24,16 +24,27 @@ Interact with it using the Python client.

```python
from remotebmi.client.client import RemoteBmiClient
from remotebmi.client.reserve import reserve_values
from remotebmi.reserve import reserve_values

client = RemoteBmiClient('http://localhost:50555')
# TODO use placeholder for path
# client.initialize('<absolute path>/heat.toml')
client.initialize('/home/stefanv/git/eWaterCycle/remotebmi/python/heat.toml')
# TODO Julia server throws error here
client.get_component_name()
'The 2D Heat Equation'
client.update()
client.get_current_time()
0.25
client.get_time_units()
's'
client.get_var_location('plate_surface__temperature')
'node'
client.get_var_type('plate_surface__temperature')
numpy.float64
client.get_var_grid('plate_surface__temperature')
0
client.get_grid_type(0)
'uniform_rectilinear'
dest = reserve_values(client, 'plate_surface__temperature')
r = client.get_value('plate_surface__temperature', dest)
r
Expand Down
22 changes: 11 additions & 11 deletions RemoteBMI.jl/src/RemoteBMI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import BasicModelInterface as BMI

# TODO move route implementations to own module

function initialize(req::HTTP.Request, bmi_initialize_request::BmiInitializeRequest)::Nothing
function initialize(req::HTTP.Request, initialize_request::InitializeRequest)::Nothing
global m
m = BMI.initialize(MyModel, bmi_initialize_request.config_file)
m = BMI.initialize(MyModel, initialize_request.config_file)
return nothing
end

function get_component_name(req::HTTP.Request)::GetComponentNameResponse
function get_component_name(req::HTTP.Request)::Dict{String, String}
return Dict("name" => BMI.get_component_name(m))
end

Expand Down Expand Up @@ -89,7 +89,7 @@ function get_grid_size(req::HTTP.Request, grid::Int64;)::Int64
return BMI.get_grid_size(m, grid)
end

function get_grid_type(req::HTTP.Request, grid::Int64;)::BmiGetGridTypeResponse
function get_grid_type(req::HTTP.Request, grid::Int64;)::Dict{String, String}
return Dict("type" => BMI.get_grid_type(m, grid))
end

Expand Down Expand Up @@ -142,8 +142,8 @@ function set_value(req::HTTP.Request, name::String, request_body::Vector{Float64
BMI.set_value(m, name, request_body)
end

function set_value_at_indices(req::HTTP.Request, name::String, bmi_set_value_at_indices_request::BmiSetValueAtIndicesRequest;)::Nothing
BMI.set_value_at_indices(m, name, bmi_set_value_at_indices_request)
function set_value_at_indices(req::HTTP.Request, name::String, set_value_at_indices_request::SetValueAtIndicesRequest;)::Nothing
BMI.set_value_at_indices(m, name, set_value_at_indices_request)
end

function get_current_time(req::HTTP.Request;)::Float64
Expand All @@ -162,7 +162,7 @@ function get_time_step(req::HTTP.Request;)::Float64
return BMI.get_time_step(m)
end

function get_time_units(req::HTTP.Request;)::GetTimeUnitsResponse
function get_time_units(req::HTTP.Request;)::Dict{String, String}
return Dict("units" => BMI.get_time_units(m))
end

Expand Down Expand Up @@ -247,18 +247,18 @@ function get_var_itemsize(req::HTTP.Request, name::String;)::Int64
return BMI.get_var_itemsize(m, name)
end

function get_var_location(req::HTTP.Request, name::String;)::GetVarLocationResponseLocation
function get_var_location(req::HTTP.Request, name::String;)::Dict{String, String}
return Dict("location" => BMI.get_var_location(m, name))
end

function get_var_nbytes(req::HTTP.Request, name::String;)::Int64
return BMI.get_var_nbytes(m, name)
end

function get_var_type(req::HTTP.Request, name::String;)::GetVarTypeResponse
function get_var_type(req::HTTP.Request, name::String;)::Dict{String, String}
raw_type = BMI.get_var_type(m, name)
map = Dict(
"Float64" => "float64",
"Float64" => "double",
"Float32" => "float32",
"Int64" => "int64",
"Int32" => "int32",
Expand All @@ -271,7 +271,7 @@ function get_var_type(req::HTTP.Request, name::String;)::GetVarTypeResponse
return Dict("type" => type)
end

function get_var_units(req::HTTP.Request, name::String;)::GetVarUnitsResponse
function get_var_units(req::HTTP.Request, name::String;)::Dict{String, String}
return Dict("units" => BMI.get_var_units(m, name))
end

Expand Down

0 comments on commit 99f141a

Please sign in to comment.