Repository navigation
Write CLI results in Fortran binary format (#30) - #40
Merged
neuromechanist merged 4 commits intoJul 5, 2026
Merged
neuromechanist merged 4 commits into
neuromechanist merged 4 commits into
Conversation
The legacy NumPy CLI wrote results as .npy, but loadmodout (and the tests/comparison path) expect raw Fortran-format binaries with no extension, so the round-trip raised FileNotFoundError for 'W'. Converge on the Fortran format: - AMICA._write_results now writes raw little-endian float64 (int32 comp_list) files (gm, A, W, S, mean, c, alpha, mu, sbeta, rho, comp_list, LL) in loadmodout's layout, making pyAMICA output directly comparable to and loadable by the same reader as the Fortran amicaout. Verified: loadmodout round-trip Hungarian-matches the Fortran reference W at min corr 0.95 / 32-of-32 bijective (150-iter fit; the full CLI run is higher). comp_list is written 1-based (Fortran convention). - load_results now reads that raw-binary format back into AMICA's internal array shapes for the amica_viz helpers (the compressed flag is a documented no-op; the format is never .npz). - Fix a pre-existing broken import in amica_viz.plot_pdf_fits (from amica_pdf -> from .amica_pdf). - Un-xfail test_sample_data_cli; add a fast non-slow smoke test covering the format round-trip (loadmodout + load_results shapes) and the viz helpers on real data (also viz coverage for #15). Tested: new smoke test + non-slow suite green (33 passed, 1 xfailed which is the unrelated under-convergence test_sample_data_light).
amica_data.save_results wrote the .npy/.npz format and had no callers; it is the counterpart to the old load_results and is now inconsistent with the raw-binary format everything reads. Removing it finishes converging on the single Fortran-binary format.
- AMICA.fit now does an unconditional (finite-guarded) final _write_results, so a run whose last iteration is not a writestep multiple still persists the converged result; the finite guard avoids overwriting good output with a #39 NaN state. - Scope the _write_results "Fortran byte layout" claim to num_models==1 in the docstring/comments; multi-model output is self-consistent (loadmodout round-trips) but not byte-identical to Fortran (noted, ref #27). - load_results raises a clear FileNotFoundError on an incomplete output directory instead of a cryptic downstream KeyError in a viz helper. - Update the stale `compressed` docstrings in the viz helpers (legacy no-op). - Smoke test now relies on fit's final write (exercises that path) and adds value-level round-trip asserts (loaded W/A/alpha/comp_list == in-memory), guarding transpose/axis-order regressions a shape check would miss. - Add test_cli_subprocess_output_loadable: runs the real amica_cli entrypoint on a short stable config and confirms loadmodout reads the output (the direct #30 regression). Tested: non-slow suite 34 passed, 1 xfailed.
Member
Author
Review (3 agents, Sonnet) + resolutionsFindings addressed in b20ba66: Addressed
Skipped (with rationale)
Non-slow suite after fixes: 34 passed, 1 xfailed (the unrelated under-convergence test). |
neuromechanist
deleted the
30-legacy-cli-saveload-format-mismatch-npy-vs-fortran-binary
branch
July 5, 2026 02:15
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
The legacy NumPy CLI wrote results as
.npy, butloadmodout(and the tests/comparison path) expect raw Fortran-format binaries with no extension, so the round-trip raisedFileNotFoundErrorforW. This converges pyAMICA on the single Fortran-binary format.Changes
AMICA._write_resultsnow writes raw little-endian float64 (int32comp_list) files (gm, A, W, S, mean, c, alpha, mu, sbeta, rho, comp_list, LL) inloadmodout's byte layout, so pyAMICA output is directly comparable to and loadable by the same reader as the Fortranamicaout.comp_listis written 1-based (Fortran convention).load_resultsnow reads that raw-binary format back into AMICA's internal array shapes for theamica_vizhelpers (thecompressedflag is a documented no-op; the format is never.npz).amica_data.save_results(.npy/.npzwriter, no callers) to finish converging on one format.amica_viz.plot_pdf_fits(from amica_pdf→from .amica_pdf).test_cli_output_format_roundtripcovering the format round-trip (loadmodout+load_resultsshapes) and all three viz helpers on real data (also viz coverage toward Test coverage gaps: AMICA.save/load and plot_components #15).Verification
_write_results→loadmodoutHungarian-matches the Fortran referenceWat min corr 0.95 / 32-of-32 bijective (150-iter fit; the full run is higher).Honest status on
test_sample_data_cliThe #30 format bug is fixed, but I kept
test_sample_data_cli(the full 2000-iter CLI-vs-Fortran integration test)xfail: with the format fixed it now gets past the load step, but the NumPy backend diverges to a non-finite likelihood ~iter 687 on the sample data and stops early, so the degraded result no longer matches Fortran. That is a separate long-fit numerical-stability bug, filed as #39 (the torchAMICATorchNGdefault backend is unaffected; the NumPy backend is stable and matches Fortran at ~150 iters per the #37 parity test). The xfail reason now points at #39, and the format contract itself is covered by the new smoke test.Related