Code Duplication Throughout PowerSimulations
This is an issue to track instances of code duplication in PowerSimulations.jl that aren't new and aren't a top priority but should be fixed at some point.
In https://github.com/NREL-Sienna/PowerSimulations.jl/blob/main/src/devices_models/devices/common/add_to_expression.jl, there is a lot of duplication between methods of add_to_expression!, making it tedious to implement systematic changes like https://github.com/NREL-Sienna/PowerSimulations.jl/pull/1033/files#diff-f58cd1b5ce8435e93d2afbd31851717b14b829c25d93383227b2d2a5063e7e8bR365.
In src/network_models/powermodels_interface.jl, the two methods of powermodels_network! are nearly identical.
Lots of duplication between the _make_system_expressions! methods of src/core/optimization_container.jl
The two branch_rate_bounds! methods in https://github.com/NREL-Sienna/PowerSimulations.jl/blob/d2ba9484cb2ba62d96da79906224c4f85e8904bd/src/devices_models/devices/AC_branches.jl#L103
are nearly identical
The add_constraints! method at https://github.com/NREL-Sienna/PowerSimulations.jl/blob/d2ba9484cb2ba62d96da79906224c4f85e8904bd/src/devices_models/devices/AC_branches.jl#L269 and the one right after it are nearly identical
(Probably not all of these are a good first issue, but some of them are)
Lots of duplication in core/optimization_container.jl — has_container_key, get_variable, etc. My first thought is that an approach like this could help factor out differences between the various key types.
Duplicate block starting https://github.com/NREL-Sienna/PowerSimulations.jl/blob/757b45cbe25f0645108a24310d3d26a10aae6531/test/test_services_constructor.jl#L31
The various write_model_*_results! functions in store_common.jl. This speaks to a trend of code duplication across [variables, expressions, duals, etc.] — even if we hold that it's necessary to have separate functions in the public interface for each of these, we don't need nearly as much duplication in the underlying implementations.
Same thing at https://github.com/NREL-Sienna/PowerSimulations.jl/blob/ff8d9ffca3c8b44e6a1988b08034a96ca5f535ad/src/simulation/simulation_results.jl#L327
https://github.com/NREL-Sienna/PowerSimulations.jl/blob/03f72e0dc9304961a05c3bc2e9666d4706f064e8/test/test_network_constructors.jl#L370 just twice but still, got an error caused by find-and-replace that implies this shouldn't be duplicated
The two methods of get_time_series_values! at
https://github.com/NREL-Sienna/PowerSimulations.jl/blob/03f72e0dc9304961a05c3bc2e9666d4706f064e8/src/operation/time_series_interface.jl#L1
are nearly identical