From 410995ce4dfa2fc955582abd00d65640af03f63f Mon Sep 17 00:00:00 2001 From: Willem van Verseveld Date: Tue, 3 Dec 2024 11:49:29 +0100 Subject: [PATCH 1/3] Wflow server: allow JSON reading and writing of `NaN` and `Inf` By setting `allow_inf` arg to `true`. --- server/src/server.jl | 4 ++-- server/test/client.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/server.jl b/server/src/server.jl index b3aded4be..33cae0d33 100644 --- a/server/src/server.jl +++ b/server/src/server.jl @@ -89,7 +89,7 @@ function wflow_bmi(s::ZMQ.Socket, handler::ModelHandler, f) response(s) else @info "Send response including output from Wflow function `$(f.fn)`" - ZMQ.send(s, JSON3.write(ret)) + ZMQ.send(s, JSON3.write(ret; allow_inf = true)) end catch e @error "Wflow function `$(f.fn)` failed" exception = (e, catch_backtrace()) @@ -151,7 +151,7 @@ function start(port::Int) while true # Wait for next request from client req = ZMQ.recv(socket) - json = JSON3.read(req) + json = JSON3.read(req; allow_inf = true) @info "Received request to run function `$(json.fn)`..." if haskey(map_structs, json.fn) diff --git a/server/test/client.jl b/server/test/client.jl index 1688af26f..06921cde2 100644 --- a/server/test/client.jl +++ b/server/test/client.jl @@ -10,7 +10,7 @@ ZMQ.connect(socket, "tcp://localhost:5555") function request(message) ZMQ.send(socket, JSON3.write(message)) - ret_value = JSON3.read(ZMQ.recv(socket), Dict) + ret_value = JSON3.read(ZMQ.recv(socket), Dict; allow_inf = true) return ret_value end From 43e43822d47dfd53cbf8f8af0a03084297d51073 Mon Sep 17 00:00:00 2001 From: Willem van Verseveld Date: Tue, 3 Dec 2024 12:28:11 +0100 Subject: [PATCH 2/3] Add small server test To test if `NaN` values are allowed. --- server/test/client.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/test/client.jl b/server/test/client.jl index 06921cde2..009a37a19 100644 --- a/server/test/client.jl +++ b/server/test/client.jl @@ -24,6 +24,12 @@ end @test request((fn = "get_time_units",)) == Dict("time_units" => "s") end +@testset "Reading and writing NaN values allowed" begin + msg = + (fn = "get_value", name = "vertical.soil.variables.vwc[1]", dest = fill(0.0, 50063)) + @test isnan(mean(request(msg)["value"])) +end + @testset "update functions" begin @test request((fn = "update_until", time = 86400.0)) == Dict("status" => "OK") @test request((fn = "get_current_time",)) == Dict("current_time" => 86400) From f860bbcf90b4639f90d0cd6bef7124e592bb01a8 Mon Sep 17 00:00:00 2001 From: Willem van Verseveld Date: Tue, 3 Dec 2024 12:43:46 +0100 Subject: [PATCH 3/3] Update changelog --- docs/changelog.qmd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.qmd b/docs/changelog.qmd index c5ad6760f..ac5903765 100644 --- a/docs/changelog.qmd +++ b/docs/changelog.qmd @@ -16,6 +16,9 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Mutating BMI model control functions (`update`, `update_until` and `finalize`) and extended mutating BMI functions (`load_state` and `save_state`) should return `nothing`. - Added downloading of testdata to Dockerfile, to ensure an image was able to build. +- Wflow ZMQ server: allow JSON reading and writing of `NaN` and `Inf` values to avoid a JSON + spec error. For example, during initialization of a wflow model, some (diagnostic) model + variables are initialized with `NaN` values. ### Changed - Removed vertical concepts `HBV` and `FLEXTopo`.