Skip to content

Commit 2f6bc6e

Browse files
committed
fix(levels): reduce force and torque outputs deterministically
1 parent 2cc5c05 commit 2f6bc6e

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

CodeEntropy/levels/level_dag.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,7 @@ def _reduce_one_frame(
240240
def _reduce_force_and_torque(
241241
self, shared_data: dict[str, Any], frame_out: dict[str, Any]
242242
) -> None:
243-
"""Reduce force/torque covariance outputs into shared accumulators.
244-
245-
Args:
246-
shared_data: Shared workflow data dict containing:
247-
- "force_covariances", "torque_covariances": accumulator structures.
248-
- "frame_counts": running sample counts for each accumulator slot.
249-
- "group_id_to_index": mapping from group id to accumulator index.
250-
frame_out: Frame-local outputs containing "force" and "torque" sections.
251-
252-
Returns:
253-
None. Mutates accumulator values and counts in shared_data in-place.
254-
"""
243+
"""Reduce force/torque covariance outputs into shared accumulators."""
255244
f_cov = shared_data["force_covariances"]
256245
t_cov = shared_data["torque_covariances"]
257246
counts = shared_data["frame_counts"]
@@ -260,37 +249,43 @@ def _reduce_force_and_torque(
260249
f_frame = frame_out["force"]
261250
t_frame = frame_out["torque"]
262251

263-
for key, F in f_frame["ua"].items():
252+
for key in sorted(f_frame["ua"].keys()):
253+
F = f_frame["ua"][key]
264254
counts["ua"][key] = counts["ua"].get(key, 0) + 1
265255
n = counts["ua"][key]
266256
f_cov["ua"][key] = self._incremental_mean(f_cov["ua"].get(key), F, n)
267257

268-
for key, T in t_frame["ua"].items():
258+
for key in sorted(t_frame["ua"].keys()):
259+
T = t_frame["ua"][key]
269260
if key not in counts["ua"]:
270261
counts["ua"][key] = counts["ua"].get(key, 0) + 1
271262
n = counts["ua"][key]
272263
t_cov["ua"][key] = self._incremental_mean(t_cov["ua"].get(key), T, n)
273264

274-
for gid, F in f_frame["res"].items():
265+
for gid in sorted(f_frame["res"].keys()):
266+
F = f_frame["res"][gid]
275267
gi = gid2i[gid]
276268
counts["res"][gi] += 1
277269
n = counts["res"][gi]
278270
f_cov["res"][gi] = self._incremental_mean(f_cov["res"][gi], F, n)
279271

280-
for gid, T in t_frame["res"].items():
272+
for gid in sorted(t_frame["res"].keys()):
273+
T = t_frame["res"][gid]
281274
gi = gid2i[gid]
282275
if counts["res"][gi] == 0:
283276
counts["res"][gi] += 1
284277
n = counts["res"][gi]
285278
t_cov["res"][gi] = self._incremental_mean(t_cov["res"][gi], T, n)
286279

287-
for gid, F in f_frame["poly"].items():
280+
for gid in sorted(f_frame["poly"].keys()):
281+
F = f_frame["poly"][gid]
288282
gi = gid2i[gid]
289283
counts["poly"][gi] += 1
290284
n = counts["poly"][gi]
291285
f_cov["poly"][gi] = self._incremental_mean(f_cov["poly"][gi], F, n)
292286

293-
for gid, T in t_frame["poly"].items():
287+
for gid in sorted(t_frame["poly"].keys()):
288+
T = t_frame["poly"][gid]
294289
gi = gid2i[gid]
295290
if counts["poly"][gi] == 0:
296291
counts["poly"][gi] += 1

0 commit comments

Comments
 (0)