Skip to content

Commit

Permalink
ADD: GC processes to avoid large RAM footprints when building the dec…
Browse files Browse the repository at this point in the history
…omposition problem.
  • Loading branch information
juanjospina committed Jul 25, 2024
1 parent 3344959 commit c7a880b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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])

Expand All @@ -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

Expand All @@ -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],
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -393,6 +412,8 @@ function instantiate_model_decomposition(

end

# ************** 4.46GB ********************

# Add all instantiated subproblem models to DecompositionStruct
decomposed_models.pmd = subproblems_instantiated_models

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/core/ref_decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c7a880b

Please sign in to comment.