Refactor inference data_writer configs to the Builder pattern#1314
Draft
mcgibbon wants to merge 1 commit into
Draft
Refactor inference data_writer configs to the Builder pattern#1314mcgibbon wants to merge 1 commit into
mcgibbon wants to merge 1 commit into
Conversation
Correct the Builder-pattern-pass violations in fme/ace/inference/data_writer/ so config schema is decoupled from the runtime writer impls. Behavior-preserving. Changes: - `fme.ace.inference.data_writer.main.DataWriterConfig`: `build`/`build_paired` now construct the full list of sub-writers (raw/monthly/file writers, plus the time-coarsen wrapper) and pass them to `DataWriter`/`PairedDataWriter` (Rule 2). The impls take a pre-built `writers` list instead of raw sub-configs and the enable flags. Add `DataWriterConfig.validate_time_coarsen` as the sanctioned accessor for parent configs. - `fme.ace.inference.data_writer.file_writer`: add `FileWriterParams`, a plain leaf params dataclass; `FileWriter` takes it instead of the non-leaf `FileWriterConfig` (Rule 1). Add `FileWriterConfig.validate_time_coarsen`. - `fme.ace.inference.inference.InferenceConfig` / `fme.ace.inference.evaluator.InferenceEvaluatorConfig`: `__post_init__` validate time coarsening via `data_writer.validate_time_coarsen(...)` instead of reading `data_writer.time_coarsen`/`.files` raw fields (Rule 1, parent read). - Tests: construct writers through `DataWriterConfig.build`/`build_paired` and `FileWriterConfig._build_writer_params` rather than the old impl signatures. - [ ] Tests added
ef7b149 to
ee0dd97
Compare
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.
Corrects the Builder-pattern-pass violations in
fme/ace/inference/data_writer/flagged by the 2026-06-24 builder-pattern audit, so the config schema (the dacite/YAML surface) is decoupled from the runtime writer implementations. The change is behavior-preserving. Follows the file-ordering / leaf-*Paramstemplate set by the corrector refactor (#1313).The audit flagged three issues here:
DataWriterConfig.build/build_pairedpassed rawtime_coarsen/filessub-configs intoDataWriter/PairedDataWriter, which then built the sub-writers themselves.FileWriterreceived the whole non-leafFileWriterConfigand read ~7 of its fields.InferenceConfig/InferenceEvaluatorConfig.__post_init__reached intodata_writer.time_coarsenand iterateddata_writer.files/file_config.time_coarsen.Changes:
fme.ace.inference.data_writer.main.DataWriterConfig:build/build_pairedconstruct the full list of sub-writers (raw/monthly/file writers, plus the time-coarsen wrapper) and pass them in;DataWriter/PairedDataWriter.__init__now take a pre-builtwriterslist instead of raw sub-configs + enable flags. Addedvalidate_time_coarsen()as the sanctioned accessor for parent configs.fme.ace.inference.data_writer.file_writer: addedFileWriterParams, a plain leaf params dataclass;FileWritertakes it (storesself._params, neverself._config) instead of the non-leafFileWriterConfig. AddedFileWriterConfig.validate_time_coarsen()and_build_writer_params().fme.ace.inference.inference.InferenceConfig/fme.ace.inference.evaluator.InferenceEvaluatorConfig:__post_init__now callsdata_writer.validate_time_coarsen(...)instead of reading the raw fields.DataWriterConfig.build/build_pairedandFileWriterConfig._build_writer_paramsrather than the old impl constructor signatures.Notes:
FileWriterParams.time_selectionholds the selector sub-configs (Slice | MonthSelector | TimeSlice), so the struct is a "runtime params" leaf in spirit (it forwards an opaque selector straight to_select_time, which dispatches via each selector's own methods — no raw cross-config field reads) rather than a strict field-type leaf. The alternative (re-deriving the selection inside the builder) would duplicate_select_time's dispatch.The non-paired
DataWriter's HEALPix (face) early-return is preserved inDataWriterConfig.build(it produces an empty writer list).path/metadata are now always stored, which only affects the never-used-in-production HEALPixDataWriter.writepath (previously wouldAttributeError; both inference entrypoints usebuild_paired, which never had afacecheck).The coupled
CoupledDataWriterConfigparent reads ofdata_writer.{ocean,atmosphere}.time_coarsenare a separate audit section (they wrap validation in per-component try/except messaging) and are left as a follow-up; this refactor keepstime_coarsena public field so nothing there breaks.Tests added (existing data_writer tests migrated to the public builder API; behavior coverage preserved)
Part of the builder-pattern-pass effort (task
2026-06-24-refactor-data-writer-configs-builder-pattern, goal2026-06-24-ace-obeys-builder-pattern-pass).