Skip to content

Commit a626fea

Browse files
zcabaalcanyon289
andauthored
Fix bug causing the group order of Approximations to be non-determinstics
Co-authored-by: Ravin Kumar <[email protected]>
1 parent 0fc84ad commit a626fea

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pymc/variational/opvi.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,11 +1337,13 @@ def __init__(self, groups, model=None):
13371337
raise GroupError("Found duplicates in groups")
13381338
seen.update(g.group)
13391339
self.groups.append(g)
1340-
if set(model.free_RVs) - seen:
1340+
# List iteration to preserve order for reproducibility between runs
1341+
unseen_free_RVs = [var for var in model.free_RVs if var not in seen]
1342+
if unseen_free_RVs:
13411343
if rest is None:
13421344
raise GroupError("No approximation is specified for the rest variables")
13431345
else:
1344-
rest.__init_group__(list(set(model.free_RVs) - seen))
1346+
rest.__init_group__(unseen_free_RVs)
13451347
self.groups.append(rest)
13461348
self.model = model
13471349

0 commit comments

Comments
 (0)