NREL-Sienna / PowerSystems.jl

Data structures in Julia to enable power systems analysis. Part of the Scalable Integrated Infrastructure Planning Initiative at the National Renewable Energy Lab.
https://nrel-sienna.github.io/PowerSystems.jl/stable/
BSD 3-Clause "New" or "Revised" License
314 stars 79 forks source link

Document behavior of some function cases #781

Open jd-lara opened 3 years ago

jd-lara commented 3 years ago

I recently saw this pattern in a package using PowerSystems.

gens = deepcopy([g for g in get_components(ThermalStandard, sys)])

What happens with gens?

daniel-thom commented 3 years ago

This is certainly not a good idea unless the user understands the internals. If the generators are not attached to a system then they need to change the name and change the UUID (set_name! and IS.assign_new_uuid!). If they are attached to a system then many things will not work correctly. The user will never be able to retrieve the copied generators from the system.

We should add code to ensure that duplicate UUIDs are never added to a system. We currently only check for duplicate names. We would have to add new tracking.

Based on the implementation of Base.deepcopy It might be possible to block the function if the component is attached to a system.