Skip to content

perf: fused fixed-fibre counting and one-pass stress field in compute_fatigue - #44

Merged
SMI-Lab-Inha merged 3 commits into
devfrom
perf/throughput-020
Nov 20, 2026
Merged

SMI-Lab-Inha merged 3 commits into
devfrom
perf/throughput-020

Conversation

@SMI-Lab-Inha

@SMI-Lab-Inha SMI-Lab-Inha commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

compute_fatigue runs 2.3–3.0 times faster on the default direction-tied model. Every damage value is unchanged bit for bit. The sea-state batch no longer caps the worker count. A throughput benchmark script records the timings, and a light test checks the fast path against the arithmetic it replaces.

Registered targets

Targets (a)–(c) and the removal of the worker cap were fixed before any change was made; the numerical threshold of (d), 0.8 efficiency at 8 workers, was set after the measurements (the original target said only "near-linear"). Workload: one-hour synthetic sea state on the 66 kV template (kappa_x, kappa_y irregular, peak period 10 s, standard deviations 0.004 and 0.002 1/m, tension 100 ± 10 kN, 20 000 samples at 0.18 s), numba, one thread (AMD Zen 4 core), compilation excluded, minimum of 3 calls.

Target Before After Met
(a) 1 layer, 12 positions × 4 fibres: ≤ 0.17 s per location 0.034 s 0.015 s yes (before too)
(b) all 284 wires, 32 fibres, direction-tied: ≤ 1.0 ns per series-step 13.3 ns 4.9 ns no
(c) distributed ≤ 5 × direction-tied, same workload (all wires, 32 fibres) 10.6× 25.9× no
(d) batch scales with workers: ≥ 0.8 efficiency at 8 workers; no library cap cap 8 no cap; 0.80 (96 runs) yes

Reference basis. A commercial cross-section tool reports 270 one-hour sea states × 76 locations × 48 series (12 positions × 4 hot spots of one layer) × 20 000 steps, about 1.97 × 10¹⁰ stress evaluations, in about 5.8 h on one core of a 2008 laptop: 1.06 µs per evaluation. That core is estimated (not measured) at 4–6 times slower than a Zen 4 core, which puts the reference at about 180–265 ns per evaluation on this machine. Target (a) is its per-location time normalised the same way (about 1.0 s per location-sea-state / (4–6)). Target (b) was registered as 1.0 ns per series-step from a figure that has since been found to be off by a factor of 1000; it is kept here as registered and reported as not met. On the corrected basis CableXSec, at 4.9 ns per series-step after this change (13.3 ns before), is about 36–54 times faster per evaluation than the normalised reference (14–20 times before).

(c) and the "after" ratio: the distributed time fell from 25.8 s to 23.3 s, but the direction-tied time fell more. (d): efficiency is speed-up over worker count, against 1 worker.

Timings at 39c1f81 (before the dev merge)

validation/scripts/benchmark_throughput.py --repeat 3. Before (4a6541b) and after were run in the same session on the same machine.

Case Before After Speed-up ns per series-step (after)
direction-tied, all wires, 4 fibres 0.884 s 0.293 s 3.0× 12.9
direction-tied, all wires, 32 fibres 2.418 s 0.897 s 2.7× 4.9
direction-tied, 12 positions per layer, 4 fibres 0.068 s 0.029 s 2.3× 14.9
distributed, all wires, 4 fibres 24.33 s 22.45 s 1.08× 988
distributed, all wires, 32 fibres 25.75 s 23.26 s 1.11× 128
distributed, 12 positions, 4 fibres 23.81 s 22.43 s 1.06× 11 683

Batch (run_sea_state_batch, synthetic CableDyn runs of 20 000 samples, one section, all wires, 32 fibres):

Runs 1 worker 2 4 8 Efficiency at 8
48 43.3 s 23.5 s 13.0 s 7.8 s 0.69
96 85.7 s 13.4 s 0.80

The remainder is a fixed cost of about 2.5 s at 8 workers: each spawned worker imports the package (1.2 s) and loads the compiled kernels before its first run. This cost is the same for any number of runs, so efficiency rises with campaign size.

Without numba (CABLEXSEC_DISABLE_NUMBA=1, 3 000 samples), the run is no slower: 0.89 → 0.88 s (all wires, 4 fibres) and 0.65 → 0.65 s (12 positions, 32 fibres). Damage is bitwise equal there too.

Re-measured after merging dev e74e01f

dev moved the damage since 4a6541b, by up to 8.7 % relative on this workload (#39, the Yun shear stack stopping at the armour support, and the later merges). So the reference was rebuilt: the same benchmark script was run on dev e74e01f without this PR (--reference against the old build records those differences). This PR, merged with that dev (31b87f8), was then compared against the rebuilt reference. Both were run in one session on the same machine, with numba, one thread and --repeat 3. Other work was running on the machine, so the absolute times carry some noise.

Case dev e74e01f this PR Speed-up ns per series-step (after)
direction-tied, all wires, 4 fibres 0.727 s 0.272 s 2.7× 12.0
direction-tied, all wires, 32 fibres 2.336 s 0.841 s 2.8× 4.6
direction-tied, 12 positions per layer, 4 fibres 0.068 s 0.027 s 2.5× 14.0
distributed, all wires, 4 fibres 29.18 s 27.51 s 1.06× 1 211
distributed, all wires, 32 fibres 30.43 s 28.65 s 1.06× 158
distributed, 12 positions, 4 fibres 28.53 s 28.31 s 1.01× 14 743

Targets on these numbers:

  • (a): 0.034 → 0.014 s per location.
  • (b): 12.9 → 4.6 ns per series-step, still not met.
  • (c): 13.0× → 34.1×, still not met. The distributed solver is slower on dev's ξ, and the direction-tied path is faster.

Batch, 48 synthetic one-hour runs (20 000 samples, one section, all wires, 32 fibres):

Workers dev e74e01f this PR
1 107.6 s 42.6 s
2 61.1 s 26.9 s

The annual damage does not depend on the worker count in either build. The 4- and 8-worker rows of the batch table below come from 39c1f81, before the merge. They were not re-run here because this machine was limited to two concurrent jobs. dev's numba cache slots for batch workers (#48) were sized as 2 * MAX_WORKERS. With the cap removed, they are fixed at 16, the same number. Up to 8 workers nothing changes, and a worker beyond the 16 slots gets a temporary cache.

Without numba (CABLEXSEC_DISABLE_NUMBA=1, direction-tied cases, 3 000 samples, one call), times are 0.891 → 0.871 s (all wires, 4 fibres), 4.762 → 4.749 s (32 fibres) and 0.338 → 0.336 s (12 positions).

Profile (before)

Direction-tied, 32 fibres, 2.34 s in total:

Part Time
fibre histories formed in NumPy (at_fibre) 0.93 s
compiled counter on each fibre (miner_rows) 0.83 s
local bending stress, computed three times per layer 0.23 s
friction recursion 0.17 s

Distributed: 21.9 of 22.4 s are in the compiled increment solver. That is 2.85 million substeps of 0.1 κ_on over 556–580 helix nodes, with 1.13–1.28 Newton solves per substep and about 8 µs per substep. The curvature reaches 91 and 293 κ_on, which gives 34–108 substeps per sample. Rainflow counting and section-state setup take under 3 ms per call. In the batch, each run costs 0.14 s of fatigue work plus 0.04 s for the reader.

Changes

  • Fused fibre counting (fast_rainflow.fibre_miner_damage, used by compute_fatigue). Each fibre history is reduced to its turning points while it is formed from the field components, (mean + radial n) + tangential l, which is the arithmetic of at_fibre. The turning-point scan has no branches. The reversal scan feeds the three-point stack directly. One count serves both the unit factor and the termination SCF. Entries where the reference sum would raise are recomputed on the reference path, in the order of the former loop, so the errors are unchanged. Non-finite fibres are found from bounds on the component magnitudes.

  • One-pass field assembly (fast_field.assemble_wire_field). It does the NumPy operations in the same order, and the trigonometric factors are still evaluated by NumPy. The NumPy path, used without numba, now forms the local bending stress once instead of twice and no longer builds per-wire copies of the axial and thermal stress.

  • Direction-tied friction kernel: the bounds are kept in place instead of being allocated at every sample.

  • Batch: MAX_WORKERS is removed. workers takes any positive integer, and the pool starts at most one worker per run.

  • validation/scripts/benchmark_throughput.py: the cases above, --reference for damage differences against another build, and --batch-workers for batch scaling.

  • tests/test_fast_fatigue_path.py (added to the kernel-coverage list) checks:

    • fused counting against miner_rows on the fibre histories, bitwise, for 3 curves × 4 start offsets × 1 or 2 factors;
    • the non-finite and error paths;
    • compute_fatigue with the compiled counter against the reference loop, with lead-in and selected positions;
    • field assembly against the NumPy expressions;
    • a benchmark smoke run.

    No wall-clock assertions.

Equality

  • Benchmark workload, against dev e74e01f without this PR: all 24 damage arrays of the six cases (D_bulk_per_fibre and D_total_per_wire, both layers) are bitwise equal. Maximum absolute and relative difference: 0.
  • Without numba: the 12 arrays of the three direction-tied cases (3 000 samples) are bitwise equal to that build.
  • Before the merge: at 39c1f81 the same held against 4a6541b.
  • Suite: all exact comparisons pass unchanged, including the compiled counter against the reference counter and selected positions against the full evaluation. No tolerance was changed.

Why (b) and (c) are not met

(b) At 32 fibres on this record, the measured costs per series-step are:

Cost ns per series-step
friction recursion: 30 ns per wire and sample, mostly four libm calls (cos, asin, two expm1) needed bit for bit 0.94
forming the fibre stress and locating turning points, without branches 1.2
three-point stack: 3 370 turning points per 20 000-sample series 1.0
S-N life of each of about 1 690 cycles per series (log10 and pow, 14 ns per cycle) 1.3

That adds up to about 4.4 ns against 4.9 ns measured, so 1.0 ns cannot be reached while results stay bit for bit. A Miner sum written as count * S**m / C with integer powers would remove most of the last line, but it changes every damage value at round-off. It is left out of this PR for a separate decision.

(c) The distributed cost is the implicit solve itself, not a fixed overhead. The stick/slip pattern changes in almost every substep (1.1–1.3 Newton solves each), and about 10 passes over the helix nodes run per substep at about 1.5 ns per node and pass. Reaching 5× the new direction-tied time would mean about 4.5 s, a 5× cut. That needs either fewer substeps, which changes the results by the discretisation error rather than at round-off, or a different solver.

Gates

On 31b87f8, the merge with dev e74e01f. 040fe9b changes only the CHANGELOG numbers.

  • full suite with NUMBA_NUM_THREADS=1: 4872 passed, 4 skipped
  • full suite with CABLEXSEC_DISABLE_NUMBA=1: 4756 passed, 120 skipped
  • python -m mypy: no issues in 120 source files
  • ruff check and ruff format --check on src tests examples validation release doc: clean
  • taxonomy from --collect-only per marker: unchanged at 1248 / 77 / 59 (the new and removed tests carry no marker)
  • merge conflicts:
    • sea_state_batch.py: the removed cap next to dev's option checks; both kept, cache slots as above
    • doc/global_local_guide.md: the worker bullet, with the slot caches added
    • CHANGELOG: both entries kept

…_fatigue

compute_fatigue counts every fixed fibre of a layer in one compiled pass
(fast_rainflow.fibre_miner_damage): each fibre history is reduced to its
turning points while it is formed from the field components, without
branches, the reversal scan feeds the three-point stack directly, and one
count serves the unit and the termination stress-range factor. The fibre
histories are no longer formed in NumPy. The stress field of
wire_stress_field is assembled in one compiled pass
(fast_field.assemble_wire_field) with the operations of the NumPy
expressions in the same order; without numba the NumPy path computes the
local bending stress once instead of twice and no longer forms the
per-wire copies of the axial and thermal stress. The direction-tied
friction kernel keeps its bounds in place instead of allocating them at
every sample.

All damage is bit for bit equal to the previous build on the throughput
workload (one-hour sea state, 66 kV template, every case) and in the
suite; entries where the reference would raise are recomputed on the
reference path in the order of the former loop.

The sea-state batch has no upper limit on the worker count (the pool
starts at most one worker per run); MAX_WORKERS is removed.

validation/scripts/benchmark_throughput.py records the one-core throughput
of the sea-state path, the damage differences from an earlier build and
the batch time against the worker count; tests/test_fast_fatigue_path.py
checks the fused path against the arithmetic it replaces.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T02:51:41.785581Z 040fe9b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@read-the-docs-community

read-the-docs-community Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 CableXSec | 🛠️ Build #36030892 | 📁 Comparing 040fe9b against latest (240bf9c)

  🔍 Preview build  

24 files changed · ± 24 modified

± Modified

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 39c1f819f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
The CHANGELOG entry gives the timings of the throughput benchmark against
dev e74e01f without this change, measured in one session on one machine:
direction-tied 2.5 to 2.8 times faster, distributed 29.2 s to 27.5 s, batch
of 48 runs 107.6 s to 42.6 s on one worker and 61.1 s to 26.9 s on two. All
24 damage arrays of the benchmark are bitwise equal to that build with
numba, and the 12 of the direction-tied cases without numba. The 16
persistent cache slots of the batch workers stay as they were now that the
worker count has no upper limit.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 040fe9b0d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SMI-Lab-Inha
SMI-Lab-Inha merged commit f0753a3 into dev Nov 20, 2026
14 checks passed
@SMI-Lab-Inha
SMI-Lab-Inha deleted the perf/throughput-020 branch November 20, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant