From c7a880be483cf14c2b131b4031494db3b75f46aa Mon Sep 17 00:00:00 2001 From: jjospina Date: Thu, 25 Jul 2024 09:54:10 -0600 Subject: [PATCH] ADD: GC processes to avoid large RAM footprints when building the decomposition problem. --- src/core/base.jl | 27 ++++++++++++++++++++++++++- src/core/ref_decomposition.jl | 4 ++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/core/base.jl b/src/core/base.jl index 3c38096..88db4fc 100755 --- a/src/core/base.jl +++ b/src/core/base.jl @@ -295,6 +295,9 @@ function instantiate_model_decomposition( distro_systems_separated = _separate_pmd_circuits(pmitd_data["it"][_PMD.pmd_it_name]; multinetwork=multinetwork) pmitd_data["it"][_PMD.pmd_it_name] = distro_systems_separated + # Force call Garbage collector to reduce RAM usage + GC.gc() + # Correct the network data and assign the respective boundary number values. correct_network_data_decomposition!(pmitd_data; multinetwork=multinetwork) @@ -329,6 +332,9 @@ function instantiate_model_decomposition( # Set master optimizer JuMP.set_optimizer(optimizer.master, _SDO.Optimizer; add_bridges = true) + # Force call Garbage collector to reduce RAM usage + GC.gc() + # Get the number of subproblems number_of_subproblems = length(pmitd_data["it"][_PMD.pmd_it_name]) @@ -347,6 +353,9 @@ function instantiate_model_decomposition( subproblems_JuMP_models = Vector{JuMP.Model}(undef, number_of_subproblems) boundary_vars_vector = Vector{Vector{Vector{JuMP.VariableRef}}}(undef, number_of_subproblems) + + # ************** 1.64GB ******************** + # Threaded loop for instantiating subproblems Threads.@threads for i in 1:1:number_of_subproblems @@ -358,6 +367,8 @@ function instantiate_model_decomposition( # add pmitd(boundary) info. to pmd ref ckts_data_vector[i][pmitd_it_name] = boundary_for_ckt + # ************** 1.65GB ******************** + # Instantiate the PMD model subproblem_instantiated = _IM.instantiate_model(ckts_data_vector[i], pmitd_type.parameters[2], @@ -367,6 +378,12 @@ function instantiate_model_decomposition( _PMD.pmd_it_sym; kwargs... ) + # ************** 3.00GB - Without refs in _ref_connect_distribution_transmission_decomposition! ******************** + + # ************** 3.58GB - With everything and GC.gc() ******************** + + # ************** 4.00GB ******************** + # Add instantiated subproblem to vector of instantiated subproblems subproblems_instantiated_models[i] = subproblem_instantiated @@ -381,6 +398,8 @@ function instantiate_model_decomposition( # Add the subproblem JuMP model into the vector of instantiated subproblems subproblems_JuMP_models[i] = subproblem_instantiated.model + # ************** 4.23GB ******************** + # Generate the boundary linking vars. (ACP, ACR, etc.) if (export_models == true) linking_vars_vector = generate_boundary_linking_vars(master_instantiated, subproblem_instantiated, boundary_number; export_models=export_models) @@ -393,6 +412,8 @@ function instantiate_model_decomposition( end + # ************** 4.46GB ******************** + # Add all instantiated subproblem models to DecompositionStruct decomposed_models.pmd = subproblems_instantiated_models @@ -646,7 +667,11 @@ function solve_model( multinetwork=multinetwork, pmitd_ref_extensions=pmitd_ref_extensions, export_models=export_models, - kwargs...) + kwargs... + ) + + # Force call Garbage collector to reduce RAM usage + GC.gc() result = run_decomposition(pmitd) diff --git a/src/core/ref_decomposition.jl b/src/core/ref_decomposition.jl index feff71a..6f167d7 100644 --- a/src/core/ref_decomposition.jl +++ b/src/core/ref_decomposition.jl @@ -162,7 +162,7 @@ Creates the boundary `refs` that integrate/connect the transmission and distribu """ function _ref_connect_transmission_distribution_decomposition!(ref::Dict{Symbol,<:Any}) - # Loops over all T-D pmitd available + # Loops over all nw available for specific pm for (nw, nw_ref) in ref[:it][:pm][:nw] # boundary info. @@ -255,7 +255,7 @@ Creates the boundary `refs` that integrate/connect the distribution system bus w """ function _ref_connect_distribution_transmission_decomposition!(ref::Dict{Symbol,<:Any}) - # Loops over all T-D pmitd available + # Loops over all nw available for specific pmd for (nw, nw_ref) in ref[:it][:pmd][:nw] # boundary info.