Repository navigation
Add linear algebra solver architecture with a Preconditioned Conjugate Gradient solver - #77
Open
timchem1508 wants to merge 4 commits into
Open
timchem1508 wants to merge 4 commits into
timchem1508 wants to merge 4 commits into
Conversation
Restructure the charge models around a response cache and pluggable linear algebra solvers, on top of the eeqbc2025 theory of main: - mchrg_model_type separates setup and solution: update() fills mchrg_cache (CN, local charges, capacitance and Coulomb matrices and their derivatives), solve() takes a solver and returns the charges and their Cartesian and strain response; mchrg_cache replaces cache_container - multicharge_solver with the abstract mchrg_solver_type, a direct solver and a Jacobi-preconditioned Conjugate Gradient solver; new_mchrg_solver builds a solver from its input - CG reports non-convergence within the iteration limit and a breakdown on non-positive curvature as errors; the inverse matrix is only computed by the direct solver and only on request - generic dot, scal, axpy and symv wrappers in multicharge_blas - command line: --solver cg|direct, --maxiter, --tolerance, -qg/--qgrad, -v/--verbose, -s/--silent; -v no longer prints the version, use --version - new solver test suite covering convergence failure, breakdown, singular matrices and all verbosity levels; extend the model and pbc tests to the new API
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #77 +/- ##
===========================================
- Coverage 51.57% 24.81% -26.77%
===========================================
Files 18 2 -16
Lines 1648 266 -1382
Branches 746 116 -630
===========================================
- Hits 850 66 -784
+ Misses 390 153 -237
+ Partials 408 47 -361 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…e meson amd cmake files; use the upstream thresholds in the pbc tests.
…m), cache%xvec(:ndim). Refactor solver input handling; replace solver_maker with new_mchrg_solver in tests
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
The cache_container type is reconstructed into one multicharge cache type. The linear system solver type is added to speed-up the charge calculations and adpat the multicharge for futher improvements. Next to the existing direct solver (LAPACK Bunch–Kaufman), it adds a Jacobi-preconditioned Conjugate Gradient (CG) solver. For large systems, CG brings the cost of the linear solve down from O(N³) to O(N²).
Scaling
Application of the PCG solver vs. the direct one on the methane molecules sphere calculations:
The direct solver factorizes the dense (N+1)×(N+1) Coulomb matrix with
sytrf/sytrs, which costs O(N³). Each CG iteration costs one dense matrix–vector product, which is O(N²). With the Jacobi preconditioner the number of iterations stays about the same as the system grows, so the whole solve scales as O(N²). Use the (Nid)×(Nid) van-der-Waals radii matrix instead of the (N)×(N) one to save time and memory.Changes
Model and cache
mchrg_model_typeseparates setup from solution.update()fillsmchrg_cachewith the CN, local charges, capacitance and Coulomb matrices, and their derivatives.solve()takes a solver and returns the charges, energy, gradient and virial, and the charge derivatives.mchrg_cachereplacescache_container.Solvers (
multicharge_solver)mchrg_solver_typeandmchrg_solver_input.new_mchrg_solverbuilds a solver from its input.direct_solver: Bunch–Kaufman factorization of the system that includes the Lagrange multiplier for the total-charge constraint. It computes the inverse (sytri) only when charge derivatives are requested.cg_solver: Jacobi-preconditioned CG. The system with the Lagrange multiplier is indefinite, so CG cannot solve it directly. Instead, CG solves two positive-definite N×N systems,A u = 1andA v = −x, and gets the multiplier from the total-charge constraint. Defaults are 1000 iterations and a relative residual tolerance of 1e-15.Other
dot,scal,axpyandsymvwrappers inmulticharge_blas.--solver cg|direct,--maxiter,--tolerance,-qg/--qgrad,-v/--verboseand-s/--silent. The man page is updated.rvdwinstead of the atomwise to save time and memory.get_chargesandadd_charge_hessianAPIs uses the direct solver at the moment.Behavior changes and limitations
dqdranddqdLneed the inverse matrix, so only the direct solver provides them. Requesting them with CG returns an error. The energy gradient and virial work with both solvers.-vnow means--verbose. Use--versionto print the version.cache_containeris nowmchrg_cache, andsolvetakes a solver argument.Tests
test_solversuite for CG: identity, diagonal, SPD, ill-conditioned and random SPD matrices, zero right-hand side, invalid input, non-convergence, breakdown and verbosity levels. For the direct solver: inverse, singular matrix and verbosity.