You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes when cloning a simulation, I've found that the original simulation is inexplicably affected by actions in the cloned simulation. I've seen this for a while but have been unable to generate a MWE, but yesterday I think I found the issue, in this line. When a group population is cloned, it looks like the clone still has access to the original members, which is unchanged.
Reacted by Mahdi Ben Jelloul, pdp, Mauko Quiroga-Alvarado and Thomas Guillet
@benjello at first I thought this was a duplicate of #848 , yet reading both issues, it appears like the behaviour described here is intended. Do you confirm?
Hi! I believe I found the mechanism behind this, and it turned out to be four compounding defects rather than one. @nikhilwoodruff's intuition about members was correct — the cloned group population keeps the original persons as members — but it was only part of the picture:
Holder.clone shares the holder's InMemoryStorage/OnDiskStorageby reference, so any input set, value cached or array deleted through the clone silently alters the original (and can leave it internally inconsistent: fresh input, stale cached results).
GroupPopulation.clone calls holder.clone(self) instead of holder.clone(result), so the clone's group-entity holders are bound to the original population and simulation.
The clone shares _data_storage_dir, so with a memory_config active, holders lazily created on both sides write their .npy files into the same directory — one simulation reads the other's values, and garbage-collecting either one deletes the other's files.
I have a minimal reproduction for each, and a PR with a fix and regression tests: #1385.
Activity
bonjourmauko commentedon Dec 6, 2022
Thanks @nikhilwoodruff .
@benjello at first I thought this was a duplicate of #848 , yet reading both issues, it appears like the behaviour described here is intended. Do you confirm?
benjello commentedon Dec 7, 2022
I think the behaviour expected by @nikhilwoodruff should be enforced.
Fix Simulation.clone sharing mutable state with the original
Adelagric commentedon Sep 9, 2026
Hi! I believe I found the mechanism behind this, and it turned out to be four compounding defects rather than one. @nikhilwoodruff's intuition about
memberswas correct — the cloned group population keeps the original persons asmembers— but it was only part of the picture:Holder.cloneshares the holder'sInMemoryStorage/OnDiskStorageby reference, so any input set, value cached or array deleted through the clone silently alters the original (and can leave it internally inconsistent: fresh input, stale cached results).GroupPopulation.clonecallsholder.clone(self)instead ofholder.clone(result), so the clone's group-entity holders are bound to the original population and simulation.GroupPopulation.clonereusesself.members(your observation)._data_storage_dir, so with amemory_configactive, holders lazily created on both sides write their.npyfiles into the same directory — one simulation reads the other's values, and garbage-collecting either one deletes the other's files.I have a minimal reproduction for each, and a PR with a fix and regression tests: #1385.
Fix Simulation.clone sharing mutable state with the original
Fix Simulation.clone sharing mutable state with the original
Fix Simulation.clone sharing mutable state with the original
Fix Simulation.clone sharing mutable state with the original
Fix Simulation.clone sharing mutable state with the original
Fix Simulation.clone sharing mutable state with the original
Fix Simulation.clone sharing mutable state with the original