Closed BSchilperoort closed 2 weeks ago
Found the error in the julia server code:
Server.jl:151-160
function set_value_at_indices(
req::HTTP.Request,
name::String,
set_value_at_indices_request::SetValueAtIndicesRequest;
)::Nothing
# OpenAPI request is zero-based, while Julia is one-based
jindexes = set_value_at_indices_request.indices .+ 1
src = set_value_at_indices_request.values
BMI.set_value_at_indices(m, name, src, jindexes)
end
While this is the BMI implementation:
function BMI.set_value_at_indices(m::Model, name, inds, src)
val = BMI.get_value_ptr(m, name)
val[inds] .= src
m
end
To reproduce: set up a julia remotebmi server with the heat model.
There seem to be two issues:
inds
andsrc
are switched around somewhereError 1 server output
```julia ┌ Error: handle_connection handler error. │ │ =========================== │ HTTP Error message: │ │ ERROR: BoundsError: attempt to access 48-element Vector{Float64} at index [[-20.0]] │ Stacktrace: │ [1] throw_boundserror(A::Vector{Float64}, I::Tuple{Vector{Float64}}) │ @ Base ./abstractarray.jl:744 │ [2] checkbounds │ @ ./abstractarray.jl:709 [inlined] │ [3] view │ @ ./subarray.jl:177 [inlined] │ [4] maybeview │ @ ./views.jl:148 [inlined] │ [5] dotview │ @ ./broadcast.jl:1214 [inlined] │ [6] set_value_at_indices(m::Heat.Model, name::String, inds::Vector{Float64}, src::Vector{Int64}) │ @ Heat ~/git/bmi-example-julia/src/bmi.jl:61 │ [7] set_value_at_indices(req::HTTP.Messages.Request, name::String, set_value_at_indices_request::RemoteBMI.Server.BmiServer.SetValueAtIndicesRequest) │ @ RemoteBMI.Server ~/git/remotebmi/RemoteBMI.jl/src/Server.jl:159 │ [8] (::RemoteBMI.Server.BmiServer.var"#set_value_at_indices_invoke_handler#90"{Nothing, Module})(req::HTTP.Messages.Request) │ @ RemoteBMI.Server.BmiServer ~/git/remotebmi/RemoteBMI.jl/src/server/apis/api_SettersApi.jl:62 │ [9] #2 │ @ ~/.julia/packages/OpenAPI/cxQPQ/src/server.jl:14 [inlined] │ [10] (::RemoteBMI.Server.BmiServer.var"#set_value_at_indices_validate_handler#88"{OpenAPI.Servers.var"#2#3"{Nothing, Module, typeof(RemoteBMI.Server.BmiServer.set_value_at_indices_invoke)}})(req::HTTP.Messages.Request) │ @ RemoteBMI.Server.BmiServer ~/git/remotebmi/RemoteBMI.jl/src/server/apis/api_SettersApi.jl:55 │ [11] (::RemoteBMI.Server.BmiServer.var"#set_value_at_indices_read_handler#87"{RemoteBMI.Server.BmiServer.var"#set_value_at_indices_validate_handler#88"{OpenAPI.Servers.var"#2#3"{Nothing, Module, typeof(RemoteBMI.Server.BmiServer.set_value_at_indices_invoke)}}})(req::HTTP.Messages.Request) │ @ RemoteBMI.Server.BmiServer ~/git/remotebmi/RemoteBMI.jl/src/server/apis/api_SettersApi.jl:45 │ [12] (::HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing})(req::HTTP.Messages.Request) │ @ HTTP.Handlers ~/.julia/packages/HTTP/y3eEt/src/Handlers.jl:439 │ [13] (::HTTP.Handlers.var"#1#2"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}})(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}) │ @ HTTP.Handlers ~/.julia/packages/HTTP/y3eEt/src/Handlers.jl:58 │ [14] #invokelatest#2 │ @ ./essentials.jl:819 [inlined] │ [15] invokelatest │ @ ./essentials.jl:816 [inlined] │ [16] handle_connection(f::Function, c::HTTP.Connections.Connection{Sockets.TCPSocket}, listener::HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, readtimeout::Int64, access_log::Nothing) │ @ HTTP.Servers ~/.julia/packages/HTTP/y3eEt/src/Servers.jl:469 │ [17] macro expansion │ @ ~/.julia/packages/HTTP/y3eEt/src/Servers.jl:401 [inlined] │ [18] (::HTTP.Servers.var"#16#17"{HTTP.Handlers.var"#1#2"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}}, HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, Set{HTTP.Connections.Connection}, Int64, Nothing, ReentrantLock, Base.Semaphore, HTTP.Connections.Connection{Sockets.TCPSocket}})() │ @ HTTP.Servers ./task.jl:514 │ request = │ HTTP.Messages.Request: │ """ │ POST /set_value_at_indices/plate_surface__temperature HTTP/1.1 │ Host: 0.0.0.0:50051 │ Accept: */* │ Accept-Encoding: gzip, deflate │ Connection: keep-alive │ User-Agent: python-httpx/0.27.2 │ Content-Length: 36 │ Content-Type: application/json │ │ """ └ @ HTTP.Servers ~/.julia/packages/HTTP/y3eEt/src/Servers.jl:483 ```
Error 2 server output
```julia ┌ Error: handle_connection handler error. │ │ =========================== │ HTTP Error message: │ │ ERROR: ArgumentError: invalid index: 24.0 of type Float64 │ Stacktrace: │ [1] to_index(i::Float64) │ @ Base ./indices.jl:300 │ [2] to_index(A::Vector{Float64}, i::Float64) │ @ Base ./indices.jl:277 │ [3] _to_indices1(A::Vector{Float64}, inds::Tuple{Base.OneTo{Int64}}, I1::Float64) │ @ Base ./indices.jl:359 │ [4] to_indices │ @ ./indices.jl:354 [inlined] │ [5] to_indices │ @ ./indices.jl:345 [inlined] │ [6] setindex! │ @ ./abstractarray.jl:1399 [inlined] │ [7] setindex! │ @ ./subarray.jl:327 [inlined] │ [8] copyto_unaliased!(deststyle::IndexCartesian, dest::SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Float64}}, false}, srcstyle::IndexLinear, src::Vector{Int64}) │ @ Base ./abstractarray.jl:1107 │ [9] copyto! │ @ ./abstractarray.jl:1073 [inlined] │ [10] copyto! │ @ ./broadcast.jl:967 [inlined] │ [11] copyto! │ @ ./broadcast.jl:926 [inlined] │ [12] materialize! │ @ ./broadcast.jl:884 [inlined] │ [13] materialize! │ @ ./broadcast.jl:881 [inlined] │ [14] set_value_at_indices(m::Heat.Model, name::String, inds::Vector{Float64}, src::Vector{Int64}) │ @ Heat ~/git/bmi-example-julia/src/bmi.jl:61 │ [15] set_value_at_indices(req::HTTP.Messages.Request, name::String, set_value_at_indices_request::RemoteBMI.Server.BmiServer.SetValueAtIndicesRequest) │ @ RemoteBMI.Server ~/git/remotebmi/RemoteBMI.jl/src/Server.jl:159 │ [16] (::RemoteBMI.Server.BmiServer.var"#set_value_at_indices_invoke_handler#90"{Nothing, Module})(req::HTTP.Messages.Request) │ @ RemoteBMI.Server.BmiServer ~/git/remotebmi/RemoteBMI.jl/src/server/apis/api_SettersApi.jl:62 │ [17] #2 │ @ ~/.julia/packages/OpenAPI/cxQPQ/src/server.jl:14 [inlined] │ [18] (::RemoteBMI.Server.BmiServer.var"#set_value_at_indices_validate_handler#88"{OpenAPI.Servers.var"#2#3"{Nothing, Module, typeof(RemoteBMI.Server.BmiServer.set_value_at_indices_invoke)}})(req::HTTP.Messages.Request) │ @ RemoteBMI.Server.BmiServer ~/git/remotebmi/RemoteBMI.jl/src/server/apis/api_SettersApi.jl:55 │ [19] (::RemoteBMI.Server.BmiServer.var"#set_value_at_indices_read_handler#87"{RemoteBMI.Server.BmiServer.var"#set_value_at_indices_validate_handler#88"{OpenAPI.Servers.var"#2#3"{Nothing, Module, typeof(RemoteBMI.Server.BmiServer.set_value_at_indices_invoke)}}})(req::HTTP.Messages.Request) │ @ RemoteBMI.Server.BmiServer ~/git/remotebmi/RemoteBMI.jl/src/server/apis/api_SettersApi.jl:45 │ [20] (::HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing})(req::HTTP.Messages.Request) │ @ HTTP.Handlers ~/.julia/packages/HTTP/y3eEt/src/Handlers.jl:439 │ [21] (::HTTP.Handlers.var"#1#2"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}})(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}) │ @ HTTP.Handlers ~/.julia/packages/HTTP/y3eEt/src/Handlers.jl:58 │ [22] #invokelatest#2 │ @ ./essentials.jl:819 [inlined] │ [23] invokelatest │ @ ./essentials.jl:816 [inlined] │ [24] handle_connection(f::Function, c::HTTP.Connections.Connection{Sockets.TCPSocket}, listener::HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, readtimeout::Int64, access_log::Nothing) │ @ HTTP.Servers ~/.julia/packages/HTTP/y3eEt/src/Servers.jl:469 │ [25] macro expansion │ @ ~/.julia/packages/HTTP/y3eEt/src/Servers.jl:401 [inlined] │ [26] (::HTTP.Servers.var"#16#17"{HTTP.Handlers.var"#1#2"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}}, HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, Set{HTTP.Connections.Connection}, Int64, Nothing, ReentrantLock, Base.Semaphore, HTTP.Connections.Connection{Sockets.TCPSocket}})() │ @ HTTP.Servers ./task.jl:514 │ request = │ HTTP.Messages.Request: │ """ │ POST /set_value_at_indices/plate_surface__temperature HTTP/1.1 │ Host: 0.0.0.0:50051 │ Accept: */* │ Accept-Encoding: gzip, deflate │ Connection: keep-alive │ User-Agent: python-httpx/0.27.2 │ Content-Length: 36 │ Content-Type: application/json │ │ """ └ @ HTTP.Servers ~/.julia/packages/HTTP/y3eEt/src/Servers.jl:483 ```