From fa77fcedc75548e92f8336c043474c49c59e53f1 Mon Sep 17 00:00:00 2001 From: Stuart Daines Date: Thu, 31 Aug 2023 10:24:36 +0100 Subject: [PATCH] Simplify and fix precompile @PrecompileTools.compile_workload run_model was failing, and error was concealed by use of Logging.NullLogger() With fixes in PALEOboxes v0.21.18 precompile now works and ~halves startup time (49s -> 27s for COPSE_reloaded, testing on Julia 1.10.0-beta2) --- Project.toml | 2 +- src/PALEOcopse.jl | 31 +++++++++++-------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Project.toml b/Project.toml index b944b9c..8b1d5c0 100644 --- a/Project.toml +++ b/Project.toml @@ -21,7 +21,7 @@ Documenter = "0.27" Infiltrator = "1.0" Interpolations = "0.13, 0.14" MAT = "0.10" -PALEOboxes = "0.20.4, 0.21" +PALEOboxes = "0.21.18" PALEOmodel = "0.15.8" PrecompileTools = "1.0" Plots = "1.0" diff --git a/src/PALEOcopse.jl b/src/PALEOcopse.jl index 6bc686d..5fb133d 100644 --- a/src/PALEOcopse.jl +++ b/src/PALEOcopse.jl @@ -20,7 +20,7 @@ include("sedcrust/SedCrust.jl") include("biogeochem/BioGeoChem.jl") -# TODO gains here with Julia 1.9.0-rc3, PrecompileTools v1.0.3 are marginal (95sec -> 82sec for include("COPSE_reloaded_reloaded.jl")) +# gains from precompilation with Julia 1.10.0-beta2, PrecompileTools v1.2.0 are 48sec -> 27sec for include("COPSE_reloaded_reloaded.jl")) if VERSION >= v"1.8.0" # negligible benefit from precompile prior to Julia 1.8.0 @PrecompileTools.setup_workload begin # create Reactions and register methods to precompile this code @@ -28,30 +28,21 @@ if VERSION >= v"1.8.0" # negligible benefit from precompile prior to Julia 1.8.0 # Putting some things in `setup` can reduce the size of the # precompile file and potentially make loading faster. - - rdict = PB.find_all_reactions() - reactionlist = ["ReactionSrSed", "ReactionLandWeatheringFluxes", "ReactionSrLand", "ReactionLandArea", "ReactionForce_LIPs", - "ReactionForce_CK_Solar", "ReactionLandWeatheringRates", "ReactionModelBergman2004", - "ReactionCIsotopes", "ReactionMarineBiotaCOPSE", "ReactionOceanBurialCOPSE", "ReactionAtmOcean_A", "ReactionSedCrustCOPSE", "ReactionGlobalTemperatureBerner", - "ReactionSrOceanfloor", "ReactionForce_CPlandrelbergman2004", "ReactionForce_UDWEbergman2004", "ReactionSeafloorWeathering", - "ReactionSrMantleCrust", "ReactionLandBergman2004", "ReactionAtmOcean_O", "ReactionForce_spreadsheet", - "ReactionGlobalTemperatureCK1992", "ReactionLandBiota", "ReactionForce_Bbergman2004", + configlist = [ + (joinpath(@__DIR__, "../examples/COPSE/COPSE_bergman2004_bergman2004_cfg.yaml"), "Bergman2004"), + (joinpath(@__DIR__, "../examples/COPSE/COPSE_reloaded_bergman2004_cfg.yaml"), "model1"), + (joinpath(@__DIR__, "../examples/COPSE/COPSE_reloaded_reloaded_cfg.yaml"), "model1"), ] - @PrecompileTools.compile_workload begin # all calls in this block will be precompiled, regardless of whether # they belong to your package or not (on Julia 1.8 and higher) - - Logging.with_logger(Logging.NullLogger()) do - for r in reactionlist - PB.precompile_reaction(rdict, r) - end - - # - PB.run_model(joinpath(@__DIR__, "../examples/COPSE/COPSE_bergman2004_bergman2004_cfg.yaml"), "Bergman2004") - PB.run_model(joinpath(@__DIR__, "../examples/COPSE/COPSE_reloaded_bergman2004_cfg.yaml"), "model1") - PB.run_model(joinpath(@__DIR__, "../examples/COPSE/COPSE_reloaded_reloaded_cfg.yaml"), "model1") + logger=Logging.NullLogger() + # logger=Logging.ConsoleLogger() + + for (config_file, config_model) in configlist + PB.run_model(config_file, config_model; call_do_deriv=true, logger) end + end end end