nlsq.core.profiler¶
Performance profiling for Trust Region Reflective optimization.
Added in version 1.2.0: Extracted from nlsq.core.trf for modularity.
This module provides profiling infrastructure for the TRF optimizer, enabling detailed performance analysis of optimization runs.
Classes¶
TRFProfiler¶
A profiler that records timing information for each phase of TRF optimization:
Jacobian computation time
SVD decomposition time
Trust region step computation
Function evaluation time
Total iteration time
NullProfiler¶
A no-op profiler implementation for production use when profiling overhead is not desired. Implements the same interface as TRFProfiler but does nothing.
Module Contents¶
Profiling utilities for Trust Region Reflective optimization.
This module provides profiling classes for timing TRF algorithm operations, enabling performance analysis and optimization tuning.
- class nlsq.core.profiler.NullProfiler[source]¶
Bases:
objectNull object profiler with zero overhead.
Provides same interface as TRFProfiler but does nothing, enabling profiling to be toggled with no performance impact.
- class nlsq.core.profiler.TRFProfiler[source]¶
Bases:
objectProfiler for timing TRF algorithm operations.
Records detailed timing information for each operation in the TRF algorithm, including GPU synchronization via block_until_ready() for accurate timings.
This enables performance analysis without duplicating the entire algorithm.
- time_operation(operation, jax_result)[source]¶
Time a JAX operation with GPU synchronization.
- Parameters:
operation (str) – Operation name (‘fun’, ‘jac’, ‘svd’, ‘cost’, ‘grad’, etc.)
jax_result – JAX array result to synchronize
- Returns:
The synchronized result (same as input)
- Return type:
result
Usage Example¶
from nlsq.core.profiler import TRFProfiler, NullProfiler
from nlsq.core.trf import TrustRegionReflective
# Enable profiling
profiler = TRFProfiler()
optimizer = TrustRegionReflective(profiler=profiler)
# Run optimization
result = optimizer.optimize(...)
# Get timing statistics
stats = profiler.get_stats()
print(f"Jacobian time: {stats['jacobian_time']:.3f}s")
print(f"SVD time: {stats['svd_time']:.3f}s")
See Also¶
nlsq.trf module - Main Trust Region Reflective optimizer
nlsq.profiling module - General profiling utilities