Skip to content

Add readable and fast compiled model modes - #191

Draft
VEZY wants to merge 187 commits into
mainfrom
compile-models
Draft

Add readable and fast compiled model modes#191
VEZY wants to merge 187 commits into
mainfrom
compile-models

Conversation

@VEZY

@VEZY VEZY commented Apr 28, 2026

Copy link
Copy Markdown
Member

Summary

  • Add mode=:readable | :fast to compiled model generation and preserve Status-backed execution semantics
  • Emit clearer generated code with stable per-block locals, inputs/outputs comments, and improved source rewriting for current-model and hard-dependency references
  • Tighten MTG loop bounds for dynamic growth and keep multirate compilation parity intact
  • Expand compiler coverage for readable output, fast mode, unsupported modes, alias-based hard dependencies, and MTG/multirate regressions

Testing

  • Focused compiler test suite passes for single-scale, multiscale, multirate, and cross-scale hard-dependency cases
  • Combined regression with existing ModelMapping coverage passes
  • git diff --check passes

VEZY added 9 commits March 18, 2026 12:11
Added generated GraphSimulation compatibility validation in src/compiled_model.jl (line 68). Compiled scripts now embed a model signature and fail early if called with a different mapping/model set or wrong same-rate vs multirate mode.
Added the compatibility signature to generated script headers for inspection.
Hoisted multirate per-node setup out of the timestep loop in src/compiled_model.jl (line 338): node metadata, model, model spec, and model clock are now generated as stable locals like _mr_Leaf_carbon_assimilation_model_clock.
Kept temporal input resolution, meteo sampling, output publishing, and requested exports delegated to the existing runtime helpers.
Kept the GraphSimulation(...; type_promotion=...) constructor fix in src/mtg/GraphSimulation.jl (line 37).
Added tests for compatibility validation and multirate hoisting in test/test-compiled-model.jl (line 113).
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
main 23899a9... main / 23899a9...
bench_linux/PBP 20.5 ± 2.5 ms 20.6 ± 1.9 ms 0.995 ± 0.15
bench_linux/PBP_multiple_timesteps_MT 0.256 ± 0.05 s 0.252 ± 0.058 s 1.02 ± 0.31
bench_linux/PBP_multiple_timesteps_ST 0.229 ± 0.018 s 0.222 ± 0.022 s 1.03 ± 0.13
bench_linux/PSE 5.01 s 4.91 ± 0.096 s 1.02
bench_linux/PSE_multirate_output_request_run 7.33 s 7.28 s 1.01
bench_linux/PSE_multirate_status_tracked_run 3.84 ± 0.44 s 3.86 ± 0.45 s 0.994 ± 0.16
bench_linux/XPalm_convert_outputs 0.92 ± 0.38 s 0.986 ± 0.034 s 0.933 ± 0.38
bench_linux/XPalm_run 11.7 s 11.3 s 1.03
bench_linux/XPalm_setup 0.936 ± 0.13 s 0.935 ± 0.14 s 1 ± 0.2
time_to_load 2.07 ± 0.017 s 2.06 ± 0.015 s 1.01 ± 0.011
Memory benchmarks
main 23899a9... main / 23899a9...
bench_linux/PBP 0.12 M allocs: 7.2 MB 0.12 M allocs: 7.2 MB 1
bench_linux/PBP_multiple_timesteps_MT 3.73 M allocs: 0.237 GB 3.73 M allocs: 0.237 GB 1
bench_linux/PBP_multiple_timesteps_ST 3.58 M allocs: 0.213 GB 3.58 M allocs: 0.213 GB 1
bench_linux/PSE 0.0499 G allocs: 3.7 GB 0.0498 G allocs: 3.69 GB 1
bench_linux/PSE_multirate_output_request_run 0.0851 G allocs: 3.5 GB 0.0851 G allocs: 3.5 GB 1
bench_linux/PSE_multirate_status_tracked_run 0.0607 G allocs: 1.93 GB 0.0607 G allocs: 1.93 GB 1
bench_linux/XPalm_convert_outputs 6.62 M allocs: 0.436 GB 6.62 M allocs: 0.436 GB 1
bench_linux/XPalm_run 0.104 G allocs: 6.71 GB 0.104 G allocs: 6.68 GB 1.01
bench_linux/XPalm_setup 0.302 M allocs: 16.2 MB 0.488 M allocs: 25 MB 0.646
time_to_load 0.149 k allocs: 11.1 kB 0.149 k allocs: 11.1 kB 1

@VEZY

VEZY commented May 15, 2026

Copy link
Copy Markdown
Member Author

Comment: use https://github.com/JuliaDebug/CodeTracking.jl for a helper to retrieve code after the functions were created (in the case that the modeler didn't use the macro on the run! Method)

VEZY added 18 commits June 3, 2026 17:25
- Added `Domain`, `SimulationMapping`, and `DomainSimulation` for composing plant, soil, scene, and future environment domains.
- Added cross-domain stream/value dependencies with `AllDomains(...)` and explicit `Route(...)` materialization.
- Added hard-domain dependencies with `HardDomains(...)`, `dependency_targets(...)`, `model_target(...)`, and `run_target!(...)` so scene models can manually run plant/soil targets, including iterative workflows.
- Added MTG-backed domain support with selectors, multi-plant domains, graph-domain output publication, dynamic topology registration, organ removal, and reparenting.
- Added `Updates(:var; after=...)` for intentional same-scale variable updates by later models.
- Added environment/microclimate backend protocol with `AbstractEnvironmentBackend`, `GlobalConstant`, `meteo_inputs_`, `meteo_outputs_`, sampling, scattering, and validation.
- Extended multirate support with `Dates`-based timesteps, inferred/explicit bindings, temporal output policies, scoped streams, meteo aggregation, and requested output export.
- Added MAESPA-style example in [examples/maespa_domain_example.jl](/Users/rvezy/Documents/dev/PlantSimEngine/examples/maespa_domain_example.jl) with two plant species, shared soil, scene-scale iterative energy balance, and hard-domain targets.
- Added docs for domain simulation, model traits, hard-domain target design, and implementation plan/handoff notes.
- Added focused tests for domains, environment backends, meteo traits, updates, and the MAESPA example.

Verification already run:
- `julia --project=test test/runtests.jl` passed: `1844 / 1844`
- `julia --project=docs docs/make.jl` passed
- `git diff --check` passed

Files to remember are untracked too, especially:
- `src/domains/domain_simulation.jl`
- `src/time/runtime/environment_backends.jl`
- `src/dependencies/update_dependencies.jl`
- `examples/maespa_domain_example.jl`
- new docs under `docs/src/dev/`
- new tests under `test/test-domain-simulation.jl`, `test/test-environment-backends.jl`, `test/test-maespa-domain-example.jl`, `test/test-meteo-traits.jl`, `test/test-updates.jl`
- remove ModelList compatibility
- replace Symbol("") mapping sentinels
- refactor repeated multirate input-resolution flow
- split the large domain runner into scheduler/routes/environment/graph/publication pieces
- replace assertions by more standard errors
Shared Status / StatusView interface helpers.
Extracted repeated test graph comparison runner.
Extracted toy tutorial MTG helpers.
Typed export plans, reverse mappings, temporal stream aliases.
Preserved renamed producer source variables in binding inference.
Added explicit domain DAG run ordering.
Added topology reindexing for RefVectors after add/remove/reparent.
Split MAESPA scene solver math from side effects and added validation tests.
Fix recursive call leading to stack overflow
compile_scene (line 638) now validates required inputs_(model) variables.
A required input is valid if it has a compiled Inputs(...)/inferred binding or already exists on the target object Status.
Missing inputs now error with application id, object id, and input name.
Added tests for missing inputs, ambiguous same-object producers, and status-provided inputs.
…cies.

Unscoped Inputs(...) / Calls(...) dependency selectors now infer scope from the consumer object:
scene consumers default to SceneScope()
non-scene consumers default to Self()
Direct public resolve_object_ids(scene, Many(...)) remains scene-wide unless within=... is explicit.
Shared cross-scope dependencies from organs now need explicit within=SceneScope(), as in the updated shared-soil test.
Added tests showing plant-level unscoped leaf inputs are plant-local, while scene-level unscoped leaf inputs are scene-wide.
Exceptional-organ Override(...).
Instance and object-level model replacement validation.
Concrete dispatch preserved for same-type parameter overrides.
explain_instances(scene) and instance membership in explain_objects.
New organs inherit instance kind and species.
Hard-called overridden models use the correct per-object implementation.
VEZY added 30 commits August 11, 2026 15:11
# Conflicts:
#	.gitignore
#	src/PlantSimEngine.jl
#	test/runtests.jl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant