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

Code Duplication Throughout PowerSimulations

Open GabrielKS opened this issue 2 years ago • 15 comments

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.

GabrielKS avatar Jan 11 '24 21:01 GabrielKS

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.

GabrielKS avatar Jan 11 '24 21:01 GabrielKS

In src/network_models/powermodels_interface.jl, the two methods of powermodels_network! are nearly identical.

GabrielKS avatar Jan 16 '24 17:01 GabrielKS

Lots of duplication between the _make_system_expressions! methods of src/core/optimization_container.jl

GabrielKS avatar Jan 22 '24 17:01 GabrielKS

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

GabrielKS avatar Jan 22 '24 17:01 GabrielKS

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

GabrielKS avatar Jan 22 '24 18:01 GabrielKS

(Probably not all of these are a good first issue, but some of them are)

GabrielKS avatar Feb 21 '24 17:02 GabrielKS

Lots of duplication in core/optimization_container.jlhas_container_key, get_variable, etc. My first thought is that an approach like this could help factor out differences between the various key types.

GabrielKS avatar Mar 08 '24 21:03 GabrielKS

Duplicate block starting https://github.com/NREL-Sienna/PowerSimulations.jl/blob/757b45cbe25f0645108a24310d3d26a10aae6531/test/test_services_constructor.jl#L31

GabrielKS avatar Mar 09 '24 00:03 GabrielKS

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.

GabrielKS avatar Mar 11 '24 23:03 GabrielKS

Same thing at https://github.com/NREL-Sienna/PowerSimulations.jl/blob/ff8d9ffca3c8b44e6a1988b08034a96ca5f535ad/src/simulation/simulation_results.jl#L327

GabrielKS avatar Mar 12 '24 00:03 GabrielKS

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

GabrielKS avatar Mar 13 '24 22:03 GabrielKS

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

GabrielKS avatar Mar 13 '24 23:03 GabrielKS