PowerSystems.jl icon indicating copy to clipboard operation
PowerSystems.jl copied to clipboard

Document behavior of some function cases

Open jd-lara opened this issue 3 years ago • 1 comments

I recently saw this pattern in a package using PowerSystems.

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

What happens with gens?

jd-lara avatar Jul 19 '21 17:07 jd-lara

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.

daniel-thom avatar Jul 19 '21 19:07 daniel-thom