Skip to content

Commit b239fc0

Browse files
committed
tests(results): enforce deterministic group ordering by sorting group iterations across entropy pipeline
1 parent 66ea8ac commit b239fc0

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

CodeEntropy/entropy/nodes/configurational.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run(self, shared_data: MutableMapping[str, Any], **_: Any) -> dict[str, Any]
5353
fragments = universe.atoms.fragments
5454
results: dict[int, dict[str, float]] = {}
5555

56-
for group_id, mol_ids in groups.items():
56+
for group_id, mol_ids in sorted(groups.items()):
5757
results[group_id] = {"ua": 0.0, "res": 0.0, "poly": 0.0}
5858
if not mol_ids:
5959
continue

CodeEntropy/entropy/nodes/orientational.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def run(self, shared_data: MutableMapping[str, Any], **_: Any) -> dict[str, Any]
5252

5353
results: dict[int, float] = {}
5454

55-
for group_id, mol_ids in groups.items():
55+
for group_id, mol_ids in sorted(groups.items()):
5656
results[group_id] = 0
5757
if not mol_ids:
5858
continue

CodeEntropy/entropy/nodes/vibrational.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run(self, shared_data: MutableMapping[str, Any], **_: Any) -> dict[str, Any]
9090

9191
results: dict[int, dict[str, dict[str, float]]] = {}
9292

93-
for group_id, mol_ids in groups.items():
93+
for group_id, mol_ids in sorted(groups.items()):
9494
results[group_id] = {}
9595
if not mol_ids:
9696
continue
@@ -198,7 +198,7 @@ def _get_group_id_to_index(self, shared_data: Mapping[str, Any]) -> dict[int, in
198198
if isinstance(gid2i, dict) and gid2i:
199199
return gid2i
200200
groups = shared_data["groups"]
201-
return {gid: i for i, gid in enumerate(groups.keys())}
201+
return {gid: i for i, gid in enumerate(sorted(groups.keys()))}
202202

203203
def _get_ua_frame_counts(self, shared_data: Mapping[str, Any]) -> dict[CovKey, int]:
204204
"""Extract per-(group,residue) frame counts for united-atom covariances.

CodeEntropy/entropy/workflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ def _split_water_groups(
293293

294294
water_groups = {
295295
gid: mol_ids
296-
for gid, mol_ids in groups.items()
296+
for gid, mol_ids in sorted(groups.items())
297297
if any(
298298
res.resid in water_resids
299299
for mol in [universe.atoms.fragments[i] for i in mol_ids]
300300
for res in mol.residues
301301
)
302302
}
303303
nonwater_groups = {
304-
gid: g for gid, g in groups.items() if gid not in water_groups
304+
gid: g for gid, g in sorted(groups.items()) if gid not in water_groups
305305
}
306306
return nonwater_groups, water_groups
307307

@@ -354,7 +354,7 @@ def _finalize_molecule_results(self) -> None:
354354
except (TypeError, ValueError):
355355
logger.warning("Skipping invalid entry: %s, %s", group_id, result)
356356

357-
for group_id, total in entropy_by_group.items():
357+
for group_id, total in sorted(entropy_by_group.items()):
358358
self._reporter.molecule_data.append(
359359
(group_id, "Group Total", "Group Total Entropy", total)
360360
)

CodeEntropy/levels/nodes/covariance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def run(self, ctx: FrameCtx) -> dict[str, Any]:
9393
res_molcount: dict[int, int] = {}
9494
poly_molcount: dict[int, int] = {}
9595

96-
for group_id, mol_ids in groups.items():
96+
for group_id, mol_ids in sorted(groups.items()):
9797
for mol_id in mol_ids:
9898
mol = fragments[mol_id]
9999
level_list = levels[mol_id]

0 commit comments

Comments
 (0)