|
| 1 | +# Model traits |
| 2 | + |
| 3 | +This page centralizes the model-level traits that can be defined in `PlantSimEngine`. |
| 4 | +It complements: |
| 5 | + |
| 6 | +- [Model execution](model_execution.md) for runtime behavior, |
| 7 | +- [Parallelization](step_by_step/parallelization.md) for execution over objects/time-steps. |
| 8 | + |
| 9 | +## Trait inventory for models |
| 10 | + |
| 11 | +### `timespec(::Type{<:MyModel})` |
| 12 | + |
| 13 | +Defines the default execution clock of a model. |
| 14 | + |
| 15 | +Default: |
| 16 | + |
| 17 | +```julia |
| 18 | +PlantSimEngine.timespec(::Type{<:AbstractModel}) = ClockSpec(1.0, 0.0) |
| 19 | +``` |
| 20 | + |
| 21 | +Use it when your model has a natural native clock (for example daily by default). |
| 22 | + |
| 23 | +### `output_policy(::Type{<:MyModel})` |
| 24 | + |
| 25 | +Defines per-output default schedule policy for produced streams. |
| 26 | + |
| 27 | +Default: |
| 28 | + |
| 29 | +```julia |
| 30 | +PlantSimEngine.output_policy(::Type{<:AbstractModel}) = NamedTuple() |
| 31 | +``` |
| 32 | + |
| 33 | +Behavior: |
| 34 | + |
| 35 | +- unspecified outputs fall back to `HoldLast()`; |
| 36 | +- used by runtime when resolving cross-clock reads; |
| 37 | +- used as default policy for inferred `InputBindings(...)` when users do not provide explicit bindings. |
| 38 | + |
| 39 | +Example: |
| 40 | + |
| 41 | +```julia |
| 42 | +PlantSimEngine.output_policy(::Type{<:MyModel}) = ( |
| 43 | + carbon_assimilation=Integrate(), |
| 44 | + leaf_temperature=Aggregate(MeanReducer()), |
| 45 | +) |
| 46 | +``` |
| 47 | + |
| 48 | +### `timestep_hint(::Type{<:MyModel})` |
| 49 | + |
| 50 | +Optional compatibility hint when `TimeStepModel(...)` is not provided. |
| 51 | + |
| 52 | +Default: |
| 53 | + |
| 54 | +```julia |
| 55 | +PlantSimEngine.timestep_hint(::Type{<:AbstractModel}) = nothing |
| 56 | +``` |
| 57 | + |
| 58 | +Supported forms include: |
| 59 | + |
| 60 | +- fixed period: `Dates.Hour(1)`; |
| 61 | +- range: `(Dates.Minute(30), Dates.Hour(2))`; |
| 62 | +- named tuple: `(; required=..., preferred=...)`. |
| 63 | + |
| 64 | +`required` is enforced when runtime uses meteo-derived timestep. |
| 65 | +`preferred` is informational only. |
| 66 | + |
| 67 | +### `meteo_hint(::Type{<:MyModel})` |
| 68 | + |
| 69 | +Optional inference trait for weather sampling configuration. |
| 70 | + |
| 71 | +Default: |
| 72 | + |
| 73 | +```julia |
| 74 | +PlantSimEngine.meteo_hint(::Type{<:AbstractModel}) = nothing |
| 75 | +``` |
| 76 | + |
| 77 | +Expected value: |
| 78 | + |
| 79 | +```julia |
| 80 | +(; bindings=..., window=...) |
| 81 | +``` |
| 82 | + |
| 83 | +Where: |
| 84 | + |
| 85 | +- `bindings` is compatible with `MeteoBindings(...)`, |
| 86 | +- `window` is compatible with `MeteoWindow(...)`. |
| 87 | + |
| 88 | +### `TimeStepDependencyTrait(::Type{<:MyModel})` |
| 89 | +### `ObjectDependencyTrait(::Type{<:MyModel})` |
| 90 | + |
| 91 | +Parallelization traits (single-scale runtime): |
| 92 | + |
| 93 | +- `TimeStepDependencyTrait`: depends or not on other timesteps; |
| 94 | +- `ObjectDependencyTrait`: depends or not on other objects. |
| 95 | + |
| 96 | +Defaults are conservative (`dependent`) and can be overridden when safe. |
| 97 | + |
| 98 | +## Precedence rules |
| 99 | + |
| 100 | +Runtime precedence is intentionally explicit: |
| 101 | + |
| 102 | +1. Input policy: |
| 103 | + explicit `InputBindings(..., policy=...)` > inferred from producer `output_policy` > `HoldLast()`. |
| 104 | +1. Timestep: |
| 105 | + `TimeStepModel(...)` > `timespec(model)` when non-default > meteo base step. |
| 106 | +1. Meteo sampling: |
| 107 | + explicit `MeteoBindings(...)`/`MeteoWindow(...)` > `meteo_hint(...)` > runtime defaults. |
| 108 | + |
| 109 | +## Is everything documented? |
| 110 | + |
| 111 | +For model-level traits, the documented set is now: |
| 112 | + |
| 113 | +- `timespec`, |
| 114 | +- `output_policy`, |
| 115 | +- `timestep_hint`, |
| 116 | +- `meteo_hint`, |
| 117 | +- `TimeStepDependencyTrait`, |
| 118 | +- `ObjectDependencyTrait`. |
| 119 | + |
| 120 | +Outside model traits, `PlantSimEngine` also exposes data-format traits such as `DataFormat` for input containers (see [Input types](working_with_data/inputs.md)). |
| 121 | + |
| 122 | +## Naming conventions and API consistency |
| 123 | + |
| 124 | +Current API uses two naming styles on purpose: |
| 125 | + |
| 126 | +- snake_case for trait/query functions (`timespec`, `output_policy`, `timestep_hint`, `meteo_hint`); |
| 127 | +- CamelCase for `ModelSpec` pipeline transforms (`TimeStepModel`, `InputBindings`, `MeteoBindings`, `MeteoWindow`, `OutputRouting`, `ScopeModel`). |
| 128 | + |
| 129 | +This distinction reflects role: |
| 130 | + |
| 131 | +- snake_case: "what the model declares"; |
| 132 | +- CamelCase: "what the mapping config applies". |
| 133 | + |
| 134 | +For future unification, a non-breaking path would be: |
| 135 | + |
| 136 | +1. keep existing names as stable API, |
| 137 | +1. avoid plain snake_case aliases that would collide with existing getter names |
| 138 | + (`input_bindings`, `meteo_bindings`, `output_routing`, `model_scope`), |
| 139 | +1. if needed, add explicit config-oriented aliases with distinct names |
| 140 | + (for example `*_config` forms) and keep current constructors, |
| 141 | +1. evaluate deprecations only after one full release cycle and user feedback. |
0 commit comments