Skip to content

Phase 3: native run engine + binary resolver/installer - #175

Merged
neuromechanist merged 2 commits into
mainfrom
feature/issue-168-phase3-native-engine
Jul 17, 2026
Merged

neuromechanist merged 2 commits into
mainfrom
feature/issue-168-phase3-native-engine

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

Adds AMICANative, the fourth run engine (alongside NumPy, PyTorch, MLX). It runs the dependency-free native binary and returns an AmicaOutput with the usual accessors, so it is the parity oracle the Python backends are checked against.

Closes #168. Part of epic #165.

What's included

  • pyAMICA.native.resolver: maps the host to its release asset, downloads on first use with SHA-256 verification, caches it, and honors PAMICA_NATIVE_BINARY. windows-arm64 -> windows-x64 (emulation, Native windows-arm64 AMICA binary (no MSYS2 gfortran yet) #173). python -m pyAMICA.native installs the binary explicitly.
  • pyAMICA.native.AMICANative: writes the data (.fdt, column-major) + a full input.param (embedded template, so no dependency on installed sample data), runs the binary, and loads the result via loadmodout. Friendly n_models/n_mix aliases; a collapsed fit is reported as a clear degenerate-fit error instead of an opaque SVD failure (cf. AMICA wrapper marks is_fitted_ even on a degenerate (nan_ll/singular_ll) fit #50).
  • Exported as from pyAMICA import AMICANative; pyAMICA.native added to the wheel packages.
  • CI builds the binary on Linux and sets PAMICA_NATIVE_BINARY, so the engine's end-to-end tests run for real (not skipped).

Test plan

  • 15 tests: resolver logic (platform tag, asset alias, SHA-256 verify, override, no-download) + real end-to-end engine runs on sample EEG (single- and multi-model, transform, degenerate-fit detection, input validation). No mocks; the E2E tests use a real locally/CI-built binary.
  • Full non-slow suite: 292 passed, 1 xfailed, no regressions.

@neuromechanist

Copy link
Copy Markdown
Member Author

Review (Sonnet) addressed

Critical (security): fixed. The resolver downloaded straight to the final cache path and verified after, so a corrupt/tampered binary poisoned the cache and (on Windows, where .exe needs no exec bit) could execute unverified on later calls, plus a TOCTOU race. Now the download stages in a private temp dir on the same filesystem, is SHA-256-verified and chmod'd there, and only then atomically renamed into the cache path -- so a file exists at the cache path only once verified. Regression tests added: a bad checksum raises and leaves the cache path absent (no poisoning), and a subsequent good download still succeeds.

Important: fixed. A relative binary/PAMICA_NATIVE_BINARY path passed the existence check but failed at exec time (subprocess runs with cwd=tempdir); both now Path(...).resolve().

Minor: addressed. version cache segment guarded against ../ traversal (Path(version).name); empty/truncated W now caught alongside the NaN degenerate-fit check; added a comment on the files-first param ordering requirement.

Confirmed clean by the reviewer: _fmt scientific-notation fidelity (byte-identical to input.param), URL host-injection safety, lazy top-level import (no network at import), and tempdir/output lifetime (all arrays materialized before cleanup).

17 native tests pass (incl. the 2 new security regression tests); lint/ty clean.

@neuromechanist
neuromechanist merged commit 79d1fa7 into main Jul 17, 2026
6 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-168-phase3-native-engine branch July 17, 2026 22:45
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 77.90698% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.62%. Comparing base (85892a2) to head (10ed96e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pyAMICA/native/__main__.py 0.00% 16 Missing ⚠️
pyAMICA/native/engine.py 83.56% 5 Missing and 7 partials ⚠️
pyAMICA/native/resolver.py 87.34% 6 Missing and 4 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #175      +/-   ##
==========================================
- Coverage   82.95%   82.62%   -0.34%     
==========================================
  Files          19       23       +4     
  Lines        2435     2607     +172     
  Branches      412      441      +29     
==========================================
+ Hits         2020     2154     +134     
- Misses        299      326      +27     
- Partials      116      127      +11     
Files with missing lines Coverage Δ
pyAMICA/__init__.py 100.00% <100.00%> (ø)
pyAMICA/native/__init__.py 100.00% <100.00%> (ø)
pyAMICA/native/resolver.py 87.34% <87.34%> (ø)
pyAMICA/native/engine.py 83.56% <83.56%> (ø)
pyAMICA/native/__main__.py 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Phase 3: native run engine + per-system binary resolver/installer

2 participants