HELICS icon indicating copy to clipboard operation
HELICS copied to clipboard

Translators imprecisely convert string to float

Open trevorhardy opened this issue 1 year ago • 2 comments

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)

trevorhardy avatar Oct 16 '24 16:10 trevorhardy

Are you complaining about an error 1*10^-16? I want to know an application where that matters?

phlptp avatar Oct 16 '24 16:10 phlptp

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.

trevorhardy avatar Oct 16 '24 18:10 trevorhardy

This needs to be tried again with develop, we switched the underlying json library so that might have fixed the issue

phlptp avatar Dec 06 '24 13:12 phlptp

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

trevorhardy avatar Dec 06 '24 18:12 trevorhardy

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
}

trevorhardy avatar Dec 06 '24 19:12 trevorhardy