Repository navigation
feat(fault): native fault kernel in the new package loop-model-core (spec 007) - #431
Draft
lachlangrose wants to merge 39 commits into
Draft
lachlangrose wants to merge 39 commits into
lachlangrose wants to merge 39 commits into
Conversation
…er handoff benchmarks/fault_evaluation/many_faults.py builds the deterministic 94-fault model (54 isolated, 40 cutting faults; about 7 minutes), times evaluate_model and the cost of each fault, and saves or compares the model ids and group values bit for bit (SC-001, SC-004). A fast test checks the fault layout without a build. HANDOFF.md tells the implementer what to read, the order of work and how to measure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
…1 profile T001 records the native fault decision in ROADMAP.md. T002 profiles the 94-fault model: the restore order work takes most of the time of a cut fault. T003 and T014 add failing tests for restore_order and the native settings. T008 adds the Rust module fault with types and stubs. T009 records the likely cause of the proof-of-concept difference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
…es and k-d tree T004 adds restore_order: a feature keeps the restore order of its faults and computes it again only when a cutting fault changes (spec 007 story 1). T010, T011 and T023 port the structured grid lookup, the fault displacement profiles and an exact nearest-point search to the Rust module fault, with tests against values from Python. T015 adds LoopStructuralConfig.native_faults, native_threads and the native kernel switch. The T003 test no longer passes equal_nan to assert_array_equal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
GridField::gradient gives a zero gradient outside the grid, as the Python interpolator does. Only a NaN coordinate gives a NaN gradient. A NaN gradient outside the grid would make a restored point NaN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
…rnel Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
T012 adds the native restoration of the Rust module fault: apply and restore port FaultSegment.apply_to_points and restore_through, with the block sides, reverse movement, the cutter chain, the region masks and the step direction of #425. A thread pool serves the batch functions. T019 adds --native-faults {on,off} to the benchmark runner. T005 measures the 94-fault model after the order cache: 13.6 ms for each cutting fault (39.1 ms before), so SC-001 still fails and D1b runs next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
…kernel to Python T006 (D1b) restores the points once for the three members of a cut fault frame, with bit-identical results. The 94-fault model now takes 10.7 ms for each cutting fault (39.1 ms before stage S1); SC-001 asks for 10 ms. The lookup-count test allows fewer lookups for the child_faults case, with the maintainer's agreement. T013 adds the PyO3 classes FaultChain and GridField and FAULT_KERNEL_VERSION = 1. T024 adds the native tetrahedron gradient with the nearest-point fill and the refinement rounds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
… and CI checks T017 and T018 add the tests of the native restoration (parity with the Python path on the golden models, the switch, and story 5: fallback, no stale data, GIL release, threads); they fail until T016. T025 adds FaultChain.feature_gradient. T020 runs tests/fault_evaluation with the native core in CI, and T030 adds a fault kernel smoke test to the wheel workflow. T007 records stage S1 in ROADMAP.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
T016 adds chain_for and restore to _native_faults: a supported feature gets a FaultChain built from its faults, kept with a state token, and the Python path calls the kernel first. A fault whose cutters are not restored at its turn (forward movement) uses the Python path. The largest native difference on the golden models is 9.3e-10. T034 runs the spec 003 tests of the Python internals with the native path off. T031 documents the fault kernel. The T006, T017 and T018 tests follow the decisions in the plan answers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
…tests T021 measures stage S2 on the T030 computer: the native restoration takes 0.23 to 0.30 of the Python time on 1 thread (SC-002 asks for 0.20 or less) and 0.023 to 0.028 on 20 threads (SC-003 passes). The extra memory for 10 million points is 685 MB (Python 6430 MB; SC-007 passes). The largest native difference on the golden models is 9.3e-10 m. T026 adds the parity tests of native values, gradients and model ids; they fail until T027. New task T035 makes the 1-thread kernel faster. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
The native field parity test now checks that the native path is used for each faulted feature, so it cannot pass on the Python path twice. The gradient test on a fault also checks the Python path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
T027 adds field_for: a supported feature evaluates its values and grid gradients with a native GridField, and the gradient of a faulted feature with FaultChain.feature_gradient (tetrahedron, nearest fill, refinement). The largest native difference of the field parity tests is 1.2e-10. The fold feature on a tetrahedral mesh keeps the Python path. T035 removes hot-path work in the native restoration; a quiet re-measure shows no measurable gain, so SC-002 still fails (0.23 to 0.30; target 0.20). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
T028 measures the 94-fault model with the native path: evaluate_model at 5000 points takes 0.059 s (target 0.5 s; Python 0.971 s in the same run, 2.09 s on master), and the golden tests pass with the native path on. T022 records stage S2 in ROADMAP.md. New task T036 lets the 94-fault benchmark run with the native path on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
… record S3 and S4 checks T036 writes None for the per-fault times when the native path makes no Python fault call, so many_faults no longer fails with the native path on. T029 records stage S3 in ROADMAP.md. T032 builds the native wheel on Linux x86_64, installs it in a clean environment and passes the smoke test and the golden tests; the other platforms need a CI run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
T033 runs the full test suite three times: with the native path on and off 3341 tests pass, and without the native package 3296 pass. The only failure is a native solver test that also fails on master with the core installed. Ruff finds no new errors. ROADMAP.md records stage S4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
…pec 007 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
The maintainer moves the native fault kernel out of loop_interpolation_core into a new package loop-model-core, in spec 007. Design D5 and tasks T037 to T042 move the crate, the Python import, the extra, CI and release, and fix two end review findings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
…op-model-core The fault kernel evaluates a built model and shares no code with the solver, so it moves out of loop_interpolation_core into packages/loop_model_core (Python module loop_model_core, FAULT_KERNEL_VERSION 1). The Rust code and its tests move with git mv; the PyO3 classes FaultChain and GridField move to the new crate. The solver core keeps only the solver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
LoopStructural imports the fault kernel from loop_model_core, and the extra native installs loop-model-core. A new workflow builds and smoke tests its wheels on the five platforms; pypi.yml publishes it, native.yml checks and tests it, and release-please and the dev-tools config know the package. The solver core wheel test keeps only the solver check. uv.lock is not changed: the master lock is already stale (plan Answers, T038). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
… subclasses to Python native_threads() gives 0 (all cores) for a negative setting, as -1 in joblib; before, the native call raised OverflowError. The support checks of the native path use exact types for FaultSegment, FaultDisplacement and the region classes, so a user subclass takes the Python path (FR-008). The settings test fixture now restores the module state after each test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
With both native cores, with the native path off, and without loop-model-core, the full suite passes except one native solver test that also fails on master. Ruff finds no new errors. Both crates pass fmt, clippy and tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
Native and Python results agree on the 94-fault model at 500, 2000 and 5000 points: the largest difference is 1.3e-12 (tolerance 1e-4), the NaN points are equal and no model id differs. The official benchmark runs with the native path on: 0.063 s at 5000 points (SC-004, target 0.5 s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo
This branch has not been deployed
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
Spec 007: a native (Rust) fault kernel for LoopStructural, with the Python path kept as the reference and the fallback.
restore_order), and the three members of a cut fault frame share one restoration. Bit-identical results.loop-model-core(packages/loop_model_core, moduleloop_model_core) restores points through the faults of a supported feature and evaluates field values, grid gradients and the tetrahedron gradient of faulted features. LoopStructural uses it automatically when it is installed (pip install loopstructural[native]) andFAULT_KERNEL_VERSIONmatches.LoopStructuralConfig.native_faultsorLOOPSTRUCTURAL_NATIVE_FAULTS=0(the setting wins).LoopStructuralConfig.native_threads(None, 0 or a negative value: all cores).model-core-wheels.yml, 5 platforms, abi3-py39), PyPI upload, CI checks innative.yml, and release-please and dev-tools entries.loop_interpolation_corekeeps only the solver.Spec, plan, tasks and evidence:
specs/007-native-fault-kernel/(verification.mdhas all measurements).Results (T030 computer, i7-12700H)
evaluate_modelat 5000 ptsNative vs Python: largest difference 9.3e-10 on the golden models and 1.3e-12 on the 94-fault model (tolerance 1e-8 × box); NaN points equal; model ids equal.
Test plan
pytestwith the native path on (3343 passed), off (3343 passed), and withoutloop-model-core(3311 passed). The only failure,tests/unit/modelling/test_native_fault_frame.py::test_the_native_fault_frame_is_the_cg_fault_frame, is a native solver test that also fails on master wheneverloop_interpolation_coreis installed (out of scope).ruff check LoopStructural packages: no new errors (34 on master).cargo fmt --check, clippy (none, parallel, python) with-D warnings,cargo test --release(also--features parallel).model-core-wheels.ymlandcore-wheels.ymlon all platforms (SC-008); macOS x86_64 is cross-compiled and needs a check by hand.Before merge / release
uv.lockis not changed: the master lock is already stale (release-please raised versions without a re-lock). A separate re-lock on master addsloop-model-core.pypi.ymlas a trusted publisher of the new projectloop-model-core.feattitle, so release-please makes the firstloop-model-corerelease.grid_field.rs). 34 minor review findings are listed inspecs/007-native-fault-kernel/run-state.json.🤖 Generated with Claude Code
https://claude.ai/code/session_01XADRvNCFVAUoEtXrZywGSo