Genericization and Autodiff #4

Merged
connor merged 4 commits from feature/generic-scalar into main 2026-09-29 18:24:02 -04:00
3 changed files with 61 additions and 56 deletions
Showing only changes of commit db14a02df4 - Show all commits

No files matched your search

+35 -32
View File
@@ -1,17 +1,17 @@
# Vern7 Performance Benchmark Report
**Date**: 2025-10-24
**Test System**: Linux 6.17.4-arch2-1
**Date**: 2026-09-29 (re-measured; first run 2025-10-24)
**Test System**: Linux 7.2.6-arch2-1
**Optimization Level**: Release build with full optimizations
## Executive Summary
Vern7 demonstrates **substantial performance advantages** over lower-order methods (BS3 and DP5) at tight tolerances (1e-8 to 1e-12), achieving:
- **2.7x faster** than DP5 at 1e-10 tolerance (exponential problem)
- **3.8x faster** than DP5 in harmonic oscillator
- **8.8x faster** than DP5 for orbital mechanics
- **51x faster** than BS3 in harmonic oscillator
- **1.65x faster** than DP5 for interpolation workloads
- **2.9x faster** than DP5 at 1e-10 tolerance (exponential problem)
- **4.5x faster** than DP5 in harmonic oscillator
- **9.9x faster** than DP5 for orbital mechanics
- **83x faster** than BS3 in harmonic oscillator
- **2.1x faster** than DP5 for interpolation workloads
These results confirm Vern7's design goal: **maximum efficiency for high-accuracy requirements**.
@@ -23,14 +23,14 @@ These results confirm Vern7's design goal: **maximum efficiency for high-accurac
| Method | Time (μs) | Relative Speed | Speedup vs BS3 |
|--------|-----------|----------------|----------------|
| **Vern7** | **3.81** | **1.00x** (baseline) | **51.8x** |
| DP5 | 10.43 | 2.74x slower | 18.9x |
| BS3 | 197.37 | 51.8x slower | 1.0x |
| **Vern7** | **2.93** | **1.00x** (baseline) | **53.4x** |
| DP5 | 8.36 | 2.85x slower | 18.7x |
| BS3 | 156.63 | 53.4x slower | 1.0x |
**Analysis**:
- Vern7 is **2.7x faster** than DP5 and **51x faster** than BS3
- Vern7 is **2.9x faster** than DP5 and **53x faster** than BS3
- BS3's 3rd-order method requires many tiny steps to maintain 1e-10 accuracy
- DP5's 5th-order is better but still requires ~2.7x more work than Vern7
- DP5's 5th-order is better but still requires ~2.9x more work than Vern7
- Vern7's 7th-order allows much larger step sizes while maintaining accuracy
---
@@ -41,15 +41,15 @@ These results confirm Vern7's design goal: **maximum efficiency for high-accurac
| Method | Time (μs) | Relative Speed | Speedup vs BS3 |
|--------|-----------|----------------|----------------|
| **Vern7** | **26.89** | **1.00x** (baseline) | **55.1x** |
| DP5 | 102.74 | 3.82x slower | 14.4x |
| BS3 | 1,481.4 | 55.1x slower | 1.0x |
| **Vern7** | **19.27** | **1.00x** (baseline) | **82.9x** |
| DP5 | 87.02 | 4.52x slower | 18.4x |
| BS3 | 1,597.5 | 82.9x slower | 1.0x |
**Analysis**:
- Vern7 is **3.8x faster** than DP5 and **55x faster** than BS3
- Vern7 is **4.5x faster** than DP5 and **83x faster** than BS3
- Smooth periodic problems like harmonic oscillators are ideal for high-order methods
- BS3 requires ~1.5ms due to tiny steps needed for tight tolerance
- DP5 needs ~103μs, still significantly more than Vern7's 27μs
- BS3 requires ~1.6ms due to tiny steps needed for tight tolerance
- DP5 needs ~87μs, still significantly more than Vern7's 19μs
- Higher dimensionality (2D vs 1D) amplifies the advantage of larger steps
---
@@ -60,11 +60,11 @@ These results confirm Vern7's design goal: **maximum efficiency for high-accurac
| Method | Time (μs) | Relative Speed | Speedup |
|--------|-----------|----------------|---------|
| **Vern7** | **98.75** | **1.00x** (baseline) | **8.77x** |
| DP5 | 865.79 | 8.77x slower | 1.0x |
| **Vern7** | **66.47** | **1.00x** (baseline) | **9.89x** |
| DP5 | 657.35 | 9.89x slower | 1.0x |
**Analysis**:
- Vern7 is **8.8x faster** than DP5 for this challenging 6D problem
- Vern7 is **9.9x faster** than DP5 for this challenging 6D problem
- Orbital mechanics requires tight tolerances to maintain energy conservation
- BS3 was too slow to include in the benchmark at this tolerance
- 6D problem with long integration time shows Vern7's scalability
@@ -78,17 +78,20 @@ These results confirm Vern7's design goal: **maximum efficiency for high-accurac
| Method | Time (μs) | Relative Speed | Notes |
|--------|-----------|----------------|-------|
| **Vern7** | **11.05** | **1.00x** (baseline) | Lazy extra stages |
| DP5 | 18.27 | 1.65x slower | Standard dense output |
| **Vern7** | **7.36** | **1.00x** (baseline) | Lazy extra stages |
| DP5 | 15.48 | 2.10x slower | Standard dense output |
**Analysis**:
- Vern7 with lazy computation is **1.65x faster** than DP5
- Vern7 with lazy computation is **2.1x faster** than DP5
- First interpolation triggers lazy computation of 6 extra stages (k11-k16)
- Subsequent interpolations reuse cached extra stages (~10ns RefCell overhead)
- Despite computing extra stages, Vern7 is still faster overall due to:
1. Fewer total integration steps (larger step sizes)
2. Higher accuracy interpolation (7th order vs 5th order)
- Lazy computation adds minimal overhead (~6μs for 6 stages, amortized over 100 interpolations)
- Lazy computation adds minimal overhead, amortized over 100 interpolations
- Each benchmark iteration builds a fresh `Solution`, so the lazy stages are
computed once per iteration rather than served from the `RefCell` cache; this
is the honest cost of interpolating into a solution you have just produced
---
@@ -100,11 +103,11 @@ These results confirm Vern7's design goal: **maximum efficiency for high-accurac
| Tolerance | DP5 (μs) | Vern7 (μs) | Speedup | Winner |
|-----------|----------|------------|---------|--------|
| 1e-6 | 2.63 | 2.05 | 1.28x | Vern7 |
| 1e-7 | 3.71 | 2.74 | 1.35x | Vern7 |
| 1e-8 | 5.43 | 3.12 | 1.74x | Vern7 |
| 1e-9 | 7.97 | 3.86 | 2.06x | **Vern7** |
| 1e-10 | 11.33 | 5.33 | 2.13x | **Vern7** |
| 1e-6 | 1.95 | 1.57 | 1.24x | Vern7 |
| 1e-7 | 2.76 | 2.09 | 1.32x | Vern7 |
| 1e-8 | 4.16 | 2.26 | 1.84x | Vern7 |
| 1e-9 | 6.23 | 2.92 | 2.13x | **Vern7** |
| 1e-10 | 9.39 | 3.93 | 2.39x | **Vern7** |
### Performance Scaling Chart (Conceptual)
@@ -127,8 +130,8 @@ Time (μs)
```
**Analysis**:
- At **moderate tolerances (1e-6)**: Vern7 is 1.3x faster
- At **tight tolerances (1e-10)**: Vern7 is 2.1x faster
- At **moderate tolerances (1e-6)**: Vern7 is 1.2x faster
- At **tight tolerances (1e-10)**: Vern7 is 2.4x faster
- **Crossover point**: Vern7 becomes increasingly advantageous as tolerance tightens
- DP5's time scales roughly quadratically with tolerance
- Vern7's time scales more slowly (higher order = larger steps)
+24 -22
View File
@@ -1,6 +1,6 @@
# BS3 vs DP5 Benchmark Results
Generated: 2025-10-23
Generated: 2026-09-29 (re-measured; first run 2025-10-23)
## Summary
@@ -10,7 +10,7 @@ Comprehensive performance comparison between **BS3** (Bogacki-Shampine 3rd order
### Overall Performance Comparison
**DP5 is consistently faster than BS3 across all tested scenarios**, typically by a factor of **1.5x to 4.3x**.
**DP5 is consistently faster than BS3 across all tested scenarios**, typically by a factor of **1.6x to 4.8x**.
This might seem counterintuitive since BS3 uses fewer stages (4 vs 7), but several factors explain DP5's superior performance:
@@ -32,8 +32,8 @@ Despite being slower in these benchmarks, BS3 still has value:
| Method | Time | Ratio |
|--------|------|-------|
| **BS3** | 3.28 µs | 1.92x slower |
| **DP5** | 1.70 µs | baseline |
| **BS3** | 2.96 µs | 2.08x slower |
| **DP5** | 1.43 µs | baseline |
Simple 1D problem with smooth exponential solution.
@@ -41,8 +41,8 @@ Simple 1D problem with smooth exponential solution.
| Method | Time | Ratio |
|--------|------|-------|
| **BS3** | 30.70 µs | 2.25x slower |
| **DP5** | 13.67 µs | baseline |
| **BS3** | 27.45 µs | 2.26x slower |
| **DP5** | 12.16 µs | baseline |
2D conservative system with periodic solution.
@@ -50,8 +50,8 @@ Simple 1D problem with smooth exponential solution.
| Method | Time | Ratio |
|--------|------|-------|
| **BS3** | 132.35 µs | 3.57x slower |
| **DP5** | 37.11 µs | baseline |
| **BS3** | 113.66 µs | 3.65x slower |
| **DP5** | 31.15 µs | baseline |
Nonlinear 2D system with trigonometric terms.
@@ -59,8 +59,8 @@ Nonlinear 2D system with trigonometric terms.
| Method | Time | Ratio |
|--------|------|-------|
| **BS3** | 124.72 µs | 1.45x slower |
| **DP5** | 86.10 µs | baseline |
| **BS3** | 102.04 µs | 1.56x slower |
| **DP5** | 65.52 µs | baseline |
Higher-dimensional problem with gravitational dynamics.
@@ -68,8 +68,8 @@ Higher-dimensional problem with gravitational dynamics.
| Method | Time (solve + 100 interpolations) | Ratio |
|--------|-----------------------------------|-------|
| **BS3** | 19.68 µs | 4.81x slower |
| **DP5** | 4.09 µs | baseline |
| **BS3** | 16.28 µs | 4.70x slower |
| **DP5** | 3.46 µs | baseline |
BS3 uses cubic Hermite interpolation, DP5 uses optimized 5th order interpolation.
@@ -79,14 +79,14 @@ Performance across different tolerance levels (`y' = -y` problem):
| Tolerance | BS3 Time | DP5 Time | Ratio (BS3/DP5) |
|-----------|----------|----------|-----------------|
| 1e-3 | 1.63 µs | 1.26 µs | 1.30x |
| 1e-4 | 2.61 µs | 1.54 µs | 1.70x |
| 1e-5 | 4.64 µs | 2.03 µs | 2.28x |
| 1e-6 | 8.76 µs | ~2.6 µs* | ~3.4x* |
| 1e-7 | -** | -** | - |
| 1e-3 | 1.15 µs | 0.92 µs | 1.25x |
| 1e-4 | 2.01 µs | 1.19 µs | 1.69x |
| 1e-5 | 3.41 µs | 1.45 µs | 2.36x |
| 1e-6 | 6.72 µs | 1.92 µs | 3.50x |
| 1e-7 | 13.55 µs | 2.82 µs | 4.80x |
\* Estimated from trend (benchmark timed out)
\** Not completed
Both 1e-6 and 1e-7 are now measured. The earlier run estimated 1e-6 from the
trend and did not complete 1e-7.
**Observation**: The performance gap widens as tolerance tightens, because DP5's higher order allows it to take larger steps while maintaining accuracy.
@@ -96,15 +96,17 @@ Performance across different tolerance levels (`y' = -y` problem):
1. **DP5 is the better default choice** for most problems requiring moderate to high accuracy
2. **Performance gap increases** with tighter tolerances (favoring DP5)
3. **Higher dimensions** slightly favor BS3 relative to DP5 (1.45x vs 3.57x slowdown)
4. **Interpolation** strongly favors DP5 (4.8x faster)
3. **Higher dimensions** slightly favor BS3 relative to DP5 (1.56x vs 3.65x slowdown)
4. **Interpolation** strongly favors DP5 (4.7x faster)
### Implementation Quality
Both integrators pass all accuracy and convergence tests:
- ✅ BS3: 3rd order convergence rate verified
- ✅ DP5: 5th order convergence rate verified (existing implementation)
- ✅ Both: FSAL property correctly implemented
- ⚠️ Both: FSAL is a property of the *methods*, but neither implementation
exploits it - each step recomputes `k[0] = f(t, y)` rather than reusing the
previous step's last stage. See roadmap feature 36.
- ✅ Both: Dense output accurate to specified order
### Future Optimizations
+2 -2
View File
@@ -15,8 +15,8 @@ and field line tracing:
| **Vern7** (Verner) | 7(6) | 10+6 | 7th order | High accuracy (rtol ~ 1e-8 to 1e-12) |
**Performance at 1e-10 tolerance:**
- Vern7: **2.7-8.8x faster** than DP5
- Vern7: **50x+ faster** than BS3
- Vern7: **2.9-9.9x faster** than DP5
- Vern7: **53-83x faster** than BS3
See [benchmark report](VERN7_BENCHMARK_REPORT.md) for detailed performance analysis.