Translators imprecisely convert string to float
Describe the bug When using the translator functionality in the example, values that are precisely represented as strings (e.g. "1.314159") have lost precision after being translated (e.g. 1.3141590000000001).
What is the expected behavior? String would convert exactly to their respective float value (at least to the first dozen or so significant figures).
To Reproduce Run the "translator_testfed_next_time.json" runner file in the translator example folder.
Environment (please complete the following information):
- Operating System: macOS
- Language Extension: Python
- what compiler or setup process did you use: build develop from source just prior to the 3.6 release
- HELICS version: helics version v3.5.3, Python HELICS version v3.5.3, HELICS Library version 3.5.3 (2024-07-08)
Are you complaining about an error 1*10^-16? I want to know an application where that matters?
My concern is that, particularly for people like me who don't always understand the details under the hood, the imprecision looks like a mistake. It reduces trust in the operation and will raise questions.
This needs to be tried again with develop, we switched the underlying json library so that might have fixed the issue
Doesn't appear to have fixed the issue; there's still a mis-match between the printed representation of the sent values and the received values after translation.
sender.log
Granted time: 1.0
DEBUG:__main__:Granted time: 1.0
published value 1.314159 as a double
DEBUG:__main__: published value 1.314159 as a double
Granted time: 2.0
DEBUG:__main__:Granted time: 2.0
published value 2.314159 as a double
DEBUG:__main__: published value 2.314159 as a double
Granted time: 3.0
DEBUG:__main__:Granted time: 3.0
published value 3.314159 as a double
DEBUG:__main__: published value 3.314159 as a double
receiver.log
Requested time: 1
DEBUG:__main__:Requested time: 1
Granted time: 1.0
DEBUG:__main__:Granted time: 1.0
Requested time: 2
DEBUG:__main__:Requested time: 2
Granted time: 1.000000001
DEBUG:__main__:Granted time: 1.000000001
message sent at 1.000000001
DEBUG:__main__: message sent at 1.000000001
translated value: {
"type" : "double",
"value" : 1.3141590000000001
}
DEBUG:__main__: translated value: {
"type" : "double",
"value" : 1.3141590000000001
}
Requested time: 2
DEBUG:__main__:Requested time: 2
Granted time: 2.0
DEBUG:__main__:Granted time: 2.0
Requested time: 3
DEBUG:__main__:Requested time: 3
Granted time: 2.000000001
DEBUG:__main__:Granted time: 2.000000001
message sent at 2.000000001
DEBUG:__main__: message sent at 2.000000001
translated value: {
"type" : "double",
"value" : 2.3141590000000001
}
DEBUG:__main__: translated value: {
"type" : "double",
"value" : 2.3141590000000001
}
Requested time: 3
DEBUG:__main__:Requested time: 3
Granted time: 3.0
DEBUG:__main__:Granted time: 3.0
Requested time: 4
DEBUG:__main__:Requested time: 4
Granted time: 3.000000001
DEBUG:__main__:Granted time: 3.000000001
message sent at 3.000000001
DEBUG:__main__: message sent at 3.000000001
translated value: {
"type" : "double",
"value" : 3.3141590000000001
}
DEBUG:__main__: translated value: {
"type" : "double",
"value" : 3.3141590000000001
}
Requested time: 4
My above comment was mistakenly run using an older version of the library where the fix was not in place. Using a locally built 3.6.0 library from develop showed the sent and received value representations were identical.
sender.log
Granted time: 1.0
DEBUG:__main__:Granted time: 1.0
published value 1.314159 as a double
DEBUG:__main__: published value 1.314159 as a double
Granted time: 2.0
DEBUG:__main__:Granted time: 2.0
published value 2.314159 as a double
DEBUG:__main__: published value 2.314159 as a double
Granted time: 3.0
DEBUG:__main__:Granted time: 3.0
published value 3.314159 as a double
DEBUG:__main__: published value 3.314159 as a double
receiver.log
Requested time: 1
DEBUG:__main__:Requested time: 1
Granted time: 1.0
DEBUG:__main__:Granted time: 1.0
Requested time: 2
DEBUG:__main__:Requested time: 2
Granted time: 1.000000001
DEBUG:__main__:Granted time: 1.000000001
message sent at 1.000000001
DEBUG:__main__: message sent at 1.000000001
translated value: {
"type": "double",
"value": 1.314159
}
DEBUG:__main__: translated value: {
"type": "double",
"value": 1.314159
}
Requested time: 2
DEBUG:__main__:Requested time: 2
Granted time: 2.0
DEBUG:__main__:Granted time: 2.0
Requested time: 3
DEBUG:__main__:Requested time: 3
Granted time: 2.000000001
DEBUG:__main__:Granted time: 2.000000001
message sent at 2.000000001
DEBUG:__main__: message sent at 2.000000001
translated value: {
"type": "double",
"value": 2.314159
}
DEBUG:__main__: translated value: {
"type": "double",
"value": 2.314159
}
Requested time: 3
DEBUG:__main__:Requested time: 3
Granted time: 3.0
DEBUG:__main__:Granted time: 3.0
Requested time: 4
DEBUG:__main__:Requested time: 4
Granted time: 3.000000001
DEBUG:__main__:Granted time: 3.000000001
message sent at 3.000000001
DEBUG:__main__: message sent at 3.000000001
translated value: {
"type": "double",
"value": 3.314159
}
DEBUG:__main__: translated value: {
"type": "double",
"value": 3.314159
}