Skip to content

Deferred-update LU and Cholesky with a task executor, and a RandomizedSVD compressor - #96

Merged
maltezfaria merged 11 commits into
mainfrom
lazy-hlu
Nov 20, 2026
Merged

maltezfaria merged 11 commits into
mainfrom
lazy-hlu

Conversation

@maltezfaria

@maltezfaria maltezfaria commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

This PR, made with Claude Code, replaces the hierarchical LU and Cholesky factorizations with deferred-update versions run by a task executor, and adds a randomized SVD compressor. It is breaking (0.3.0).

  • Deferred updates. Updates of a block are accumulated until the block is needed. Each low-rank block of the factors is then compressed once, from the sum of its updates (Börm 2019; same structure as htool's lazy factorization).
  • Task executor. ThreadsExecutor runs each piece of work once the blocks it depends on are ready; SerialExecutor runs the same code sequentially. The assembly also uses it.
  • Compression.
    • New RandomizedSVD compressor, the default of lu and cholesky.
    • Truncation is in the Frobenius norm.

Breaking changes

  • lu(H; …)/cholesky(H; …) use RandomizedSVD. Pass lu(H, PartialACA(; atol)) for the ACA.
  • ldiv!/rdiv! with an HMatrix right-hand side and a compressor, and compress!(::HMatrix, comp), are removed.
  • Errors from threaded runs are rethrown unwrapped.
  • cholesky rejects a lower-stored Hermitian.
  • New dependency on Random.

Also:

  • ThreadsExecutor/SerialExecutor are public.
  • H + λI works for a Hermitian H.
  • An early ArgumentError for non-scalar entries.
  • Fewer allocations in solves and products.
  • Docs updated: a threads section, and the reference split into public and internal pages.

…a RandomizedSVD compressor

- An `RkMatrix` records which of its factors have orthogonal columns and estimates of
  its truncation errors (Frobenius norm). Assigning a factor resets them, and
  `_modified_factor!` updates them after an in-place change of one factor.
- `PartialACA` recompresses its result with a truncated SVD by default
  (`recompress = true`). `TSVD` and the recompression drop the trailing singular values
  whose Frobenius norm is below `max(atol, rtol*norm)`.
- New public compressor `RandomizedSVD(; atol, rtol, rank, block = 4)`: a range finder
  using Householder QR on blocks of Gaussian samples, stopped by the estimated
  Frobenius error, then a truncated SVD. It only needs products with the block and its
  adjoint.
- New dependency on the `Random` standard library.
`ThreadsExecutor` runs pieces of work as tasks, each waiting only for the last writer of
each object it reads or writes. It assumes the access pattern of the drivers: an object
is written by pieces of work spawned in order, and read once final. A read of an internal
block of an `HMatrix` waits for a join over the writers of its leaves. With
`check_accesses = true`, the executor checks this pattern. `SerialExecutor` runs the
work immediately.

- `wait` rethrows the first error of a piece of work as is.
- `_run!` waits for the spawned work even when the driver throws.
- `workspaces`/`with_workspace` is a pool that never blocks.
- CI runs the tests on 4 threads.
…he executor

Every update of a block is deferred until the block is factorized, solved for or
flushed, so that each admissible leaf is compressed once, from its data plus the sum of
its updates. This is the accumulator of Börm (2019), following the lazy factorization of
htool.
- The node owes a set of products, and carries the exact low-rank terms evaluated
  for the leaves below it.
- An admissible leaf is compressed through a `LeafOperator`, from its products with
  blocks of vectors, by `RandomizedSVD` (the default) or any other compressor.
- `LazyDriver` does the structural work; the numeric work (low-rank terms, flushes,
  dense factorizations and solves of the leaves) goes to the executor.

API:
- `lu`/`lu!` and `cholesky`/`cholesky!` replace the eager factorizations. They take a
  compressor, or `atol`, `rtol`, `rank` and `block` for a `RandomizedSVD`, and run on
  threads with `threads = true` (the default).
- The methods taking a compressor or cluster trees also accept an `executor`.
  `ThreadsExecutor` and `SerialExecutor` are public.
- `assemble_hmatrix` assembles the leaves through the executor, with workspaces taken
  from a pool.
- The H-matrix products and solves with a compressor become the internal `hmul!`,
  `hldiv!` and `hrdiv!`. `ldiv!(L, X::HMatrix, comp)` and `rdiv!(X::HMatrix, U, comp)`
  are removed.

Fixes and cleanup:
- The `Hermitian` wrappers keep their `uplo`, so a lower-stored `Hermitian` works in
  `Matrix`, `mul!` and `hmul!`. `cholesky!` rejects one with an `ArgumentError`.
- `H + λI` with a real `λ` keeps a `Hermitian` `H` Hermitian.
- Non-scalar entries raise an `ArgumentError` before a factorization or product starts.
- Triangular solves with vectors and the serial products in the ordering of the trees
  reuse one scratch vector per call instead of allocating for each low-rank leaf.
- Removed `compress!(::HMatrix, comp)` and `*(::Number, ::RkMatrix)`, which had no
  caller.
…and internal pages

- The guide describes the factorizations (each low-rank block compressed once, by a
  randomized SVD by default), the Cholesky factorization of a `Hermitian` and its
  shifts, and the recompression of the assembly.
- A new section on threads: BLAS on a single thread, `threads = false` for full
  backtraces, and the executors.
- The reference page holds the public API. The internals have two pages of their own,
  each below Documenter's size warning.
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.23633% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.13%. Comparing base (dd9c667) to head (0158098).

Files with missing lines Patch % Lines
src/multiplication.jl 93.93% 6 Missing ⚠️
src/thread_executor.jl 97.97% 2 Missing ⚠️
src/hmatrix.jl 96.15% 1 Missing ⚠️
src/triangular.jl 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #96      +/-   ##
==========================================
+ Coverage   90.08%   93.13%   +3.05%     
==========================================
  Files          13       15       +2     
  Lines        1351     1588     +237     
==========================================
+ Hits         1217     1479     +262     
+ Misses        134      109      -25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…-hosted runners

- The workflow uses the AirspeedVelocity action on `ubuntu-latest` with 4 threads, for
  pull requests labeled `run benchmark` from branches of this repository. It runs the
  pull request's script on both revisions and posts the ratios as a comment.
- The suite defines its own kernel (single layer on a Fibonacci sphere), and no longer
  depends on the test utilities or LoopVectorization.
- It covers the compressors on one block, then assembly, `mul!`, `lu`, `cholesky` and
  solves, serial and threaded. It only calls functions that exist on both revisions.
- `HMATRICES_BENCHMARK_BLAS` loads another BLAS (e.g. AppleAccelerate) for local runs.
@maltezfaria maltezfaria added the run benchmark Trigger the `BenchmarkCI.jl` action label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Benchmark Results (Julia v1)

Time benchmarks
main 0158098... main / 0158098...
Helmholtz/lu threads=false 5.07 s 3.23 ± 0.039 s 1.57
Helmholtz/lu threads=true 4.94 s 1.47 ± 0.044 s 3.36
Laplace/assemble threads=false 1.13 ± 0.0022 s 1.14 ± 0.018 s 0.988 ± 0.016
Laplace/assemble threads=true 0.556 ± 0.084 s 0.516 ± 0.013 s 1.08 ± 0.16
Laplace/cholesky threads=false 1.4 ± 0.031 s 1.23 ± 0.064 s 1.14 ± 0.065
Laplace/cholesky threads=true 1.46 ± 0.075 s 0.558 ± 0.015 s 2.62 ± 0.15
Laplace/lu threads=false 2.81 ± 0.025 s 2.52 ± 0.037 s 1.12 ± 0.019
Laplace/lu threads=true 2.81 ± 0.056 s 1.11 ± 0.042 s 2.54 ± 0.11
Laplace/mul! threads=false 29.9 ± 0.69 ms 31 ± 0.87 ms 0.964 ± 0.035
Laplace/mul! threads=true 14.9 ± 1.8 ms 14.4 ± 0.35 ms 1.04 ± 0.13
Laplace/solve 30.9 ± 0.49 ms 26.2 ± 0.61 ms 1.18 ± 0.033
compressors/PartialACA 0.378 ± 0.014 ms 0.385 ± 0.015 ms 0.981 ± 0.053
compressors/TSVD 0.283 ± 0.0017 s 0.282 ± 0.0087 s 1 ± 0.032
compressors/RandomizedSVD 11.5 ± 0.38 ms
time_to_load 0.443 ± 0.0018 s 0.459 ± 0.0095 s 0.965 ± 0.02
Memory benchmarks
main 0158098... main / 0158098...
Helmholtz/lu threads=false 3.31 M allocs: 2.04 GB 0.4 M allocs: 0.77 GB 2.65
Helmholtz/lu threads=true 3.31 M allocs: 2.04 GB 0.629 M allocs: 0.812 GB 2.51
Laplace/assemble threads=false 0.143 M allocs: 0.444 GB 0.169 M allocs: 0.447 GB 0.992
Laplace/assemble threads=true 0.143 M allocs: 0.449 GB 0.306 M allocs: 0.462 GB 0.973
Laplace/cholesky threads=false 2.51 M allocs: 0.905 GB 0.425 M allocs: 0.331 GB 2.74
Laplace/cholesky threads=true 2.51 M allocs: 0.905 GB 0.738 M allocs: 0.369 GB 2.45
Laplace/lu threads=false 4.14 M allocs: 1.75 GB 0.762 M allocs: 0.629 GB 2.77
Laplace/lu threads=true 4.14 M allocs: 1.75 GB 1.24 M allocs: 0.687 GB 2.54
Laplace/mul! threads=false 8.69 k allocs: 1.48 MB 12 allocs: 0.459 MB 3.23
Laplace/mul! threads=true 8.76 k allocs: 2.5 MB 0.084 k allocs: 1.48 MB 1.69
Laplace/solve 8.69 k allocs: 1.05 MB 16 allocs: 0.46 MB 2.28
compressors/PartialACA 0.06 k allocs: 0.681 MB 0.065 k allocs: 0.682 MB 0.999
compressors/TSVD 27 allocs: 0.045 GB 29 allocs: 0.045 GB 1
compressors/RandomizedSVD 0.101 k allocs: 8.3 MB
time_to_load 0.2 k allocs: 11.7 kB 0.2 k allocs: 11.7 kB 1

maltezfaria and others added 5 commits November 3, 2026 18:38
`PartialACA` no longer recompresses by default (`recompress = false`), so the assembly
is as fast as on main; `recompress = true` lowers the ranks at the cost of a QR
factorization of each factor. The factorizations keep `RandomizedSVD` as their default,
which ends with a truncated SVD.
The docstrings are reached from the narrative pages through cross-references, so the
public and internal ones are listed together again, on a single page which says that
names neither exported nor declared `public` are internal. This removes the filters
of `make.jl` and the lists of source files of the internals pages. Documenter 1.9 is
the first version whose `@autodocs` recognizes `public` names.
… 1.x

With `HMatrices = {path = ".."}` in `[sources]`, `julia --project=docs docs/make.jl`
uses the local checkout without a `Pkg.develop` step. The compat on Documenter allows
any 1.x release, so that the latest one is used.
- actions to their latest majors: checkout v7, setup-julia v3, cache v3,
  codecov-action v7 (supersedes dependabot #88 and #90)
- test job: a timeout, and `actions: write` so that the cache action can
  delete its old caches
- docs job: julia-docdeploy alone instantiates docs/ and builds; the
  separate environment setup, buildpkg and doctest steps were redundant
  (makedocs runs the doctests and fails on a broken one)
- Runic: a job in CI through fredrikekre/runic-action, which checks every
  Julia file, replacing FormatCheck.yml
- CompatHelper: the workflow CompatHelper recommends (v3 pinned, General
  through Git, explicit permissions)
@maltezfaria
maltezfaria marked this pull request as ready for review November 19, 2026 17:28
@maltezfaria
maltezfaria merged commit 5827f29 into main Nov 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run benchmark Trigger the `BenchmarkCI.jl` action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant