bloer/bgexplorer

Cloning specs creates multiple subspecs with the same id

SimonHarms opened this issue · 0 comments

If you clone a specification with some subspecs defined the subspecs in the clone will have the same ids as the original subspec. This leads to multiple subspecs in different specifications having the same id which can cause strange behaviour.

In this test I created a radiogenic specification called "Test1", gave it a U238 subspec and then cloned it naming the clone "Test2". I then added a Th232 subspec to each specification manually. Included is a screenshot of the specs in mongosh, note that the U238 subspecs have the same id while the Th232 subspecs have different ids.

Screenshot 2023-09-28 at 6 51 48 PM

Having multiple subspecs have the same id can cause normalization to get messed up. In this model (http://206.12.97.188:5000/explore/CUTE%20Tower/19.0/component/mCJLwVHA9J7rcd2JikUQWQ) there is a specification on this component called "Inner Housing Dust" which has a U238 subspecification defined. The simulation data however is normalized according to a U238 subspec of a different specification called "Shield Dust Out" which isn't even attached to this component. "Shield Dust Out" was created by cloning "Inner Housing Dust" and changing the decay rates to match the different dust estimate. Since it's cloned the subspecs have the same id and the subspec of "Shield Dust Out" is taking precedence, leading to the wrong decay rate and improper normalization.

This can be fixed on the user level by just remaking the subspecs of each specification that's a clone of another specification. In order to fix this in bgexplorer I believe this section of code likely needs to be changed: https://github.com/bloer/bgexplorer/blob/master/bgexplorer/modeleditor/modeleditor.py#L332. Just adding deep=True to clone on its own doesn't fix the issue (though I think it's required, otherwise the subspecs in the cloned spec are just references to the original subspecs), we also need to iterate over the subspecs in the cloned spec and give them new UUIDs.