[MLA-1879] culture-invariant sorting for sensors and actuators #5194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed change(s)
Previously, sensors and actuators were sorted using the local culture for string comparisons (i.e. using
string.CompareTo
with default arguments). A potential bug with this is that sensors would be sorted one way during training, but differently when performance inference on a different end user's system. This changes sorting to useStringComparison.InvariantCulture
, which is consistent everywhere (this was initially usingOrdinal
sorting, but that differs a lot from from the localen-US
sorting)Note that this might break existing models after upgrading if the sensor names are sorted differently. I believe that this is preferable to not making the change, since the alternative would end up causing more breakages further in the future, in a harder-to-diagnose way (i.e. after a game ships).
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
https://docs.microsoft.com/en-us/dotnet/api/system.globalization.compareoptions?view=net-5.0
https://docs.microsoft.com/en-us/globalization/locale/sorting-and-string-comparison
https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.invariantculture?view=net-5.0
Types of change(s)
Checklist
Other comments