Preserve Pose bitwise representation when accessing Pose.cache SimpleMetrics data #595
+74
−7
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.
This PR aims to make a minor change to the
Pose.cacheinfrastructure.Currently, accessing SimpleMetrics data in the
Pose.cachedictionary via theget_sm_datamethod lazily initializes aSimpleMetricDataentry in thePose.datacache. If aPosedoes not already contain SimpleMetrics data, then merely accessing this getter method bitwise mutates thePose(albeit harmlessly, since it only instantiates an empty container). However, in principle, a getter ought not to modify the underlying state or binary representation of thePose.Herein, we instead conditionally check for
Pose.data().has(CacheableDataType.SIMPLE_METRIC_DATA), performing the same test at the PyRosetta layer that theget_sm_datamethod performs at the C++ interface. IfFalse, then we return an empty dictionary without lazily initializing aSimpleMetricDataentry in thePose.datacache. This minor update enables deterministic behavior when instantiatingPackedPoseobjects, during which thePose.cachedictionary is accessed to define thePackedPose.scoresattribute. By preventing lazy initialization of the SimpleMetrics data cache, the new behavior is consistent regardless of whether inputPoseobjects contain SimpleMetrics data. Unit tests are also added herein to ensure consistency of the underlying bitwise representations ofPoseobjects with and without SimpleMetrics data.