Skip to content

Change solver defaults - #941

Open
gertjanvanzwieten wants to merge 10 commits into
mainfrom
solver-defaults
Open

gertjanvanzwieten wants to merge 10 commits into
mainfrom
solver-defaults

Conversation

@gertjanvanzwieten

Copy link
Copy Markdown
Contributor

No description provided.

This patch adds a missing droptol in a boundary constraints projection.
This patch removes the base solver logic that skips the actual solve step if
the residual norm is already below atol. While technically correct, this
behaviour is almost never desired, and may leads to unexpected time series
stagnations and other mysterious failures.
This patch moves the stop criterion of the Arnoldi iterative solver to after
the first iteration. This is related to commit 94bfe85: formerly the Arnoldi
solver would not be invoked if resnorm < atol, but now that it is, we want it
to do at least one solve.
@gertjanvanzwieten
gertjanvanzwieten force-pushed the solver-defaults branch 2 times, most recently from b6169f2 to cd3ffa4 Compare November 19, 2026 15:43
This patch changes the default solver from "arnoldi" to "direct", which is a
more natural default that is faster (doing only one iteration) and should be
fine in the majority of situations that the matrix is well conditioned.
This patch instructs the Newton solver to do at least one iteration by default,
regardless of the residual of the initial guess. This is the nonlinear
equivalent of 94bfe85 and 4826528 that similarly aims to make the default
settings more robust against unexpected stagnations.
@gertjanvanzwieten
gertjanvanzwieten force-pushed the solver-defaults branch 3 times, most recently from 926e550 to 7574fd0 Compare November 19, 2026 21:41
Comment thread src/nutils/matrix/_base.py Outdated
if rhs.shape[0] != self.shape[0]:
raise MatrixError('right-hand size shape does not match matrix shape')
if not self.shape[0]: # 0 x 0 matrix
return numpy.zeros([0])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For real systems this is fine. If the system is complex, lhs as returned below will always be complex, right? Then maybe we should make the zeros complex as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Fixed.

This patch cleans up some solver.System code by introducing an __initargs
attribute that is referenced from both __reduce__ and __nutils_hash__.
This patch adds an explicit copy in System.construct so that the function can
be relied upon to always return a new dictionary.
This patch cleans up the logic by which solver.System evaluates its jacobians,
residuals and values. The caching mechanism is simplified by introducing
_cached_eval, and otherwise caching only constant matrices under key "jac".

This branch has not been deployed

No deployments
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.

2 participants