Skip to content

Conversation

@bobmyhill
Copy link
Member

This pull request improves the robustness of the nonlinear solver in burnman/optimize/nonlinear_solvers.py by adding explicit handling and reporting for singular and ill-conditioned Jacobian matrices during optimization. It introduces new termination codes and messages for these cases, updates the solver logic to detect and respond to singularities, and adds tests to verify correct behaviour in edge cases.

Solver robustness and singularity handling:

  • Added a max_condition_number threshold and logic to detect when the Jacobian is effectively singular, triggering new termination codes and descriptive messages for both failure (code 4) and successful convergence under singular conditions (code 5). (burnman/optimize/nonlinear_solvers.py) [1] [2] [3] [4] [5] [6] [7]
  • Updated _termination_info to receive the Jacobian condition number and differentiate between normal convergence, singular convergence, and failure due to singularity while violating constraints. (burnman/optimize/nonlinear_solvers.py) [1] [2]
  • Improved documentation of solver termination codes and results, describing new singularity-related codes and their meanings. (burnman/optimize/nonlinear_solvers.py)

Testing and validation:

  • Added three new tests to tests/test_equilibration.py to verify solver behaviour for: (1) convergence with a singular system, (2) ill-posed problems that leave the feasible region, and (3) detection of an ill-conditioned Jacobian. (tests/test_equilibration.py)

Minor code cleanup:

  • Removed unused namedtuple import from burnman/optimize/nonlinear_solvers.py

@bobmyhill bobmyhill requested a review from Copilot October 15, 2025 22:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the nonlinear solver's robustness by adding explicit detection and handling of singular and ill-conditioned Jacobian matrices during optimization. The solver now identifies when mathematical singularity prevents reliable convergence and provides clear diagnostic messages to users.

Key changes:

  • Introduced condition number threshold checking and new termination codes (4 and 5) to distinguish singular system failures from normal convergence
  • Updated solver logic to compute and track Jacobian condition numbers, preventing final adjustments when singularity is detected
  • Added three test cases validating solver behavior with singular systems, ill-posed problems, and ill-conditioned Jacobians

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
burnman/optimize/nonlinear_solvers.py Added max_condition_number threshold, condition number parameter to _termination_info, singularity detection logic, and new termination codes 4 and 5 with descriptive messages
tests/test_equilibration.py Added three tests verifying correct termination codes for singular convergence (code 5), infeasible region exit (code 2), and singular system failure (code 4)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bobmyhill bobmyhill force-pushed the test_singular_jacobians branch 4 times, most recently from d0ef05d to d1c3abb Compare October 15, 2025 23:02
@bobmyhill bobmyhill force-pushed the test_singular_jacobians branch 2 times, most recently from 7ec64c3 to 30024cd Compare October 16, 2025 10:15
@bobmyhill bobmyhill force-pushed the test_singular_jacobians branch from 30024cd to c45108a Compare October 16, 2025 10:38
@bobmyhill bobmyhill requested a review from Copilot October 16, 2025 10:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bobmyhill
Copy link
Member Author

@bjheinen some of the logic we discussed on Tuesday is implemented here. Thanks!

@bobmyhill bobmyhill merged commit 046b87f into geodynamics:main Oct 16, 2025
12 checks passed
@bjheinen
Copy link
Contributor

@bobmyhill Looks good! With these extra tests and the check for is_singular at the start of the solve() loop I would be tempted again to see if moving the conditional regularisation to this stage would help convergence in near-singular cases (i.e. before computing luJ)

@bobmyhill bobmyhill deleted the test_singular_jacobians branch October 16, 2025 11:24
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