Repository navigation
feat(native): solve structural frames, use the cg iteration limit, and keep no stale field - #383
Merged
Merged
Conversation
…d keep no stale field - add_gradient_orthogonal_constraints keeps the points and the vectors as raw data in a native setup (b = 0), and the adapter gives them to the core as tangent rows. So the coordinates 1 and 2 of a structural frame (for example a fault) can use solver='native'. Before, they raised NotImplementedError for add_constraints_to_least_squares. - Without maxiter, the native iteration limit is 10 x the number of nodes, as the cg matrix solver. The core default (5000) stopped before it converged on large grids. - When a native solve does not converge and the old field is missing, only NaN, or from another grid, c gets the partial field. Before, c kept a field of the old grid, so a later evaluation failed with 'cannot assign N values to array of shape M'.
This was referenced Nov 2, 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.
Three problems with
solver='native'that showed up in the QGIS plugin with a real model (six faults and one stratigraphic group).1. Structural frames (faults) can use the native solver
The coordinates 1 and 2 of a structural frame get gradient orthogonal constraints (
add_orthogonal_feature→add_gradient_orthogonal_constraints). These were built as sparse rows after the setup, socheck_supportedrefused them (add_constraints_to_least_squares), and every fault fell back to cg.With
b = 0an orthogonal constraint is a tangent constraint (gradient · vector = 0), which the core already supports. Now, in a native setup,FiniteDifferenceInterpolator.add_gradient_orthogonal_constraintskeeps the points, the vectors and the weight as raw data (_native_orthogonal, cleared byreset), and_native._add_datagives them to the core withadd_tangent. A constraint withb != 0still builds rows, so the check still refuses it.2. The native iteration limit follows the grid
The core stops after 5000 iterations by default.
cg(scipy) allows 10 × the number of unknowns. On a grid of 87 232 nodes the native solve stopped at 5000 iterations with a residual of 1.2e-6. Now, withoutmaxiterinsolver_kwargs,_core_settingsuses 10 ×n_nodes. With it the same model converged in 7442 iterations (4.6 s).3. No stale field after a solve that does not converge
When a native solve did not converge,
ckept its old value. If the grid changed after the last solve (for example a new number of elements), the oldchad the old size, the builder still marked the feature as built, and the surfaces failed withcannot assign 51000 vlaues to array of shape 87232. Now, if the oldcis missing, only NaN, or from another grid,cgets the partial field (as the matrix solvers do). A valid old field of the same grid is still kept, as before.Tests
packages/loop_interpolation/tests/test_native_orthogonal_and_limits.py: orthogonal constraints are kept as raw data and give the same field as cg (within 1e-4 of the range);b != 0is still refused; the default limit; a non-converged solve replaces a field of another grid and keeps a field of this grid.tests/unit/modelling/test_native_fault_frame.py: all three coordinates of a fault use native and converge, and the frame matches the cg frame (largest difference 9e-5 of the range). For that fault, native takes 3.7 s and cg 12.5 s.packages/loop_interpolation/tests: 655 passed.tests/unit: 709 passed (with NumPy 2.4; with NumPy 2.5 the 2D tests intest_2d_p1_p2_support.pyfail because ofnp.cross, as noted in feat: allow loop-interpolation 0.2 and add the native extra #381).🤖 Generated with Claude Code