PALEOtoolkit / PALEOboxes.jl

Model coupler for the PALEO model framework
https://PALEOtoolkit.github.io/PALEOboxes.jl
MIT License
2 stars 1 forks source link

Programmatic API as well as / instead of YAML config file ? #7

Open sjdaines opened 2 years ago

sjdaines commented 2 years ago

Overall goal is to make use of PALEO follow best practices in the Julia ecosystem (see eg https://discourse.julialang.org/t/julia-stats-data-ml-expanding-usability/67948 https://docs.google.com/presentation/d/1deIp582Ommw2wQtI1EQaR3lNy8LSLOA2c0FYjKKR-Bo/edit#slide=id.p1 )

This could be straightforward: really just need to define some add methods, with careful attention to syntax to produce code that reads like a config file, eg:

domain_global = add!(model, Domain("global"))

add!(
    domain_global,
    "myreaction" => SomeReactionType(
        pars=(
            a:=1,
            b:=2
        ),
        variable_links=(
            "varname" => "varnewname"
        ),
        variable_attributes=(
            "varname:initial_value" => 42
        ),
    ),
)

etc
sjdaines commented 1 year ago

another attempt at an example syntax (see eg https://github.com/ordovician/QtUIParser.jl/blob/master/examples/color-selector.jl for inspiration):

function create_model(external_parameters)
    model = Model(
        parameters = external_parameters,
        domains = [
              :ocean => Domain(
                  reactions = [
                      "reservoir_A" => ReactionReservoir(
                           parameters = [
                               :isotope_type=>PB.IsotopeLinear,
                           ],
                          variable_links = [
                                "R*"=>"A*",
                          ],
                          variable_attributes = [
                              ("R", :initial_value) => 32.0,
                          ],
                      ),
                  ], # reactions
              ), # Domain
          ], # domains
     )  # model

     return model
end

NB: this will need a macro to write Reaction constructors, see eg https://discourse.julialang.org/t/writing-this-inner-constructor-with-a-macro/62945