From 99f141a7571b01f71f12db07c5d98a7c8f80da0c Mon Sep 17 00:00:00 2001 From: sverhoeven Date: Tue, 24 Sep 2024 14:56:08 +0200 Subject: [PATCH] Able to talk to Julia heat model from Python --- .gitignore | 1 + RemoteBMI.jl/example/README.md | 17 ++++++++++++++--- RemoteBMI.jl/src/RemoteBMI.jl | 22 +++++++++++----------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 3e9bd6e..5079cc5 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/RemoteBMI.jl/example/README.md b/RemoteBMI.jl/example/README.md index ae6df17..f279f53 100644 --- a/RemoteBMI.jl/example/README.md +++ b/RemoteBMI.jl/example/README.md @@ -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 ``` @@ -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('/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 diff --git a/RemoteBMI.jl/src/RemoteBMI.jl b/RemoteBMI.jl/src/RemoteBMI.jl index e51e02f..f2ca264 100644 --- a/RemoteBMI.jl/src/RemoteBMI.jl +++ b/RemoteBMI.jl/src/RemoteBMI.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -247,7 +247,7 @@ 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 @@ -255,10 +255,10 @@ 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", @@ -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