Repository navigation
Phase 3: shared params-file reader for every backend - #327
Merged
neuromechanist merged 11 commits intoSep 22, 2026
Merged
neuromechanist merged 11 commits into
neuromechanist merged 11 commits into
Conversation
read_params_file (issue #304) is the single params-file entry point every backend should use: content-sniffs JSON vs Fortran input.param text and returns canonical pamica keys either way, aliasing a JSON file's schema spellings (min_grad_norm/max_decs/numrej/num_mix_comps/ share_int) via one table. A file with both an alias and its canonical key raises ValueError. writestep/do_history/histstep move from FORTRAN_UNSUPPORTED_KEYS to translated (identity) keys: the reader translates what any backend supports, not just the wrapper; the legacy NumPy backend already implements periodic checkpointing under these names.
Replaces the wrapper's own inline JSON/Fortran content sniffing with the shared reader (issue #304). Behavior change: sample_params.json's own max_decs/min_grad_norm/share_int settings are now applied (as maxdecs/min_nd/share_iter) instead of silently landing in the "not applied" warning.
AMICA_NumPy(params_file=...) and load_default_params now read through read_params_file (issue #304) instead of a bare json.load, so the legacy backend accepts the literal Fortran input.param text too, not just JSON. Canonical keys map to this backend's own spellings (min_nd -> min_grad_norm, maxdecs -> max_decs, share_iter -> share_int); files/data_dim/field_dim come off the same parsed dict instead of a second file read. A params-file setting this backend does not consume is named in one logger.warning. from_json_file is renamed to from_params_file (matches the PyTorch wrapper's name, now accepts both formats); no alias left behind. pdftype != 0 now raises NotImplementedError at construction: this backend implements only the generalized-Gaussian source density and previously silently ignored the setting. numpy_impl/params.json's bundled default pdftype changes 1 -> 0 to match; the value was never read by the fit path, so no previously-passing fit's numerics change.
_FORTRAN_ALIASES is now derived from fortran_params. PAMICA_KEY_TO_FORTRAN_KEY (the shared reader's single source of truth for pamica-key -> Fortran-keyword) plus the one JSON-only share_int addition, instead of a hand-maintained duplicate. load_sample_data reads sample_params.json through read_params_file, so min_nd/maxdecs/ share_iter land in run_pytorch_amica's ng_kwargs via the plain _NG_PARAMS filter; the max_decs special case is no longer needed.
docs/guides/validation.md: read_params_file, the JSON alias table, the writestep/do_history/histstep move, and the NumPy backend's own params-file/pdftype behavior. docs/guides/amica-differences.md: the backend-differences table's Fortran input.param reader row (NumPy now yes, MLX awaits epic #324 Phase 4) and the NumPy pdftype NotImplementedError. docs/api/numpy-backend.md: the renamed from_params_file classmethod and the pdftype guard. docs/changelog.md: Unreleased entry covering the shared reader, the wrapper's now-applied JSON aliases, NumPy's input.param support, the from_json_file rename, and the NumPy pdftype guard.
cli.py's load_params() did a bare json.load, so the CLI died with JSONDecodeError on a Fortran input.param even though AMICA(params_ file=...) already accepted it. It now calls the same _read_numpy_keyed_params helper the constructor uses (no duplicated key-mapping table), so both formats work; files stays unresolved relative to the working directory, matching Fortran-binary semantics. New test_numpy_cli.py exercises main() end to end on real bundled data for both formats; verified to fail with JSONDecodeError on the pre-fix load_params().
Replaces the hand-added share_int entry with a composition of JSON_ALIAS_TO_CANONICAL (JSON alias -> canonical) and PAMICA_KEY_TO_FORTRAN_KEY (canonical -> Fortran keyword), so write_fortran_param_file accepts either raw JSON-schema keys or canonical keys with no hand-maintained entry left in this module. Adds coverage: canonical maxdecs/min_nd are written as Fortran max_decs/min_grad_norm, and an end-to-end test feeds load_sample_ data()'s canonical-keyed params straight into write_fortran_param_ file, asserting the written file carries Fortran's own spellings and none of the canonical ones.
NumPy: explicit kwargs win over params-file defaults (mirrors the PyTorch wrapper's precedence test). Wrapper: fitting from input.param names writestep/do_history/histstep in the "not applied" warning, since AMICATorchNG has no matching constructor keyword (issue #312). Pins FORTRAN_TO_PAMICA_KEY/FORTRAN_UNSUPPORTED_KEYS table sizes so a future move between them forces the docstring/doc counts to be revisited.
fortran_params.py module docstring and its mirror in validation.md still claimed share_int was "out of scope" and surfaced only via the "not applied" warning -- stale since read_params_file/ JSON_ALIAS_TO_CANONICAL landed; both now correctly say share_iter needs no Fortran-side rename and the JSON alias table handles share_int on the way in. Reworded four "silently landed in the not applied warning" claims (amica.py, changelog.md, validation.md, a test docstring): the warning already named max_decs/min_grad_norm/share_int before this epic, it just did not apply them -- "silently" overstated that. numpy_impl/core.py's __init__ docstring now says params_file accepts both formats. AGENTS.md's architecture-map line for fortran_params.py now describes it as the shared reader for the wrapper, AMICA_NumPy and the NumPy CLI. amica-differences.md spells out "generalized Gaussian (GG)" at first use. Applies semantic line breaks to the Markdown prose this epic added (changelog.md, validation.md, amica-differences.md, numpy-backend.md), without reflowing pre-existing text.
…-class' into feature/issue-304-phase3-params-surface # Conflicts: # docs/changelog.md # pamica/numpy_impl/core.py
neuromechanist
merged commit Sep 22, 2026
b6ecf22
into
feature/issue-324-epic-mlx-first-class
8 checks passed
This was referenced Sep 22, 2026
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
pamica/fortran_params.pygainsread_params_file, the single params-file entry point every backend now uses: it content-sniffs JSON vs. the literal Fortraninput.paramtext and returns pamica's canonical keys either way, applying one alias table (JSON_ALIAS_TO_CANONICAL) to a JSON file's own schema spellings (min_grad_norm,max_decs,numrej,num_mix_comps,share_int); a file carrying both an alias and its canonical key raisesValueErrornaming both.writestep/do_history/histstepmove fromFORTRAN_UNSUPPORTED_KEYSto translated (identity) keys: the reader now translates what any pamica backend can honor (the legacy NumPy backend already implements periodic on-disk checkpointing under these names), and each consumer is responsible for warning about what it cannot apply.AMICA.from_params_file(the PyTorch wrapper) now callsread_params_fileinstead of its own inline JSON/Fortran sniffing, sosample_params.json's ownmax_decs/min_grad_norm/share_intsettings are now applied (see "Behavior changes" below).AMICA_NumPy(pamica/numpy_impl/core.py) routes both the bundled defaultparams.jsonand a user-suppliedparams_filethroughread_params_file, maps the canonical keys to this backend's own attribute spellings (min_nd->min_grad_norm,maxdecs->max_decs,share_iter->share_int), and readsfiles/data_dim/field_dimoff the same parsed dict instead of a second rawjson.load. A params-file setting this backend does not consume is named in onelogger.warning. The classmethodfrom_json_fileis renamed tofrom_params_file(no alias left behind), andpdftype != 0now raisesNotImplementedErrorat construction -- this backend implements only the generalized-Gaussian source density and previously silently ignored the setting;numpy_impl/params.json's bundled defaultpdftypechanged1->0to match.validate_implementations.py's own JSON-schema-to-Fortran-keyword alias table (_FORTRAN_ALIASES) and itsmax_decsspecial case are now derived from the shared reader (fortran_params.PAMICA_KEY_TO_FORTRAN_KEY) instead of duplicating the knowledge;load_sample_datareadssample_params.jsonthroughread_params_filetoo.pamica/native/engine.pyis left untouched: its_DEFAULT_PARAMSare correctly Fortran-spelled (out of scope per the design), and its_ALIASEStable (n_models/n_mix-> Fortran keywords) maps from the wrapper-level constructor kwarg names, not pamica's canonical params-file keys, so deriving it from the shared table would not be a direct, behavior-preserving swap -- see "Deviations / notes for the lead" below.Docs updated:
docs/guides/amica-differences.md(backend table row + pdftype guard note),docs/guides/validation.md(read_params_file, the JSON alias table, the writestep/do_history/histstep move, the NumPy backend's own params-file/pdftype behavior),docs/api/numpy-backend.md(renamed classmethod, Fortran support, pdftype guard),docs/changelog.md("Unreleased").Part of #304 (MLX path lands with Phase 4, #313). Part of epic #324.
Behavior changes
AMICA.from_params_file(PyTorch wrapper) now appliessample_params.json's ownmax_decs/min_grad_norm/share_intsettings (asmaxdecs/min_nd/share_iter) instead of silently dropping them into the "not applied" warning.AMICA_NumPy(params_file=...)now accepts the literal Fortraninput.paramtext format, not just JSON (previously raised a rawjson.JSONDecodeError).AMICA_NumPy's unconsumed params-file settings are now named in onelogger.warninginstead of silently vanishing.AMICA_NumPy.from_json_fileis renamed tofrom_params_file; no alias left behind.AMICA_NumPy(pdftype=...)with anything other than0now raisesNotImplementedErrorat construction.numpy_impl/params.json's bundled defaultpdftypechanged1->0; since the value was never read by the fit path, no previously-passing fit's numerics change.validate_implementations.py --help/ its own JSON-vs-Fortran comparison harness:min_nd/share_iter(fromsample_params.json'smin_grad_norm/share_int) now reachAMICATorchNGautomatically via the canonical-keyedparamsdict (previously silently landed in the harness's own "ignored" warning while, on the Fortran side,write_fortran_param_filealready wrote them -- an uncontrolled-comparison gap this closes as a side effect, not a regression).Test plan
uv run ruff check --fix . && uv run ruff format .-- cleanuv run ty check-- cleanuv run pytest pamica/tests/test_fortran_params.py pamica/tests/test_fortran_param_forwarding.py pamica/tests/test_sample_data.py pamica/tests/test_numpy_params_file.py -q-- 85 passed, 3 xfailed (pre-existing, unrelated), 0 faileduv run pytest -q -n auto(full suite) -- in progress at PR-open time; will report the final count separatelyuv run python validate_implementations.py --help-- still worksread_params_file(sample_params.json)andread_params_file(input.param)agree on 49 shared keys (>= 47 gate), the only difference beingfilesValueErrorAMICA_NumPyfrominput.paramequalsAMICA_NumPyfromsample_params.jsonon every shared hyperparameter attributeAMICA_NumPy(params_file=<input.param>, max_iter=3, ...).fit()with no explicit data runs (chdir tosample_data/, matching the Fortran binary's own path resolution)AMICA_NumPy(pdftype=1|2|3|4)raisesNotImplementedError;pdftype=0constructsAMICA.from_params_file(sample_params.json)appliesmaxdecs=3/min_nd=1e-7/share_iter=100to the fittedAMICATorchNG, and the wrapper's "not applied" warning no longer namesmax_decs/min_grad_norm/share_intAMICA_NumPy's unconsumed-key warning nameskurt_start/num_kurt/kurt_int/num_samplesforinput.param;writestep/do_history/histstepfrom Fortran text reachAMICA_NumPy's attributes