hpfracc.algorithms — architecture, dependencies, and maintenance
This note complements CONTRIBUTING.md (numerical integrity, canonical engines), the Development Guide, SPECIAL_ARCHITECTURE.md, VALIDATION_ARCHITECTURE.md, and SOLVERS_ARCHITECTURE.md. It describes how the algorithms package is layered, how it talks to core / special, known risks, and how to refresh coverage numbers.
1. Design goals
Single numerical path for classical fractional derivatives (Riemann–Liouville, Caputo, Grünwald–Letnikov):
algorithms/derivatives.py+algorithms/impls/*.Explicit behaviour under numerical stress: warnings, NaN where appropriate, optional strict mode (see README “Failure over Falsity”).
Legacy grid integrals (
integral_methods.py) remain a supported alternate API, clearly documented vshpfracc.core.integrals.Research extensions (advanced / novel / special operators) live in larger modules without diluting the canonical three-operator path.
2. Layered layout (mental model)
Layer |
Modules |
Responsibility |
|---|---|---|
A — Canonical engines |
|
Backend dispatch, finite checks, RL/Caputo/GL kernels. |
B — Compatibility shims |
|
|
C — Legacy grid integrals |
|
FFT / direct / adaptive RL & Caputo integrals on uniform samples; delegates to |
D — Extended operators |
|
Weyl, Marchaud, Hadamard, Reiz–Feller, Adomian; CF/AB; Laplacian, FrFT, Z/Mellin, etc. (legacy import path |
E — Legacy base |
|
|
3. Dependency diagram (read-only edges)
Intended import direction: core.definitions and special are foundations; fractional_implementations consumes algorithms; algorithms must not import core.derivatives at module top level (avoid cycles).
flowchart TB
subgraph foundations["Foundations"]
DEF["core.definitions"]
SPEC["special (gamma, binomial, …)"]
end
subgraph algorithms_pkg["hpfracc.algorithms"]
BASE["base.FractionalOperator"]
DISP["dispatch.BackendDispatcher"]
IMPL["impls: numpy / jax / cuda"]
DER["derivatives.UnifiedFractionalOperator\nRiemannLiouville, Caputo, GrunwaldLetnikov"]
OPT["optimized_methods\n(engines + GPU-named shims)"]
INT["integral_methods"]
ADV["advanced_methods"]
NOV["novel_derivatives"]
SPM["fractional_operator_methods"]
end
subgraph core_pkg["hpfracc.core (consumers)"]
FI["fractional_implementations"]
CI["core.integrals"]
end
DEF --> DER
DEF --> INT
DEF --> ADV
DEF --> NOV
DEF --> SPM
SPEC --> IMPL
SPEC --> INT
SPEC --> ADV
SPEC --> SPM
BASE --> DER
DISP --> DER
IMPL --> DER
DER --> OPT
INT --> CI
FI --> DER
FI --> INT
FI --> ADV
FI --> NOV
FI --> SPM
4. Naming: engines vs parallel advanced operators
In
optimized_methods.py:OptimizedRiemannLiouville(etc.) are aliases of the unified RL/Caputo/GL classes inderivatives.py(same numerical engines, convenience names).In
advanced_methods.py: canonical parallel subclasses areParallelWeylDerivative,ParallelMarchaudDerivative, and siblings. Deprecated aliasesOptimizedWeylDerivative = ParallelWeylDerivative(etc.) remain for old code; they are not the RL/CaputoOptimized*family. Theoptimized_*_derivativecallables emitDeprecationWarningand delegate toparallel_*_derivative.
When refactoring or searching, qualify: “Optimized engines (optimized_methods)”* vs “Parallel / legacy Optimized advanced (advanced_methods)”**.
5. Risk register and mitigations
Risk |
Mitigation (status) |
|---|---|
Legacy |
Documented in |
Deprecated |
Centralized in |
|
Fixed: linear |
|
Canonical module for Laplacian / FrFT / Z–Mellin-style algorithm tooling, distinct from |
Coverage uneven on D-layer |
Use commands below before large edits; add tests with the same PR when behaviour changes. |
6. Refreshing coverage (algorithms-focused)
From the repo root, with dev extras installed (pip install -e ".[dev]"):
python -m pytest tests/test_algorithms/ \
--cov=hpfracc \
--cov-report=term-missing:skip-covered \
-q
Use --cov=hpfracc, not only hpfracc.algorithms: on some Windows/JAX/pytest-cov combinations, restricting coverage to the subpackage can trigger a partially initialized jax error during collection (import tracing order). Measuring the whole package and reading the hpfracc\algorithms\... rows avoids that while still exercising the algorithms test tree.
Optional HTML report:
python -m pytest tests/test_algorithms/ --cov=hpfracc --cov-report=html:htmlcov_algorithms -q
Note: CI’s main workflow often runs a slice of tests, not all of tests/test_algorithms/; a green PR job does not replace a local --cov pass before risky algorithm changes.
Representative snapshot (2026-04-14, tests/test_algorithms/, --cov=hpfracc)
Module |
Stmts |
Miss |
Cover |
|---|---|---|---|
|
5 |
0 |
100% |
|
361 |
127 |
65% |
|
70 |
28 |
60% |
|
115 |
43 |
63% |
|
25 |
10 |
60% |
|
58 |
48 |
17% |
|
79 |
8 |
90% |
|
66 |
58 |
12% |
|
187 |
23 |
88% |
|
189 |
54 |
71% |
|
— |
— |
includes deprecated |
|
658 |
386 |
41% |
Reading: integral_methods and optimized_methods (including deprecated GPU-named shims) are well hit by this folder. numpy_backend stays low when JAX wins backend="auto" on typical sizes; cuda_backend stays low without GPU. fractional_operator_methods has moderate line coverage here; add tests when you change behaviour, without assuming a future file split.
† optimized_methods.py row: refresh stmt/miss/% with pytest tests/test_algorithms/ --cov=hpfracc (whole package). Restricting --cov to hpfracc.algorithms only can trigger a partially initialized jax error on some Windows/pytest-cov import orders.