hpfracc.utils โ architecture, dependencies, and maintenance๏
This note complements CONTRIBUTING.md, ALGORITHMS_ARCHITECTURE.md, SPECIAL_ARCHITECTURE.md, ANALYTICS_ARCHITECTURE.md, BENCHMARKS_ARCHITECTURE.md, VALIDATION_ARCHITECTURE.md, and SOLVERS_ARCHITECTURE.md. It describes utility modules (errors, memory/cache, plotting), import coupling, and tests.
1. Design goals๏
Validation-oriented helpers without pulling numerical engines:
ErrorAnalyzer,ConvergenceRateAnalyzer(deprecated aliasConvergenceAnalyzer), andValidationFrameworksupport benchmarks and analytical checks.Lightweight default import:
import hpfracc.utilsloads error analysis and memory management only; plotting (Matplotlib) loads on first use of a plot symbol (see ยง3).Clear boundaries:
utilsdoes not importalgorithms,core, orml; validation may importutils.error_analysis.
2. Module layout๏
File |
Responsibility |
|---|---|
|
|
|
|
|
|
|
Re-exports public API; lazy attribute access for plotting symbols so |
3. Lazy plotting surface (__init__.py)๏
These names resolve via __getattr__ and import plotting only when first accessed:
PlotManager, create_comparison_plot, plot_convergence, plot_error_analysis, save_plot, setup_plotting_style.
Prefer for analysis-only code:
from hpfracc.utils.error_analysis import ErrorAnalyzer
from hpfracc.utils.memory_management import MemoryManager
Use from hpfracc.utils import PlotManager (or other plot symbols) when figures are required; first access pays the Matplotlib import cost.
4. Upstream coupling๏
Consumer |
Typical import |
|---|---|
|
|
Tests / examples |
Package or submodule imports; plotting tests often |
No reverse edges from utils into validation at import time.
5. Dependencies and risks๏
Dependency |
Where |
Note |
|---|---|---|
NumPy |
All three modules |
Required. |
psutil |
|
Process/virtual memory stats; project already lists psutil for analytics. |
Matplotlib |
|
Heavy; keep behind lazy package exports (ยง3). |
Optional / tests |
Torch tensors in |
Best-effort |
Risk |
Mitigation |
|---|---|
|
|
Stale unittest paths ( |
Use real submodule paths: |
6. Tests๏
tests/test_utils/โ expanded and coverage-oriented tests (often patchplt).tests/test_utils.py,tests/utils/โ additional smoke paths.tests_unittest/test_utils.pyโ lightweight unittest smoke aligned with the actual public API.
python -m pytest tests/test_utils/ tests/test_utils.py tests_unittest/test_utils.py -q