Skip to content

Add a diagnostic data-provider interface (isolate OMEGA specifics)#107

Open
joglekara wants to merge 1 commit into
refactor/break-coupling-prereqsfrom
feature/diagnostic-data-provider
Open

Add a diagnostic data-provider interface (isolate OMEGA specifics)#107
joglekara wants to merge 1 commit into
refactor/break-coupling-prereqsfrom
feature/diagnostic-data-provider

Conversation

@joglekara

Copy link
Copy Markdown
Member

What

Introduces a diagnostic data-provider interface — the primary goal @almilder called out in #105: isolate the OMEGA-specific diagnostic specifics behind a minimal interface so others can plug in their own diagnostic (e.g. NIF OTS) or supply preprocessed data without navigating the jax/AD model code.

"the most important goal of this decomposition is to isolate the diagnostic specifics (calibrations, data loading, k-smearing)... so that other users can add on their own diagnostic specifics (e.g. NIF OTS)... or supply preprocessed data instead of raw OMEGA files."

How

The pipeline already had the right seam: everything downstream of data loading (LossFunction, ThomsonScatteringDiagnostic, the optimization loops, postprocessing) consumes only a plain (all_data, sa, all_axes) tuple. All OMEGA-specificity sits upstream of it. This PR makes that seam an explicit, registerable contract.

  • tsadar/data/__init__.pyregister_data_provider(name) decorator + get_data_provider(config). A provider is any config -> (all_data, sa, all_axes) callable, selected by config["data"]["provider"] (default "omega").
  • tsadar/data/omega.py — the OMEGA loader (moved out of fitter) as the reference provider, self-registered as "omega".
  • fitter.fit resolves data via get_data_provider(config)(config); load_data_for_fitting stays as a thin back-compat shim.

Adding a new diagnostic now takes zero model-code changes:

from tsadar.data import register_data_provider

@register_data_provider("nif_ots")
def load_nif(config):
    ...                       # raw files OR preprocessed arrays — your choice
    return all_data, sa, all_axes

then config["data"]["provider"] = "nif_ots".

Behavior preservation

Configs without a provider key resolve to "omega" and follow the exact previous code path (incl. the multiplexed/rotated angular special case). Verified statically: registry resolves default→omega, empty-config→omega, unknown→clear KeyError; all intra-tsadar imports resolve; everything compiles. (Local jax is too old to run the suite — import smoke test + suite should be confirmed by a reviewer with a working env.)

Open question for @almilder

Supplying preprocessed data is now supported by registering a trivial provider that returns your in-memory (all_data, sa, all_axes). If you'd rather have a built-in "preprocessed" provider that reads from a file, what format do you want — .npz, xarray/netCDF, or just an in-memory dict passed programmatically? I left that out rather than guess the format.

Sequencing / not in scope

Toward #105.


🤖 Generated with Claude Code

Realizes the primary goal from #105 (per @almilder): isolate the OMEGA-specific
diagnostic specifics (raw file loading, calibration, background, lineouts)
behind a minimal interface so other users can plug in their own diagnostic
(e.g. NIF OTS) or supply preprocessed data -- without touching the jax/AD
model code.

The whole pipeline downstream of data loading already consumes only a plain
`(all_data, sa, all_axes)` tuple. This turns that existing seam into an
explicit, registerable contract:

- `tsadar/data/__init__.py`: `register_data_provider(name)` + `get_data_provider(config)`
  registry. A provider is any `config -> (all_data, sa, all_axes)` callable.
  Selected by `config["data"]["provider"]`, defaulting to "omega".
- `tsadar/data/omega.py`: the OMEGA loader (moved out of `fitter`) as the
  reference provider, self-registered as "omega".
- `fitter.fit` now resolves data via `get_data_provider(config)(config)`.
  `load_data_for_fitting` is kept as a thin back-compat shim.

Behavior-preserving: configs without a `provider` key resolve to "omega" and
follow the exact previous code path. External diagnostics register with
`tsadar.data.register_data_provider` and require no jax/AD knowledge.

Toward #105. Stacked on the coupling-break PR (#106).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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