open-AIMS / ADRIA.jl

ADRIA: Adaptive Dynamic Reef Intervention Algorithms. A multi-criteria decision support platform for informing reef restoration and adaptation interventions.
MIT License
14 stars 5 forks source link

Improvements to model performance by reducing allocations #871

Open ConnectedSystems opened 1 day ago

ConnectedSystems commented 1 day ago

A swathe of changes to the simulations to improve runtime performance, principally by reducing the volume of allocations.

Includes purpose-specific weighted sum function for use when determining DHW tolerance thresholds.

Before: image

After: image

Error between approaches: image

using Revise, Infiltrator

using ADRIA

using Statistics
using Serialization

RME_DOM = "C:/Users/tiwanaga/development/RME/rme_ml_2024_01_08"
gbr_dom = ADRIA.load_domain(RMEDomain, RME_DOM, "45")

global debug_c = 1
scen = ADRIA.param_table(gbr_dom)
rs = ADRIA.run_model(gbr_dom, scen[1, :]);

cover = dropdims(sum(rs.raw, dims=2), dims=2)
# serialize("cover_optimized.dat", cover)
# serialize("cover_unoptimized.dat", cover)

Error calculation was determined by serializing raw results to disk and then comparing the absolute maximum difference:


# Comparison

cover_opt = deserialize("cover_optimized.dat")
cover_unopt = deserialize("cover_unoptimized.dat")

maximum(abs.(cover_opt .- cover_unopt))

There are further performance optimizations potentially possible within CoralBlox and elsewhere in ADRIA, but seems to be mostly around determining strategies to avoid the GC.

We could even see if it is possible to make key functions completely allocation free and turning off the GC for those...

Update:

After some more tweaks

image