Based of UM-Bridge/UMBridge.jl#25
Problem:
It is possible that models run with given inputs (numbers) and evaluate to inf, -inf or nan values (non-numbers). Based on these values, we can take a decision in the UQ algorithm.
Currently, Umbridge does not fully support this.
Solution:
Add feature to allow serializing(write) and deserializing(read) Infinity and NaN values, and provide a global mechanism (flag) to activate the feature.
Some Context:
Python Implementation
- we use here the
.json() function from the requests package.
- the
.json() function uses loads() or dumps() from complexjson package, which finally uses loads() or dumps() from the default json python package
- the
dumps() function has allow_nan argument which enables writing the Infinity or NaN values to the JSON string. The default value is True
- the
loads() function has parse_constant argument, which can allow using a function to read the Infinity or Nan values from the JSON string. The default function is however None. A solution to allow reading Infinity and NaN is here: https://stackoverflow.com/a/62685520
- TLDR, currently if we use both a python server and client, the server will write these values to the JSON string, but the client will not be able to read them.
Julia Implementation
- we use here the
.json() functin from the JSON package.
- the
.json() function uses a StandardSerializer which does not support reading/writing of Infinity and NaN values.
- this PR adds the functionality to write Infinity and NaN values. Whether it can handle reading them as well, needs to be tested
C++ Implementation (edited by @chun9l)
- There is a wrapper function here that calls
json::parse in the JSON header file.
- The JSON library does not support
NaN or Inf natively. However, their .dump() function converts NaNs into null; see here.
- Currently unclear if there exists an easy way to enable handling of these value.
Based of UM-Bridge/UMBridge.jl#25
Problem:
It is possible that models run with given inputs (numbers) and evaluate to
inf,-infornanvalues (non-numbers). Based on these values, we can take a decision in the UQ algorithm.Currently, Umbridge does not fully support this.
Solution:
Add feature to allow serializing(write) and deserializing(read) Infinity and NaN values, and provide a global mechanism (flag) to activate the feature.
Some Context:
Python Implementation
.json()function from therequestspackage..json()function usesloads()ordumps()fromcomplexjsonpackage, which finally usesloads()ordumps()from the defaultjsonpython packagedumps()function hasallow_nanargument which enables writing the Infinity or NaN values to the JSON string. The default value isTrueloads()function hasparse_constantargument, which can allow using a function to read the Infinity or Nan values from the JSON string. The default function is howeverNone. A solution to allow reading Infinity and NaN is here: https://stackoverflow.com/a/62685520Julia Implementation
.json()functin from theJSONpackage..json()function uses aStandardSerializerwhich does not support reading/writing of Infinity and NaN values.C++ Implementation (edited by @chun9l)
json::parsein the JSON header file.NaNorInfnatively. However, their.dump()function convertsNaNsintonull; see here.