ordito.cholesky
Sparse Cholesky factorization of symmetric positive-(semi-)definite operators, solved on the device.
sparse_cholesky orders the operator by nested dissection,
factors it level by level on the device and returns a
SparseCholesky whose
solve is a fixed sequence of matrix-vector products,
recorded once and replayed. Where a Krylov solver's cost grows with the operator's condition number
and with the distance information must travel across the mesh, a factorization's does not: one
factor serves every later right-hand side and every operator of the same sparsity
(refactor).
Every solve is refined against the operator itself until its residual passes the requested test, unless the caller asks for one solve against the factor alone. A solution spanning hundreds of orders of magnitude -- the heat method's diffusions -- can be solved componentwise, each entry to its own size, which no iteration controlled by a residual norm achieves: on an M-matrix the factor and both triangular solves add terms of one sign, so no entry is formed by cancellation.
A component of the operator's graph whose rows all sum to zero (a Laplacian's constant null space) is solved up to that constant, which is then set to the initial guess's mean: the answer conjugate gradient gives from the same guess on a consistent right-hand side.
Notes
The ordering is geometric nested dissection when vertex coordinates are given and the same bisection over breadth-first distances from three mutually far vertices otherwise. Rows of 1 024 entries or more (a fan's hub) take no part in the bisection and are eliminated last, so a vertex whose neighbours span the mesh does not turn every separator into half of them. The numeric factorization is multifrontal (Liu 1992); each supernode stores the inverse of its diagonal block and the product of that inverse with its off-diagonal rows, so both triangular solves are level-scheduled products with no substitution inside a level (the partitioned inverse of Alvarado, Pothen and Schreiber 1993). Every partial sum lands in its own slot and is reduced in a fixed order, so solves are reproducible on both devices.
Classes:
| Name | Description |
|---|---|
NotPositiveDefiniteError |
The operator met a pivot that is not positive: it is not definite, at least in |
SparseCholesky |
A sparse Cholesky factorization on the device. |
Functions:
| Name | Description |
|---|---|
sparse_cholesky |
Sparse Cholesky factorization of a symmetric positive-(semi-)definite |
held_nbytes |
Device memory several factorizations hold together, in bytes: a shared analysis counted once. |
factorization_nbytes |
Peak device memory |
CHOLESKY_LEAF_ROWS
module-attribute
CHOLESKY_LEAF_ROWS = 32
Referenced by 1 place
API Reference cholesky › sparse_cholesky
CHOLESKY_TOP_ROWS
module-attribute
CHOLESKY_TOP_ROWS = 512
Referenced by 1 place
API Reference cholesky › sparse_cholesky
CHOLESKY_MEMORY_BUDGET
module-attribute
CHOLESKY_MEMORY_BUDGET = 4 << 30
Referenced by 16 places
API Reference HeatSolver › factor · heat › heat_geodesic · cholesky › SparseCholesky · SparseCholesky › with_expanded_operator · cholesky › factorization_nbytes · cholesky › sparse_cholesky · OperatorFactorization › exceeds_budget · OperatorFactorization › factor · linalg › min_quad_with_fixed · linalg › min_quad_with_fixed_precompute · linalg › solve_spd_settled · parametrization › FixedVertexSolver · FixedVertexSolver › factor · parametrization › arap · parametrization › slim · parametrization › slim_parametrization
CHOLESKY_REFINE_ROUNDS
module-attribute
CHOLESKY_REFINE_ROUNDS = 12
Referenced by 1 place
API Reference SparseCholesky › solve
NotPositiveDefiniteError
Bases: ValueError
The operator met a pivot that is not positive: it is not definite, at least in float64.
Raised by sparse_cholesky and
SparseCholesky.refactor; a ValueError, so a
caller catching that sees it too. Distinct from the operator being too large to factor, which
an iteration may still solve: a symmetric operator this cannot factor either way round is past
what conjugate gradient converges on as well.
Examples:
A cotangent Laplacian is negative semi-definite, so factoring it as given fails:
import warp as wp
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
L = od.laplacian.cotmatrix(vertices, faces, dtype=wp.float64)
try:
od.cholesky.sparse_cholesky(L)
outcome = "factored"
except od.cholesky.NotPositiveDefiniteError:
outcome = "not positive definite"
print(outcome) # not positive definite
Raised by 4 places
API Reference SparseCholesky › refactor · SparseCholesky › with_expanded_operator · SparseCholesky › with_operator · cholesky › sparse_cholesky
SparseCholesky
SparseCholesky(
plan: _Plan,
matrix: BsrMatrix[float64],
*,
negated: bool,
)
A sparse Cholesky factorization on the device.
Built by sparse_cholesky.
Attributes:
| Name | Type | Description |
|---|---|---|
n |
int
|
Rows of the factored operator. |
device |
Device
|
Device the factor lives on. |
nbytes |
int
|
Device memory the factorization holds, in bytes: its analysis (shared with every
factorization |
negated |
bool
|
Whether |
expandable |
bool
|
Whether the analysis was built for
|
records_at_once |
bool
|
Whether a solve records its refinement graph on its first run (a factorization solved many times), rather than on its second against the same operator storage (the default: a one-shot solve then runs its rounds directly and records nothing). |
Examples:
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
system = od.heat.heat_operators(vertices, faces)[0] # M - t L, float64
factor = od.cholesky.sparse_cholesky(system, vertices)
print(factor.n, factor.negated, factor.nbytes > 0) # 162 False True
Factor matrix (or its negation) over plan's structure.
Referenced by 3 places
API Reference cholesky · cholesky › held_nbytes · cholesky › sparse_cholesky
Returned by 3 places
API Reference SparseCholesky › with_expanded_operator · SparseCholesky › with_operator · cholesky › sparse_cholesky
Used by 1 place
API Reference cholesky › held_nbytes
Methods:
| Name | Description |
|---|---|
refactor |
Factor a new operator of the same sparsity pattern in place. |
with_operator |
Factor another operator of this one's sparsity pattern, sharing this analysis. |
with_expanded_operator |
Factor an operator over this pattern's 2 x 2 block expansion, deriving its analysis. |
solve |
Solve the factored system for one or several right-hand sides, refined in |
Source code in ordito/cholesky.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
negated
instance-attribute
negated = negated
expandable
instance-attribute
expandable = plan.granularity == 2
records_at_once
instance-attribute
records_at_once = False
n
instance-attribute
n = plan.n
device
instance-attribute
device = plan.device
nbytes
instance-attribute
nbytes = plan.nbytes + _numeric_nbytes(
plan.n, plan.block_entries
)
refactor
refactor(matrix: BsrMatrix[float64]) -> None
Factor a new operator of the same sparsity pattern in place.
If the new operator is not positive definite, the factorization holds no usable factor
afterwards: solve raises until a later
refactor succeeds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
BsrMatrix[float64]
|
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
NotPositiveDefiniteError
|
If the operator is not positive definite on its non-singular components (a pivot that is not positive). |
RuntimeError
|
If |
Examples:
The heat system at another diffusion time has the same pattern, so the analysis is reused:
import warp as wp
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
factor = od.cholesky.sparse_cholesky(od.heat.heat_operators(vertices, faces, t=0.01)[0])
factor.refactor(od.heat.heat_operators(vertices, faces, t=0.1)[0])
mass = od.laplacian.mass_matrix_entries(vertices, faces, dtype=wp.float64)
solution = wp.zeros_like(mass)
factor.solve(mass, solution) # (M - t L) 1 = M 1
print(f"{solution.numpy().min():.6f} {solution.numpy().max():.6f}") # 1.000000 1.000000
Referenced by 7 places
API Reference cholesky · cholesky › NotPositiveDefiniteError · cholesky › SparseCholesky · SparseCholesky › solve · SparseCholesky › with_expanded_operator · SparseCholesky › with_operator · cholesky › sparse_cholesky
Source code in ordito/cholesky.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
with_operator
with_operator(
matrix: BsrMatrix[float64],
*,
negated: bool | None = None,
) -> SparseCholesky
Factor another operator of this one's sparsity pattern, sharing this analysis.
Only the numeric factorization is paid: the ordering and every structure map are this factorization's, held by both. The two factorizations are independent otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
BsrMatrix[float64]
|
|
required |
negated
|
bool | None
|
As |
None
|
Returns:
| Type | Description |
|---|---|
SparseCholesky
|
The new factorization. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
NotPositiveDefiniteError
|
If the operator (with |
RuntimeError
|
If |
Examples:
Two diffusion times, one analysis, two independent factorizations:
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
short = od.cholesky.sparse_cholesky(od.heat.heat_operators(vertices, faces, t=0.01)[0])
long = short.with_operator(od.heat.heat_operators(vertices, faces, t=0.1)[0])
print(long is short, long.n) # False 162
Referenced by 2 places
API Reference cholesky › SparseCholesky · cholesky › held_nbytes
Source code in ordito/cholesky.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
with_expanded_operator
with_expanded_operator(
matrix: BsrMatrix[float64],
*,
negated: bool | None = None,
) -> SparseCholesky
Factor an operator over this pattern's 2 x 2 block expansion, deriving its analysis.
matrix is a wp.mat22d operator stored over this factorization's pattern, as
scalar_expansion presents it: unknown i becomes
unknowns 2 * i and 2 * i + 1. Those two are eliminated one after the other where
i was, so the expansion's analysis is this one's with every supernode and every row of
its structure doubled: no ordering or symbolic analysis of its own is run. The new
factorization holds its own analysis, and is independent of this one otherwise. Its
supernodes are twice this one's: as fine as an analysis of the expansion's own when this
one was built expandable (see sparse_cholesky),
coarser, with more fill, otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
BsrMatrix[float64]
|
|
required |
negated
|
bool | None
|
As |
None
|
Returns:
| Type | Description |
|---|---|
SparseCholesky
|
The factorization of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
NotPositiveDefiniteError
|
If the operator (with |
RuntimeError
|
If |
Examples:
The vector heat system is stored over the scalar heat system's pattern, by blocks:
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
vector_system, scalar_operators = od.heat.vector_heat_operators(vertices, faces)[:2]
heat = od.cholesky.sparse_cholesky(scalar_operators[0], vertices, expandable=True)
tangent = heat.with_expanded_operator(od.array.scalar_expansion(vector_system))
print(heat.n, tangent.n) # 162 324
Referenced by 3 places
API Reference cholesky › SparseCholesky · cholesky › sparse_cholesky · OperatorFactorization › factor
Source code in ordito/cholesky.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
solve
solve(
rhs: ArrayNd,
solution: ArrayNd,
*,
tol: float = 1e-12,
componentwise: bool = False,
refine: bool = True,
) -> None
Solve the factored system for one or several right-hand sides, refined in float64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
ArrayNd
|
|
required |
solution
|
ArrayNd
|
Same shape as |
required |
tol
|
float
|
Refinement stops once every row's residual passes the backward-error test
|
1e-12
|
componentwise
|
bool
|
Refine every entry to its own size: for solutions spanning many orders of magnitude. |
False
|
refine
|
bool
|
|
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
Examples:
Two right-hand sides solved together: (M - t L) c = c M 1 for a constant c:
import numpy as np
import warp as wp
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
factor = od.cholesky.sparse_cholesky(od.heat.heat_operators(vertices, faces)[0], vertices)
mass = od.laplacian.mass_matrix_entries(vertices, faces, dtype=wp.float64).numpy()
rhs = wp.array(np.stack([mass, 2.0 * mass]), dtype=wp.float64)
solution = wp.zeros_like(rhs)
factor.solve(rhs, solution)
print(solution.numpy().mean(axis=1).round(6)) # [1. 2.]
Referenced by 4 places
API Reference cholesky · SparseCholesky › refactor · cholesky › sparse_cholesky · OperatorFactorization › solve
Source code in ordito/cholesky.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
sparse_cholesky
sparse_cholesky(
matrix: BsrMatrix[float64],
coordinates: array[vec3] | None = None,
*,
negated: bool | None = False,
expandable: bool = False,
) -> SparseCholesky
Sparse Cholesky factorization of a symmetric positive-(semi-)definite float64 operator.
Orders the operator by nested dissection, factors it on the device and returns the
factorization, whose solve answers any later
right-hand side in a fixed number of device passes. The ordering and the symbolic analysis run
on the device too, reading back a few small counts per level of the dissection. The analysis
belongs to the returned factorization: refactor
reuses it for another operator of the same pattern, and nothing is kept across calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
BsrMatrix[float64]
|
|
required |
coordinates
|
array[vec3] | None
|
|
None
|
negated
|
bool | None
|
Factor |
False
|
expandable
|
bool
|
Order with leaves and merged tops of half
|
False
|
Returns:
| Type | Description |
|---|---|
SparseCholesky
|
The factorization, on |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
NotPositiveDefiniteError
|
If the operator is not positive definite (with |
RuntimeError
|
If |
See Also
Examples:
The heat method's system M - t L maps the constant 1 to the lumped masses, since every
row of L sums to zero; solving against the masses recovers it:
import warp as wp
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
system = od.heat.heat_operators(vertices, faces)[0] # M - t L, float64
factor = od.cholesky.sparse_cholesky(system, vertices)
mass = od.laplacian.mass_matrix_entries(vertices, faces, dtype=wp.float64)
solution = wp.zeros_like(mass)
factor.solve(mass, solution)
print(f"{solution.numpy().min():.6f} {solution.numpy().max():.6f}") # 1.000000 1.000000
A cotangent Laplacian is negative semi-definite: negated=None finds the sign, and the
singular constant component is solved up to a constant:
import numpy as np
import warp as wp
import ordito as od
vertices, faces = od.creation.grid(count=(6, 6))
L = od.laplacian.cotmatrix(vertices, faces, dtype=wp.float64)
factor = od.cholesky.sparse_cholesky(L, vertices, negated=None)
print(factor.negated) # True
x = wp.array(vertices.numpy()[:, 0], dtype=wp.float64)
solution = wp.zeros_like(x)
factor.solve(L @ x, solution)
print(np.ptp(solution.numpy() - x.numpy()) < 1e-9) # True
Referenced by 16 places
API Reference cholesky · cholesky › NotPositiveDefiniteError · cholesky › SparseCholesky · SparseCholesky › with_expanded_operator · SparseCholesky › with_operator · cholesky › factorization_nbytes · linalg · linalg › OperatorFactorization · OperatorFactorization › factor · linalg › min_quad_with_fixed · linalg › min_quad_with_fixed_precompute · linalg › solve_spd_settled · linalg › spd_column_solver · parametrization › arap · parametrization › harmonic · parametrization › slim
Source code in ordito/cholesky.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
held_nbytes
held_nbytes(
factorizations: Iterable[SparseCholesky],
) -> int
Device memory several factorizations hold together, in bytes: a shared analysis counted once.
Each factorization's nbytes counts its analysis, which
every factorization built from it by
with_operator holds too; summing nbytes
counts that analysis once a factorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factorizations
|
Iterable[SparseCholesky]
|
The factorizations, each counted once however often it appears. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The bytes of every distinct allocation the factorizations hold. |
Examples:
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=2)
short = od.cholesky.sparse_cholesky(od.heat.heat_operators(vertices, faces, t=0.01)[0])
long = short.with_operator(od.heat.heat_operators(vertices, faces, t=0.1)[0])
together = od.cholesky.held_nbytes([short, long])
print(short.nbytes < together < short.nbytes + long.nbytes) # True
Referenced by 1 place
API Reference cholesky › SparseCholesky
Source code in ordito/cholesky.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |
factorization_nbytes
factorization_nbytes(
matrix: BsrMatrix[float64],
coordinates: array[vec3] | None = None,
) -> int
Peak device memory sparse_cholesky would take, in bytes.
What the factorization holds once built plus the transient arena its first numeric
factorization works in (or a first solve's scratch, when that is larger): the figure
sparse_cholesky compares with
CHOLESKY_MEMORY_BUDGET. Found by the ordering and
the symbolic analysis alone, which stop there, so asking costs most of an analysis and no
factorization, and is answered whatever the budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
BsrMatrix[float64]
|
|
required |
coordinates
|
array[vec3] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
int
|
The bytes; |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
Examples:
import ordito as od
vertices, faces = od.creation.icosphere(subdivisions=3)
system = od.heat.heat_operators(vertices, faces)[0] # M - t L, float64
needed = od.cholesky.factorization_nbytes(system, vertices)
print(needed < od.cholesky.CHOLESKY_MEMORY_BUDGET) # True
Referenced by 1 place
API Reference OperatorFactorization › exceeds_budget
Source code in ordito/cholesky.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |