Exporting a model definition
Recipes record model construction inputs for export and replay.
using Agate.Construction: export_recipe, import_recipe
using Onyx
using OceanBioME: BoxModelGrid
Construct and save
construct_plus_recipe() returns the model together with the authored scientific recipe. The recipe can be exported to JSON and later reloaded to reconstruct the model.
grid = BoxModelGrid()
bgc, recipe = Onyx.construct_plus_recipe(;
grid,
size_structure=(;
phytoplankton=(P=(n=3, min_esd=1.0, max_esd=10.0, spacing=:log),),
zooplankton=(Z=(n=2, min_esd=20.0, max_esd=100.0, spacing=:linear),),
),
)
recipe_path = tempname() * ".json"
export_recipe(recipe_path, recipe)"/tmp/jl_aHCnIVC9iJ.json"The JSON records the model configuration and its SHA-256 content fingerprint. Preserve the Julia Project.toml and Manifest.toml separately for reproducible execution.
println("Wrote model recipe to ", recipe_path)
Wrote model recipe to /tmp/jl_aHCnIVC9iJ.json
Reload and replay
Runtime choices such as the grid are supplied again when the recipe is replayed.
loaded = import_recipe(recipe_path)
replayed = Onyx.construct(loaded; grid)
println("Recipe preserved: ", loaded == recipe)
println("Parameters preserved: ", replayed.parameters == bgc.parameters)
Recipe preserved: true
Parameters preserved: true
This page was generated using Literate.jl.