Support (event, ics) tuple return from sys_event functions#159
Open
Support (event, ics) tuple return from sys_event functions#159
Conversation
…ions When a sys_event function returns a Tuple, treat it as (event, ics_dict) and merge the initial conditions into the system. This allows system events to provide initial conditions for discrete variables they manage. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #159 +/- ##
===========================================
- Coverage 79.39% 46.66% -32.74%
===========================================
Files 18 17 -1
Lines 1383 1378 -5
===========================================
- Hits 1098 643 -455
- Misses 285 735 +450
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ctessum-claude
added a commit
to ctessum-claude/EarthSciData.jl
that referenced
this pull request
Apr 12, 2026
Redesigns the MTK interpolation path to use discrete array parameters routed through MTK's nonnumeric buffer, instead of the old stateful `ITPWrapper`. This separates data buffer updates from symbolic interpolation, enabling future GPU compatibility. ## Core design * `DataBufferType` — concrete wrapper struct used as the discrete parameter's symtype. `is_variable_floatingpoint` returns `false`, routing values to MTK's nonnumeric parameter buffer while still presenting as a scalar symbol to the rest of the system. * `@register_symbolic` declarations for the 2D/3D/4D `interp_unsafe` overloads plus `@register_derivative` with a zero derivative for IMEX `tgrad` compatibility. * `create_interp_equation` returns `(eq, discretes, constants, interp_info)` carrying everything needed to build event and interp expressions symbolically. * `build_interp_event` returns a `SymbolicDiscreteCallback` with the update affect registered for both the periodic tstops *and* the initialize slot. It uses bare subsystem symbols so MTK's `namespace_affect` rewrites them during compose/flatten. The event is attached to each loader's `System` via `discrete_events=`, so both `mtkcompile(loader)` and `convert(System, couple(loader, ...))` pick it up through the standard discrete-events machinery. * The old `create_updater_sys_event` indirection and `SysDiscreteEvent`-metadata routing are removed. * Array-based `interp_unsafe` implementations for 2D/3D/4D data with fractional index interpolation, replacing the old BSpline-backed `interp!`. * `_itp_defaults` now includes array-valued defaults wrapped in `DataBufferType` so they flow through the `initial_conditions=` path regardless of whether the caller goes through the coupled path or not. * `needed_vars` handles the `Set` return type from newer MTK's `get_variables`. ## `include_vars` / `preload_time` API Direct `mtkcompile(loader)` + `getsym(prob, ...)` without `solve` needs the data buffer to already hold real values — the discrete event only fires during integration. Preloading every variable at construction OOMs for large datasets (GEOSFP, NEI, WRF), so loaders now expose: * `include_vars` — a variable allowlist that filters the interp loop *and* triggers preloading of only the listed variables plus a hardcoded `required_vars` set (the variables needed by the loader's derived equations: pressure, geopotential height, etc.). * `preload_time` — picks the dataset DateTime to preload at (default `starttime`). Callers that will query the system at a specific time pass that DateTime here. * `preload::Bool` — for single-variable loaders (ERA5, CEDS, EDGAR, USGS3DEP, OpenAQ, LANDFIRE) a simple bool-plus-preload_time pair replaces `include_vars`, since the variable set is already limited by existing arguments. When neither `include_vars` nor `preload` is set, behaviour is unchanged: all variables get zero-filled discretes and the update event populates them during `solve`. ## Loader propagation All ten loaders (GEOSFP, WRF, NCEP-NCAR, NEI2016 monthly, ERA5, EDGARv81 monthly, CEDS, USGS3DEP, OpenAQ, LANDFIRE) updated to the new 4-tuple `create_interp_equation` API, attach the interp event via `discrete_events=`, and thread through the new preload kwargs. ## Tests Direct-mtkcompile tests in `test/geosfp_test.jl`, `test/wrf_test.jl`, and `test/NCEP-NCAR_Reanalysis_test.jl` updated to pass the appropriate `include_vars`/`preload_time` combinations matching each test's query time. Structural tests that use the coupled path are unchanged. ## Misc * `src/load.jl`: array-based `interp_unsafe(data, fit, fi..., extrap)` implementations for 2D/3D/4D arrays. * `Base.copy(::DataBufferType)` for the `MTKParameters.copy` path used during parameter-timeseries-collection construction. * `ifelse` shape fix for SymbolicUtils installed at `__init__`. Companion PR: EarthSciML/EarthSciMLBase.jl#159 (supports `(event, initial_conditions)` tuple return from sys_event for the removed SysDiscreteEvent path; no longer required by this version but kept for backward compatibility with pre-refactor loaders). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sys_eventfunction returns aTuple, treat it as(event, initial_conditions_dict)and merge the initial conditions into the systemcreate_updater_sys_eventwhich returns(event, ics)to set initial values for data array discretesTest plan
🤖 Generated with Claude Code